ping_pong.c

00001 /*
00002  * Copyright (c) 2009 Jiri Svoboda
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 }

Generated on Thu Jun 2 07:45:43 2011 for HelenOS/USB by  doxygen 1.4.7