00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <sys/time.h>
00032 #include <ipc/ns.h>
00033 #include <async.h>
00034 #include <errno.h>
00035 #include "../tester.h"
00036
00037 #define DURATION_SECS 10
00038 #define COUNT_GRANULARITY 100
00039
00040 const char *test_ping_pong(void)
00041 {
00042 TPRINTF("Pinging ns server for %d seconds...", DURATION_SECS);
00043
00044 struct timeval start;
00045 if (gettimeofday(&start, NULL) != 0) {
00046 TPRINTF("\n");
00047 return "Failed getting the time";
00048 }
00049
00050 uint64_t count = 0;
00051 while (true) {
00052 struct timeval now;
00053 if (gettimeofday(&now, NULL) != 0) {
00054 TPRINTF("\n");
00055 return "Failed getting the time";
00056 }
00057
00058 if (tv_sub(&now, &start) >= DURATION_SECS * 1000000L)
00059 break;
00060
00061 size_t i;
00062 for (i = 0; i < COUNT_GRANULARITY; i++) {
00063 int retval = async_req_0_0(PHONE_NS, NS_PING);
00064
00065 if (retval != EOK) {
00066 TPRINTF("\n");
00067 return "Failed to send ping message";
00068 }
00069 }
00070
00071 count += COUNT_GRANULARITY;
00072 }
00073
00074 TPRINTF("OK\nCompleted %" PRIu64 " round trips in %u seconds, %" PRIu64 " rt/s.\n",
00075 count, DURATION_SECS, count / DURATION_SECS);
00076
00077 return NULL;
00078 }