summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-12-05 19:25:56 -0500
committerirungentoo <irungentoo@gmail.com>2013-12-05 19:25:56 -0500
commit245a1511e6ab8d93747c7b0bcbf95bc013f87fea (patch)
treeb32b016b038b5f12af3771b7fa829a706118ce92 /auto_tests
parent3d2707748c60ea595ede34e482fa9837e5ccd0a6 (diff)
Added a assoc test.
Changed default assoc so that it behaves correctly.
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/assoc_test.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/auto_tests/assoc_test.c b/auto_tests/assoc_test.c
index 79a0e778..af88afa7 100644
--- a/auto_tests/assoc_test.c
+++ b/auto_tests/assoc_test.c
@@ -57,6 +57,70 @@ START_TEST(test_basics)
57} 57}
58END_TEST 58END_TEST
59 59
60START_TEST(test_fillup)
61{
62 /* TODO: real test */
63 int i, j;
64 uint8_t id[CLIENT_ID_SIZE];
65 //uint32_t a = current_time();
66 uint32_t a = 2710106197;
67 srand(a);
68 for(i = 0; i < CLIENT_ID_SIZE; ++i) {
69 id[i] = rand();
70 }
71 Assoc *assoc = new_Assoc(6, 15, id);
72 ck_assert_msg(assoc != NULL, "failed to create default assoc");
73 struct entry {
74 uint8_t id[CLIENT_ID_SIZE];
75 IPPTs ippts_send;
76 IP_Port ipp_recv;
77 };
78 unsigned int fail = 0;
79 struct entry entries[128];
80 struct entry closest[8];
81 for(j = 0; j < 128; ++j) {
82
83 for(i = 0; i < CLIENT_ID_SIZE; ++i) {
84 entries[j].id[i] = rand();
85 }
86 IP_Port ipp;
87 ipp.ip.family = AF_INET;
88 ipp.ip.ip4.uint32 = rand();
89 ipp.port = rand();
90 entries[j].ippts_send.ip_port = ipp;
91 entries[j].ippts_send.timestamp = unix_time();
92 ipp.ip.ip4.uint32 = rand();
93 ipp.port = rand();
94 entries[j].ipp_recv = ipp;
95 if (j % 16 == 0) {
96 memcpy(entries[j].id, id, CLIENT_ID_SIZE - 30);
97 memcpy(&closest[j/16], &entries[j], sizeof(struct entry));
98
99 }
100 uint8_t res = Assoc_add_entry(assoc, entries[j].id, &entries[j].ippts_send, &entries[j].ipp_recv, 1);
101 ck_assert_msg(res == 1, "failed to store entry: expected %u, got %u, j = %u", 1, res, j);
102 }
103 int good = 0;
104 Assoc_close_entries close_entries;
105 memset(&close_entries, 0, sizeof(close_entries));
106 close_entries.count = 8;
107 close_entries.count_good = 8;
108 close_entries.wanted_id = id;
109
110 Client_data *entri[close_entries.count];
111 close_entries.result = entri;
112
113 uint8_t found = Assoc_get_close_entries(assoc, &close_entries);
114 ck_assert_msg(found == 8, "get_close_entries(): expected %u, got %u", 1, found);
115 for (i = 0; i < 8; ++i) {
116 for (j = 0; j < 8; ++j) {
117 if (id_equal(entri[j]->client_id, closest[i].id))
118 ++good;
119 }
120 }ck_assert_msg(good == 8, "Entries found were not the closest ones. Only %u/8 were.", good);
121 //printf("good: %u %u %u\n", good, a, ((uint32_t)current_time() - a));
122}
123END_TEST
60 124
61#define DEFTESTCASE(NAME) \ 125#define DEFTESTCASE(NAME) \
62 TCase *tc_##NAME = tcase_create(#NAME); \ 126 TCase *tc_##NAME = tcase_create(#NAME); \
@@ -72,12 +136,13 @@ Suite *Assoc_suite(void)
72 Suite *s = suite_create("Assoc"); 136 Suite *s = suite_create("Assoc");
73 137
74 DEFTESTCASE(basics); 138 DEFTESTCASE(basics);
75 139 DEFTESTCASE(fillup);
76 return s; 140 return s;
77} 141}
78 142
79int main(int argc, char *argv[]) 143int main(int argc, char *argv[])
80{ 144{
145 unix_time_update();
81 Suite *Assoc = Assoc_suite(); 146 Suite *Assoc = Assoc_suite();
82 SRunner *test_runner = srunner_create(Assoc); 147 SRunner *test_runner = srunner_create(Assoc);
83 148