Skip to content

Commit

Permalink
Fix test of time measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
huitema committed Dec 29, 2023
1 parent 311d94c commit e8ba6f4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
2 changes: 0 additions & 2 deletions picoquictest/ticket_store_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ int ticket_store_test()
picoquic_stored_ticket_t* p_first_ticket = NULL;
picoquic_stored_ticket_t* p_first_ticket_bis = NULL;
picoquic_stored_ticket_t* p_first_ticket_ter = NULL;
picoquic_stored_ticket_t* p_first_ticket_empty = NULL;
uint8_t ipv4_test[4] = { 10, 0, 0, 1 };
uint8_t ipv6_test[16] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };

Expand Down Expand Up @@ -342,7 +341,6 @@ int token_store_test()
picoquic_stored_token_t* p_first_token = NULL;
picoquic_stored_token_t* p_first_token_bis = NULL;
picoquic_stored_token_t* p_first_token_ter = NULL;
picoquic_stored_token_t* p_first_token_empty = NULL;

uint64_t token_time = 40000000000ull;
uint64_t current_time = 50000000000ull;
Expand Down
47 changes: 23 additions & 24 deletions picoquictest/tls_api_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -5116,7 +5116,7 @@ int virtual_time_test()
{
/* Check that the simulated time follows the simulation */
for (int i = 0; ret == 0 && i < 5; i++) {
simulated_time += 12345000;
simulated_time += 12345678000;
test_time = picoquic_get_quic_time(qsimul);
ptls_time = picoquic_get_tls_time(qsimul);
if (test_time != simulated_time) {
Expand All @@ -5134,35 +5134,34 @@ int virtual_time_test()
}
}

/* Check that the non simulated time follows the current time */
for (int i = 0; ret == 0 && i < 5; i++) {
if (ret == 0) {
int64_t delta, delta_low, delta_high;
uint64_t current_previous = picoquic_current_time();
uint64_t test_previous = picoquic_current_time();
uint64_t ptls_previous = picoquic_get_tls_time(qdirect);

/* Check that the non simulated time follows the current time */
for (int i = 0; ret == 0 && i < 5; i++) {
#ifdef _WINDOWS
Sleep(1);
Sleep(1);
#else
usleep(1000);
usleep(1000);
#endif
current_time = picoquic_current_time();
test_time = picoquic_get_quic_time(qdirect);
ptls_time = picoquic_get_tls_time(qdirect);

if (test_time < current_time) {
DBG_PRINTF("Test time: %llu < previous current time: %llu",
(unsigned long long)test_time,
(unsigned long long)current_time);
ret = -1;
}
else {
current_time = picoquic_current_time();
if (test_time > current_time) {
DBG_PRINTF("Test time: %llu > next current time: %llu",
(unsigned long long)test_time,
(unsigned long long)current_time);
test_time = picoquic_get_quic_time(qdirect);
ptls_time = picoquic_get_tls_time(qdirect);

delta = current_time - current_previous;
delta_low = delta - 1000;
delta_high = delta + 1000;
if (test_time < test_previous + delta_low || test_time > test_previous + delta_high ) {
DBG_PRINTF("Test time: %" PRIu64 " does not match previous test time : %" PRIu64 " + delta : %" PRId64,
test_time, test_previous, delta);
ret = -1;
}
else if (ptls_time + 1000 < test_time || ptls_time > test_time + 1000) {
DBG_PRINTF("Test current time: %llu does match ptls time: %llu",
(unsigned long long)test_time,
(unsigned long long)ptls_time);
else if (ptls_time < ptls_previous + delta_low || ptls_time > ptls_previous + delta_high) {
DBG_PRINTF("Test time: %" PRIu64 " does not match previous test time : %" PRIu64 " + delta : %" PRId64,
ptls_time, ptls_previous, delta);
ret = -1;
}
}
Expand Down
12 changes: 6 additions & 6 deletions thread_tester/thread_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,9 @@ int main(int argc, char** argv)
int ret = 0;
thread_test_context_t ctx;
int is_name = 0;
picoquic_thread_t t_net = NULL;
picoquic_thread_t t_load = NULL;
picoquic_thread_t t_wake = NULL;
picoquic_thread_t t_net = (picoquic_thread_t)0;
picoquic_thread_t t_load = (picoquic_thread_t)0;
picoquic_thread_t t_wake = (picoquic_thread_t)0;

#ifdef _WINDOWS
WSADATA wsaData = { 0 };
Expand Down Expand Up @@ -614,7 +614,7 @@ int main(int argc, char** argv)
DBG_PRINTF("Cannot close load thread, ret= 0x%x", ret);
}
else {
t_load = NULL;
t_load = (picoquic_thread_t)0;
}
}
/* Wait next on the message event thread. */
Expand All @@ -625,7 +625,7 @@ int main(int argc, char** argv)
DBG_PRINTF("Cannot close wake thread, ret= 0x%x", ret);
}
else {
t_wake = NULL;
t_wake = (picoquic_thread_t)0;
}
}
printf("Load and wake thread are closed.\n");
Expand All @@ -642,7 +642,7 @@ int main(int argc, char** argv)
DBG_PRINTF("Cannot close wake thread, ret= 0x%x", ret);
}
else {
t_net = NULL;
t_net = (picoquic_thread_t)0;
}
}
/* To do: statistics */
Expand Down

0 comments on commit e8ba6f4

Please sign in to comment.