From b6e987a46ed98966621bdc1d0d19c7f67d364111 Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 15 Mar 2022 16:34:09 +0000 Subject: [PATCH] test: Speed up toxav_many_test by using fake mono_time. --- auto_tests/toxav_many_test.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 2918da8da7..8caa372b51 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -33,6 +33,12 @@ typedef struct { uint32_t friend_number; } thread_data; +static uint64_t get_state_clock_callback(Mono_Time *mono_time, void *user_data) +{ + const uint64_t *clock = (const uint64_t *)user_data; + return *clock; +} + /** * Callbacks */ @@ -129,6 +135,13 @@ static void *call_thread(void *pd) return nullptr; } +static void set_current_time_callback(Tox *tox, uint64_t *clock) +{ + // TODO(iphydf): Don't rely on toxcore internals. + Mono_Time *mono_time = ((Messenger *)tox)->mono_time; + mono_time_set_current_time_callback(mono_time, get_state_clock_callback, clock); +} + static void test_av_three_calls(void) { uint32_t index[] = { 1, 2, 3, 4, 5 }; @@ -138,23 +151,32 @@ static void test_av_three_calls(void) CallControl AliceCC[3], BobsCC[3]; + uint64_t clock; { Tox_Err_New error; bootstrap = tox_new_log(nullptr, &error, &index[0]); ck_assert(error == TOX_ERR_NEW_OK); + // TODO(iphydf): Don't rely on toxcore internals. + clock = current_time_monotonic(((Messenger *)bootstrap)->mono_time); + set_current_time_callback(bootstrap, &clock); + Alice = tox_new_log(nullptr, &error, &index[1]); ck_assert(error == TOX_ERR_NEW_OK); + set_current_time_callback(Alice, &clock); Bobs[0] = tox_new_log(nullptr, &error, &index[2]); ck_assert(error == TOX_ERR_NEW_OK); + set_current_time_callback(Bobs[0], &clock); Bobs[1] = tox_new_log(nullptr, &error, &index[3]); ck_assert(error == TOX_ERR_NEW_OK); + set_current_time_callback(Bobs[1], &clock); Bobs[2] = tox_new_log(nullptr, &error, &index[4]); ck_assert(error == TOX_ERR_NEW_OK); + set_current_time_callback(Bobs[2], &clock); } printf("Created 5 instances of Tox\n"); @@ -208,7 +230,8 @@ static void test_av_three_calls(void) break; } - c_sleep(20); + clock += 200; + c_sleep(5); } AliceAV = setup_av_instance(Alice, AliceCC); @@ -245,7 +268,9 @@ static void test_av_three_calls(void) tox_iterate(Bobs[0], nullptr); tox_iterate(Bobs[1], nullptr); tox_iterate(Bobs[2], nullptr); - c_sleep(20); + + clock += 100; + c_sleep(5); } while (time(nullptr) - start_time < 1); /* Call */ @@ -282,7 +307,8 @@ static void test_av_three_calls(void) } } - c_sleep(20); + clock += 100; + c_sleep(5); } while (time(nullptr) - start_time < 3); /* Hangup */ @@ -302,7 +328,8 @@ static void test_av_three_calls(void) tox_iterate(Bobs[1], nullptr); tox_iterate(Bobs[2], nullptr); - c_sleep(20); + clock += 100; + c_sleep(5); } while (time(nullptr) - start_time < 5); ck_assert(pthread_join(tids[0], &retval) == 0);