Skip to content

Commit

Permalink
Merge pull request #260 from kronosnet/test-suite
Browse files Browse the repository at this point in the history
[tests] add common function to sleep based on how the test suite is r…
  • Loading branch information
fabbione committed Sep 26, 2019
2 parents 9f10144 + 728ca4f commit a0128b9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions libknet/tests/api_knet_handle_pmtud_set.c
Expand Up @@ -167,7 +167,7 @@ static void test(void)
/*
* wait for PMTUd to pick up the change
*/
sleep(1);
test_sleep(knet_h, 1);
flush_logs(logfds[0], stdout);

if (knet_h->data_mtu != data_mtu - 64) {
Expand Down Expand Up @@ -196,11 +196,11 @@ static void test(void)
/*
* wait for PMTUd to pick up the change
*/
sleep(2);
test_sleep(knet_h, 1);
flush_logs(logfds[0], stdout);

if (knet_h->data_mtu != data_mtu) {
printf("knet_handle_pmtud_set failed to redetect MTU\n");
printf("knet_handle_pmtud_set failed to redetect MTU: detected mtu: %u data_mtu: %u \n", knet_h->data_mtu, data_mtu);
knet_link_set_enable(knet_h, 1, 0, 0);
knet_link_clear_config(knet_h, 1, 0);
knet_host_remove(knet_h, 1);
Expand Down
2 changes: 1 addition & 1 deletion libknet/tests/api_knet_link_set_enable.c
Expand Up @@ -293,7 +293,7 @@ static void test_sctp(void)
}

printf("Wait 2 seconds for sockets to connect\n");
sleep(2);
test_sleep(knet_h, 2);

printf("Test knet_link_set_enable with correct values (0)\n");

Expand Down
11 changes: 11 additions & 0 deletions libknet/tests/test-common.c
Expand Up @@ -478,6 +478,15 @@ int make_local_sockaddr6(struct sockaddr_storage *lo, uint16_t offset)
return _make_local_sockaddr(lo, offset, AF_INET6);
}

void test_sleep(knet_handle_t knet_h, int seconds)
{
if (is_memcheck() || is_helgrind()) {
printf("Test suite is running under valgrind, adjusting sleep timers\n");
seconds = seconds * 16;
}
sleep(seconds);
}

int wait_for_host(knet_handle_t knet_h, uint16_t host_id, int seconds, int logfd, FILE *std)
{
int i = 0;
Expand All @@ -490,6 +499,8 @@ int wait_for_host(knet_handle_t knet_h, uint16_t host_id, int seconds, int logfd
while (i < seconds) {
flush_logs(logfd, std);
if (knet_h->host_index[host_id]->status.reachable == 1) {
printf("Waiting for host to settle\n");
test_sleep(knet_h, 1);
return 0;
}
printf("waiting host %u to be reachable for %d more seconds\n", host_id, seconds - i);
Expand Down
1 change: 1 addition & 0 deletions libknet/tests/test-common.h
Expand Up @@ -71,5 +71,6 @@ int make_local_sockaddr(struct sockaddr_storage *lo, uint16_t offset);
int make_local_sockaddr6(struct sockaddr_storage *lo, uint16_t offset);
int wait_for_host(knet_handle_t knet_h, uint16_t host_id, int seconds, int logfd, FILE *std);
int wait_for_packet(knet_handle_t knet_h, int seconds, int datafd, int logfd, FILE *std);
void test_sleep(knet_handle_t knet_h, int seconds);

#endif

0 comments on commit a0128b9

Please sign in to comment.