|
| 1 | +#include "tests.h" |
| 2 | +#include "routing_table.h" |
| 3 | +#include "remove_default_routes.h" |
| 4 | + |
| 5 | +// Remove default routes from the table: |
| 6 | +// |
| 7 | +// S -> 0000 -> N # Remove |
| 8 | +// N -> 0001 -> N # Keep |
| 9 | +// ? -> 0010 -> N # Keep |
| 10 | +// N S -> 0011 -> N S # Keep |
| 11 | +// 1 -> 0100 -> 1 # Keep |
| 12 | +entry_t orthogonal_entries[] = { |
| 13 | + {{0x0, 0xf}, 0b000100, 0b100000}, |
| 14 | + {{0x1, 0xf}, 0b000100, 0b000100}, |
| 15 | + {{0x2, 0xf}, 0b000100, (1 << 24)}, |
| 16 | + {{0x3, 0xf}, 0b100100, 0b100100}, |
| 17 | + {{0x4, 0xf}, 0b1000000, 0b1000000}, |
| 18 | +}; |
| 19 | +entry_t orthogonal_entries_results[] = { |
| 20 | + {{0x1, 0xf}, 0b000100, 0b000100}, |
| 21 | + {{0x2, 0xf}, 0b000100, (1 << 24)}, |
| 22 | + {{0x3, 0xf}, 0b100100, 0b100100}, |
| 23 | + {{0x4, 0xf}, 0b1000000, 0b1000000}, |
| 24 | +}; |
| 25 | + |
| 26 | +// Remove default routes from the table: |
| 27 | +// |
| 28 | +// S -> 0000 -> N # Remove |
| 29 | +// N -> 0001 -> N # Keep |
| 30 | +// ? -> 0010 -> N # Keep |
| 31 | +// N S -> 0011 -> N S # Keep |
| 32 | +// W -> 0100 -> E # Remove |
| 33 | +entry_t orthogonal_entries2[] = { |
| 34 | + {{0x0, 0xf}, 0b000100, 0b100000}, |
| 35 | + {{0x1, 0xf}, 0b000100, 0b000100}, |
| 36 | + {{0x2, 0xf}, 0b000100, (1 << 24)}, |
| 37 | + {{0x3, 0xf}, 0b100100, 0b100100}, |
| 38 | + {{0x4, 0xf}, 0b000001, 0b001000}, |
| 39 | +}; |
| 40 | +entry_t orthogonal_entries2_results[] = { |
| 41 | + {{0x1, 0xf}, 0b000100, 0b000100}, |
| 42 | + {{0x2, 0xf}, 0b000100, (1 << 24)}, |
| 43 | + {{0x3, 0xf}, 0b100100, 0b100100}, |
| 44 | +}; |
| 45 | + |
| 46 | +// Remove default routes from the table: |
| 47 | +// |
| 48 | +// S -> 1000 -> N # Remove |
| 49 | +// S -> 0000 -> N # Keep |
| 50 | +// ? -> 0XXX -> N # Keep |
| 51 | +entry_t nonorthogonal_entries[] = { |
| 52 | + {{0x8, 0xf}, 0b000100, 0b100000}, |
| 53 | + {{0x0, 0xf}, 0b000100, 0b100000}, |
| 54 | + {{0x0, 0x8}, 0b000100, (1 << 24)}, |
| 55 | +}; |
| 56 | +entry_t nonorthogonal_entries_results[] = { |
| 57 | + {{0x0, 0xf}, 0b000100, 0b100000}, |
| 58 | + {{0x0, 0x8}, 0b000100, (1 << 24)}, |
| 59 | +}; |
| 60 | + |
| 61 | +// Set up the fixtures |
| 62 | +table_t test_tables[] = { |
| 63 | + {5, orthogonal_entries}, |
| 64 | + {5, orthogonal_entries2}, |
| 65 | + {3, nonorthogonal_entries}, |
| 66 | +}; |
| 67 | + |
| 68 | +table_t expected_tables[] = { |
| 69 | + {4, orthogonal_entries_results}, |
| 70 | + {3, orthogonal_entries2_results}, |
| 71 | + {2, nonorthogonal_entries_results}, |
| 72 | +}; |
| 73 | + |
| 74 | + |
| 75 | +START_TEST(test_removal) |
| 76 | +{ |
| 77 | + // Grab the tables |
| 78 | + table_t table = test_tables[_i]; |
| 79 | + table_t expected = expected_tables[_i]; |
| 80 | + |
| 81 | + // Minimise |
| 82 | + remove_default_routes_minimise(&table); |
| 83 | + |
| 84 | + // Check the result |
| 85 | + ck_assert_int_eq(table.size, expected.size); |
| 86 | + |
| 87 | + // Check the tables are equivalent |
| 88 | + for (unsigned int i = 0; i < table.size; i++) |
| 89 | + { |
| 90 | + // Get the entries |
| 91 | + entry_t e = table.entries[i]; |
| 92 | + entry_t f = expected.entries[i]; |
| 93 | + |
| 94 | + ck_assert_int_eq(e.keymask.key, f.keymask.key); |
| 95 | + ck_assert_int_eq(e.keymask.mask, f.keymask.mask); |
| 96 | + ck_assert_int_eq(e.route, f.route); |
| 97 | + ck_assert_int_eq(e.source, f.source); |
| 98 | + } |
| 99 | +} |
| 100 | +END_TEST |
| 101 | + |
| 102 | + |
| 103 | +Suite* remove_default_suite(void) |
| 104 | +{ |
| 105 | + Suite *s; |
| 106 | + TCase *tests; |
| 107 | + |
| 108 | + s = suite_create("Remove Default Routes"); |
| 109 | + tests = tcase_create("Core"); |
| 110 | + suite_add_tcase(s, tests); |
| 111 | + |
| 112 | + // Add the tests |
| 113 | + tcase_add_loop_test(tests, test_removal, |
| 114 | + 0, sizeof(test_tables) / sizeof(table_t)); |
| 115 | + |
| 116 | + return s; |
| 117 | +} |
0 commit comments