Skip to content

Commit

Permalink
[tests] implement common and more flexible wait_for_host implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Nov 23, 2017
1 parent 47c7504 commit 1f04cf1
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 18 deletions.
12 changes: 9 additions & 3 deletions libknet/tests/api_knet_handle_clear_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,15 @@ static void test(void)
exit(FAIL);
}

while(knet_h->host_index[1]->status.reachable != 1) {
printf("waiting host to be reachable\n");
sleep(1);
if (wait_for_host(knet_h, 1, 10, logfds[0], stdout) < 0) {
printf("timeout waiting for host to be reachable");
knet_link_set_enable(knet_h, 1, 0, 0);
knet_link_clear_config(knet_h, 1, 0);
knet_host_remove(knet_h, 1);
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}

send_len = knet_send(knet_h, send_buff, KNET_MAX_PACKET_SIZE, channel);
Expand Down
12 changes: 9 additions & 3 deletions libknet/tests/api_knet_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,15 @@ static void test(void)
exit(FAIL);
}

while(knet_h->host_index[1]->status.reachable != 1) {
printf("waiting host to be reachable\n");
sleep(1);
if (wait_for_host(knet_h, 1, 10, logfds[0], stdout) < 0) {
printf("timeout waiting for host to be reachable");
knet_link_set_enable(knet_h, 1, 0, 0);
knet_link_clear_config(knet_h, 1, 0);
knet_host_remove(knet_h, 1);
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}

send_len = knet_send(knet_h, send_buff, KNET_MAX_PACKET_SIZE, channel);
Expand Down
12 changes: 9 additions & 3 deletions libknet/tests/api_knet_send_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,15 @@ static void test(const char *model)
exit(FAIL);
}

while(knet_h->host_index[1]->status.reachable != 1) {
printf("waiting host to be reachable\n");
sleep(1);
if (wait_for_host(knet_h, 1, 10, logfds[0], stdout) < 0) {
printf("timeout waiting for host to be reachable");
knet_link_set_enable(knet_h, 1, 0, 0);
knet_link_clear_config(knet_h, 1, 0);
knet_host_remove(knet_h, 1);
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}

send_len = knet_send(knet_h, send_buff, KNET_MAX_PACKET_SIZE, channel);
Expand Down
12 changes: 9 additions & 3 deletions libknet/tests/api_knet_send_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,15 @@ static void test(const char *model)
exit(FAIL);
}

while(knet_h->host_index[1]->status.reachable != 1) {
printf("waiting host to be reachable\n");
sleep(1);
if (wait_for_host(knet_h, 1, 10, logfds[0], stdout) < 0) {
printf("timeout waiting for host to be reachable");
knet_link_set_enable(knet_h, 1, 0, 0);
knet_link_clear_config(knet_h, 1, 0);
knet_host_remove(knet_h, 1);
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}

send_len = knet_send(knet_h, send_buff, KNET_MAX_PACKET_SIZE, channel);
Expand Down
12 changes: 9 additions & 3 deletions libknet/tests/api_knet_send_loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,15 @@ static void test(void)
exit(FAIL);
}

while(knet_h->host_index[1]->status.reachable != 1) {
printf("waiting host to be reachable\n");
sleep(1);
if (wait_for_host(knet_h, 1, 10, logfds[0], stdout) < 0) {
printf("timeout waiting for host to be reachable");
knet_link_set_enable(knet_h, 1, 0, 0);
knet_link_clear_config(knet_h, 1, 0);
knet_host_remove(knet_h, 1);
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}

send_len = knet_send(knet_h, send_buff, KNET_MAX_PACKET_SIZE, channel);
Expand Down
12 changes: 9 additions & 3 deletions libknet/tests/api_knet_send_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,15 @@ static void test(void)
exit(FAIL);
}

while(knet_h->host_index[1]->status.reachable != 1) {
printf("waiting host to be reachable\n");
sleep(1);
if (wait_for_host(knet_h, 1, 10, logfds[0], stdout) < 0) {
printf("timeout waiting for host to be reachable");
knet_link_set_enable(knet_h, 1, 0, 0);
knet_link_clear_config(knet_h, 1, 0);
knet_host_remove(knet_h, 1);
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}

dhost_filter_ret = 2;
Expand Down
16 changes: 16 additions & 0 deletions libknet/tests/test-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,19 @@ int make_local_sockaddr(struct sockaddr_storage *lo, uint16_t offset)

return knet_strtoaddr("127.0.0.1", portstr, lo, sizeof(struct sockaddr_storage));
}

int wait_for_host(knet_handle_t knet_h, uint16_t host_id, int seconds, int logfd, FILE *std)
{
int i = 0;

while (i < seconds) {
flush_logs(logfd, std);
if (knet_h->host_index[host_id]->status.reachable == 1) {
return 0;
}
printf("waiting host %u to be reachable for %d more seconds\n", host_id, seconds - i);
sleep(1);
i++;
}
return -1;
}
1 change: 1 addition & 0 deletions libknet/tests/test-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ void flush_logs(int logfd, FILE *std);
int start_logthread(int logfd, FILE *std);
int stop_logthread(void);
int make_local_sockaddr(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);

#endif

0 comments on commit 1f04cf1

Please sign in to comment.