Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 1 | :: # 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 | :: |
| 28 | /* Copyright 2013, Big Switch Networks, Inc. */ |
| 29 | |
| 30 | /** |
| 31 | * Test code for setup from flow add routines |
| 32 | */ |
| 33 | |
| 34 | #include <locitest/test_common.h> |
| 35 | |
| 36 | #if !defined(__APPLE__) |
| 37 | #include <mcheck.h> |
| 38 | #define MCHECK_INIT mcheck(NULL) |
| 39 | #else /* mcheck not available under OS X */ |
| 40 | #define MCHECK_INIT do { } while (0) |
| 41 | #endif |
| 42 | |
| 43 | |
| 44 | static int |
| 45 | test_removed_setup_from_add(void) |
| 46 | { |
| 47 | of_flow_removed_t *removed; |
| 48 | of_flow_add_t *add; |
| 49 | of_match_t m1, m2; |
| 50 | |
| 51 | TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL); |
| 52 | TEST_ASSERT((removed = of_flow_removed_new(OF_VERSION_1_0)) != NULL); |
| 53 | |
| 54 | TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0); |
| 55 | TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0); |
| 56 | |
| 57 | TEST_ASSERT(of_flow_removed_setup_from_flow_add(removed, add) == 0); |
| 58 | TEST_ASSERT(of_flow_removed_match_get(removed, &m2) == 0); |
| 59 | TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0); |
| 60 | |
| 61 | of_flow_add_delete(add); |
| 62 | of_flow_removed_delete(removed); |
| 63 | |
| 64 | return TEST_PASS; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | static int |
| 69 | test_stats_entry_setup_from_add(void) |
| 70 | { |
| 71 | of_flow_add_t *add; |
| 72 | of_flow_stats_entry_t *entry; |
| 73 | of_match_t m1, m2; |
| 74 | of_list_action_t *list; |
| 75 | of_list_action_t list_out; |
| 76 | |
| 77 | TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL); |
| 78 | TEST_ASSERT((entry = of_flow_stats_entry_new(OF_VERSION_1_0)) != NULL); |
| 79 | |
| 80 | TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0); |
| 81 | TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0); |
| 82 | |
| 83 | TEST_ASSERT(of_flow_stats_entry_setup_from_flow_add(entry, add, NULL) == 0); |
| 84 | TEST_ASSERT(of_flow_stats_entry_match_get(entry, &m2) == 0); |
| 85 | TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0); |
| 86 | |
| 87 | of_flow_add_delete(add); |
| 88 | of_flow_stats_entry_delete(entry); |
| 89 | |
| 90 | /* @todo check action lists agree */ |
| 91 | |
| 92 | /* Same with an external action list */ |
| 93 | |
| 94 | TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL); |
| 95 | TEST_ASSERT((entry = of_flow_stats_entry_new(OF_VERSION_1_0)) != NULL); |
| 96 | |
| 97 | TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0); |
| 98 | TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0); |
| 99 | |
| 100 | list = of_list_action_new(OF_VERSION_1_0); |
| 101 | TEST_ASSERT(list != NULL); |
| 102 | TEST_ASSERT(of_list_action_OF_VERSION_1_0_populate(list, 1) != 0); |
| 103 | |
| 104 | /* Verify matches agree */ |
| 105 | TEST_ASSERT(of_flow_stats_entry_setup_from_flow_add(entry, add, list) == 0); |
| 106 | TEST_ASSERT(of_flow_stats_entry_match_get(entry, &m2) == 0); |
| 107 | TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0); |
| 108 | |
| 109 | of_list_action_init(&list_out, OF_VERSION_1_0, 0, 1); |
| 110 | of_flow_stats_entry_actions_bind(entry, &list_out); |
| 111 | |
| 112 | /* Verify lists agree */ |
| 113 | TEST_ASSERT(list->length == list_out.length); |
| 114 | TEST_ASSERT(memcmp(WBUF_BUF(list->wire_object.wbuf), |
| 115 | WBUF_BUF(list_out.wire_object.wbuf), |
| 116 | list->length)); |
| 117 | |
| 118 | of_flow_add_delete(add); |
| 119 | of_list_action_delete(list); |
| 120 | of_flow_stats_entry_delete(entry); |
| 121 | |
| 122 | return TEST_PASS; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | int run_setup_from_add_tests(void) |
| 127 | { |
| 128 | RUN_TEST(removed_setup_from_add); |
| 129 | RUN_TEST(stats_entry_setup_from_add); |
| 130 | |
| 131 | return TEST_PASS; |
| 132 | } |