Home | History | Annotate | Download | only in rpc_createdestroy_clntudp_create
      1 /*
      2 * Copyright (c) Bull S.A.  2007 All Rights Reserved.
      3 *
      4 * This program is free software; you can redistribute it and/or modify it
      5 * under the terms of version 2 of the GNU General Public License as
      6 * published by the Free Software Foundation.
      7 *
      8 * This program is distributed in the hope that it would be useful, but
      9 * WITHOUT ANY WARRANTY; without even the implied warranty of
     10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     11 *
     12 * Further, this software is distributed without any warranty that it is
     13 * free of the rightful claim of any third person regarding infringement
     14 * or the like.  Any license provided herein, whether implied or
     15 * otherwise, applies only to this software file.  Patent licenses, if
     16 * any, provided herein do not apply to combinations of this program with
     17 * other software, or any other product whatsoever.
     18 *
     19 * You should have received a copy of the GNU General Public License along
     20 * with this program; if not, write the Free Software Foundation, Inc.,
     21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     22 *
     23 * History:
     24 * Created by: Cyril Lacabanne (Cyril.Lacabanne (at) bull.net)
     25 *
     26 */
     27 
     28 #include <stdio.h>
     29 #include <stdlib.h>
     30 #include <sys/time.h>
     31 #include <rpc/rpc.h>
     32 #include <netdb.h>
     33 
     34 //Standard define
     35 #define PROCNUM 1
     36 #define VERSNUM 1
     37 
     38 //Set number of test call
     39 int maxIter;
     40 
     41 double average(double *tbl)
     42 {
     43 	//Return average of values in tbl
     44 	int i;
     45 	double rslt = 0;
     46 
     47 	for (i = 0; i < maxIter; i++) {
     48 		rslt += tbl[i];
     49 	}
     50 	rslt = rslt / maxIter;
     51 	return rslt;
     52 }
     53 
     54 double mini(double *tbl)
     55 {
     56 	//Return minimal of values in tbl
     57 	int i;
     58 	double rslt = tbl[0];
     59 
     60 	for (i = 0; i < maxIter; i++) {
     61 		if (rslt > tbl[i])
     62 			rslt = tbl[i];
     63 	}
     64 	return rslt;
     65 }
     66 
     67 double maxi(double *tbl)
     68 {
     69 	//Return maximal of values in tbl
     70 	int i;
     71 	double rslt = tbl[0];
     72 
     73 	for (i = 0; i < maxIter; i++) {
     74 		if (rslt < tbl[i])
     75 			rslt = tbl[i];
     76 	}
     77 	return rslt;
     78 }
     79 
     80 int main(int argn, char *argc[])
     81 {
     82 	//Program parameters : argc[1] : HostName or Host IP
     83 	//                                         argc[2] : Server Program Number
     84 	//                                         argc[3] : Number of test call
     85 	//                                         other arguments depend on test case
     86 
     87 	//run_mode can switch into stand alone program or program launch by shell script
     88 	//1 : stand alone, debug mode, more screen information
     89 	//0 : launch by shell script as test case, only one printf -> result status
     90 	int run_mode = 0;
     91 	int test_status = 0;	//Default test result set to FAILED
     92 	int i;
     93 	double *resultTbl;
     94 	struct timeval tv1, tv2;
     95 	struct timezone tz;
     96 	long long diff;
     97 	double rslt;
     98 	int progNum = atoi(argc[2]);
     99 	CLIENT *clnt = NULL;
    100 	struct sockaddr_in server_addr;
    101 	struct hostent *hp = NULL;
    102 	struct timeval pertry_timeout;
    103 	int sock = RPC_ANYSOCK;
    104 
    105 	//Test initialisation
    106 	maxIter = atoi(argc[3]);
    107 	resultTbl = malloc(maxIter * sizeof(double));
    108 
    109 	if ((hp = gethostbyname(argc[1])) == NULL) {
    110 		fprintf(stderr, "can't get addr for %s\n", argc[1]);
    111 		exit(-1);
    112 	}
    113 
    114 	pertry_timeout.tv_sec = 1;
    115 	pertry_timeout.tv_usec = 0;
    116 
    117 	bcopy(hp->h_addr, (caddr_t) & server_addr.sin_addr, hp->h_length);
    118 	server_addr.sin_family = AF_INET;
    119 	server_addr.sin_port = 0;
    120 
    121 	//Call tested function several times
    122 	for (i = 0; i < maxIter; i++) {
    123 		//Tic
    124 		gettimeofday(&tv1, &tz);
    125 
    126 		//Call function
    127 		clnt =
    128 		    clntudp_create(&server_addr, progNum, VERSNUM,
    129 				   pertry_timeout, &sock);
    130 
    131 		//Toc
    132 		gettimeofday(&tv2, &tz);
    133 
    134 		//Add function execution time (toc-tic)
    135 		diff =
    136 		    (tv2.tv_sec - tv1.tv_sec) * 1000000L + (tv2.tv_usec -
    137 							    tv1.tv_usec);
    138 		rslt = (double)diff / 1000;
    139 
    140 		if (clnt != NULL) {
    141 			resultTbl[i] = rslt;
    142 		} else {
    143 			test_status = 1;
    144 		}
    145 
    146 		if (run_mode) {
    147 			fprintf(stderr, "lf time  = %lf usecn\n", resultTbl[i]);
    148 		}
    149 	}
    150 
    151 	//This last printf gives the result status to the tests suite
    152 	//normally should be 0: test has passed or 1: test has failed
    153 	printf("%d\n", test_status);
    154 	printf("%lf %d\n", average(resultTbl), maxIter);
    155 	printf("%lf\n", mini(resultTbl));
    156 	printf("%lf\n", maxi(resultTbl));
    157 
    158 	return test_status;
    159 }
    160