blob: 0b0707693fca801dbea208f0e1643c6eaf88fa70 [file] [log] [blame]
Rich Lanea06d0c32013-03-25 08:52:03 -07001:: # Copyright 2013, Big Switch Networks, Inc.
2:: #
3:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
4:: # the following special exception:
5:: #
6:: # LOXI Exception
7:: #
8:: # As a special exception to the terms of the EPL, you may distribute libraries
9:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
10:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
11:: # from the LoxiGen Libraries and the notice provided below is (i) included in
12:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
13:: # documentation for the LoxiGen Libraries, if distributed in binary form.
14:: #
15:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
16:: #
17:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
18:: # a copy of the EPL at:
19:: #
20:: # http://www.eclipse.org/legal/epl-v10.html
21:: #
22:: # Unless required by applicable law or agreed to in writing, software
23:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25:: # EPL for the specific language governing permissions and limitations
26:: # under the EPL.
27::
Rich Laned983aa52013-06-13 11:48:37 -070028:: include('_copyright.c')
Rich Lanea06d0c32013-03-25 08:52:03 -070029
30/**
31 * Test code for setup from flow add routines
32 */
33
34#include <locitest/test_common.h>
35
YAMAMOTO Takashi071b5912013-07-02 08:37:39 +090036/* mcheck is a glibc extension */
37#if defined(__linux__)
Rich Lanea06d0c32013-03-25 08:52:03 -070038#include <mcheck.h>
39#define MCHECK_INIT mcheck(NULL)
YAMAMOTO Takashi071b5912013-07-02 08:37:39 +090040#else
Rich Lanea06d0c32013-03-25 08:52:03 -070041#define MCHECK_INIT do { } while (0)
42#endif
43
44
45static int
46test_removed_setup_from_add(void)
47{
48 of_flow_removed_t *removed;
49 of_flow_add_t *add;
50 of_match_t m1, m2;
51
52 TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL);
53 TEST_ASSERT((removed = of_flow_removed_new(OF_VERSION_1_0)) != NULL);
54
55 TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0);
56 TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0);
57
58 TEST_ASSERT(of_flow_removed_setup_from_flow_add(removed, add) == 0);
59 TEST_ASSERT(of_flow_removed_match_get(removed, &m2) == 0);
60 TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0);
61
62 of_flow_add_delete(add);
63 of_flow_removed_delete(removed);
64
65 return TEST_PASS;
66}
67
68
69static int
70test_stats_entry_setup_from_add(void)
71{
72 of_flow_add_t *add;
73 of_flow_stats_entry_t *entry;
74 of_match_t m1, m2;
75 of_list_action_t *list;
76 of_list_action_t list_out;
77
78 TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL);
79 TEST_ASSERT((entry = of_flow_stats_entry_new(OF_VERSION_1_0)) != NULL);
80
81 TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0);
82 TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0);
83
84 TEST_ASSERT(of_flow_stats_entry_setup_from_flow_add(entry, add, NULL) == 0);
85 TEST_ASSERT(of_flow_stats_entry_match_get(entry, &m2) == 0);
86 TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0);
87
88 of_flow_add_delete(add);
89 of_flow_stats_entry_delete(entry);
90
91 /* @todo check action lists agree */
92
93 /* Same with an external action list */
94
95 TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL);
96 TEST_ASSERT((entry = of_flow_stats_entry_new(OF_VERSION_1_0)) != NULL);
97
98 TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0);
99 TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0);
100
101 list = of_list_action_new(OF_VERSION_1_0);
102 TEST_ASSERT(list != NULL);
103 TEST_ASSERT(of_list_action_OF_VERSION_1_0_populate(list, 1) != 0);
104
105 /* Verify matches agree */
106 TEST_ASSERT(of_flow_stats_entry_setup_from_flow_add(entry, add, list) == 0);
107 TEST_ASSERT(of_flow_stats_entry_match_get(entry, &m2) == 0);
108 TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0);
109
110 of_list_action_init(&list_out, OF_VERSION_1_0, 0, 1);
111 of_flow_stats_entry_actions_bind(entry, &list_out);
112
113 /* Verify lists agree */
114 TEST_ASSERT(list->length == list_out.length);
115 TEST_ASSERT(memcmp(WBUF_BUF(list->wire_object.wbuf),
116 WBUF_BUF(list_out.wire_object.wbuf),
117 list->length));
118
119 of_flow_add_delete(add);
120 of_list_action_delete(list);
121 of_flow_stats_entry_delete(entry);
122
123 return TEST_PASS;
124}
125
126
127int run_setup_from_add_tests(void)
128{
129 RUN_TEST(removed_setup_from_add);
130 RUN_TEST(stats_entry_setup_from_add);
131
132 return TEST_PASS;
133}