summaryrefslogtreecommitdiff
path: root/auto_tests/run_auto_test.h
diff options
context:
space:
mode:
authorzugz (tox) <mbays+tox@sdf.org>2018-08-17 20:34:25 +0200
committerzugz (tox) <mbays+tox@sdf.org>2018-08-31 17:08:35 +0200
commit9764285ab156c25050b9e9e46a8e8bc0be701951 (patch)
treee4e608c75a36382fe84dcdfc03d8135f48aea655 /auto_tests/run_auto_test.h
parent2e4cae692e0895ce17e67fb2e1fd899c91fcb675 (diff)
Use test clock in run_auto_test tests and dht test
Diffstat (limited to 'auto_tests/run_auto_test.h')
-rw-r--r--auto_tests/run_auto_test.h27
1 files changed, 19 insertions, 8 deletions
diff --git a/auto_tests/run_auto_test.h b/auto_tests/run_auto_test.h
index ad89992a..602ad524 100644
--- a/auto_tests/run_auto_test.h
+++ b/auto_tests/run_auto_test.h
@@ -2,6 +2,8 @@
2 2
3#include "check_compat.h" 3#include "check_compat.h"
4#include "../testing/misc_tools.h" 4#include "../testing/misc_tools.h"
5#include "../toxcore/Messenger.h"
6#include "../toxcore/mono_time.h"
5 7
6static bool all_connected(uint32_t tox_count, Tox **toxes) 8static bool all_connected(uint32_t tox_count, Tox **toxes)
7{ 9{
@@ -29,13 +31,20 @@ static bool all_friends_connected(uint32_t tox_count, Tox **toxes)
29 return true; 31 return true;
30} 32}
31 33
32static bool iterate_all(uint32_t tox_count, Tox **toxes, State *state) 34static void iterate_all_wait(uint32_t tox_count, Tox **toxes, State *state, uint32_t wait)
33{ 35{
34 for (uint32_t i = 0; i < tox_count; i++) { 36 for (uint32_t i = 0; i < tox_count; i++) {
35 tox_iterate(toxes[i], &state[i]); 37 tox_iterate(toxes[i], &state[i]);
38 state[i].clock += wait;
36 } 39 }
37 40
38 return true; 41 /* Also actually sleep a little, to allow for local network processing */
42 c_sleep(20);
43}
44
45static uint64_t get_state_clock_callback(void *user_data)
46{
47 return ((State *)user_data)->clock;
39} 48}
40 49
41static void run_auto_test(uint32_t tox_count, void test(Tox **toxes, State *state)) 50static void run_auto_test(uint32_t tox_count, void test(Tox **toxes, State *state))
@@ -48,6 +57,12 @@ static void run_auto_test(uint32_t tox_count, void test(Tox **toxes, State *stat
48 state[i].index = i; 57 state[i].index = i;
49 toxes[i] = tox_new_log(nullptr, nullptr, &state[i].index); 58 toxes[i] = tox_new_log(nullptr, nullptr, &state[i].index);
50 ck_assert_msg(toxes[i], "failed to create %u tox instances", i + 1); 59 ck_assert_msg(toxes[i], "failed to create %u tox instances", i + 1);
60
61 // TODO(iphydf): Don't rely on toxcore internals.
62 Mono_Time *mono_time = (*(Messenger **)toxes[i])->mono_time;
63
64 state[i].clock = current_time_monotonic(mono_time);
65 mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &state[i]);
51 } 66 }
52 67
53 printf("toxes all add each other as friends\n"); 68 printf("toxes all add each other as friends\n");
@@ -73,17 +88,13 @@ static void run_auto_test(uint32_t tox_count, void test(Tox **toxes, State *stat
73 } 88 }
74 89
75 do { 90 do {
76 iterate_all(tox_count, toxes, state); 91 iterate_all_wait(tox_count, toxes, state, ITERATION_INTERVAL);
77
78 c_sleep(ITERATION_INTERVAL);
79 } while (!all_connected(tox_count, toxes)); 92 } while (!all_connected(tox_count, toxes));
80 93
81 printf("toxes are online\n"); 94 printf("toxes are online\n");
82 95
83 do { 96 do {
84 iterate_all(tox_count, toxes, state); 97 iterate_all_wait(tox_count, toxes, state, ITERATION_INTERVAL);
85
86 c_sleep(ITERATION_INTERVAL);
87 } while (!all_friends_connected(tox_count, toxes)); 98 } while (!all_friends_connected(tox_count, toxes));
88 99
89 printf("tox clients connected\n"); 100 printf("tox clients connected\n");