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 <tirpc/rpc/rpc.h> 32 33 //Standard define 34 #define PROCNUM 1 35 #define VERSNUM 1 36 37 //Sys define 38 #define ADDRBUFSIZE 100 39 40 //Set number of test call 41 int maxIter; 42 43 double average(double *tbl) 44 { 45 //Return average of values in tbl 46 int i; 47 double rslt = 0; 48 49 for (i = 0; i < maxIter; i++) { 50 rslt += tbl[i]; 51 } 52 rslt = rslt / maxIter; 53 return rslt; 54 } 55 56 double mini(double *tbl) 57 { 58 //Return minimal of values in tbl 59 int i; 60 double rslt = tbl[0]; 61 62 for (i = 0; i < maxIter; i++) { 63 if (rslt > tbl[i]) 64 rslt = tbl[i]; 65 } 66 return rslt; 67 } 68 69 double maxi(double *tbl) 70 { 71 //Return maximal of values in tbl 72 int i; 73 double rslt = tbl[0]; 74 75 for (i = 0; i < maxIter; i++) { 76 if (rslt < tbl[i]) 77 rslt = tbl[i]; 78 } 79 return rslt; 80 } 81 82 int main(int argn, char *argc[]) 83 { 84 //Program parameters : argc[1] : HostName or Host IP 85 // argc[2] : Server Program Number 86 // argc[3] : Number of test call 87 // other arguments depend on test case 88 89 //run_mode can switch into stand alone program or program launch by shell script 90 //1 : stand alone, debug mode, more screen information 91 //0 : launch by shell script as test case, only one printf -> result status 92 int run_mode = 0; 93 int test_status = 0; //Default test result set to FAILED 94 int i; 95 double *resultTbl; 96 struct timeval tv1, tv2; 97 struct timezone tz; 98 long long diff; 99 double rslt; 100 int progNum = atoi(argc[2]); 101 struct netconfig *nconf = NULL; 102 struct netbuf svcaddr; 103 char addrbuf[ADDRBUFSIZE]; 104 enum clnt_stat cs; 105 int var_snd = 0; 106 int var_rec = -1; 107 struct timeval tv; 108 109 //Test initialisation 110 maxIter = atoi(argc[3]); 111 resultTbl = malloc(maxIter * sizeof(double)); 112 113 tv.tv_sec = 0; 114 tv.tv_usec = 100; 115 116 nconf = getnetconfigent("udp"); 117 if (nconf == NULL) { 118 fprintf(stderr, "err nconf\n"); 119 printf("5\n"); 120 exit(5); 121 } 122 123 svcaddr.len = 0; 124 svcaddr.maxlen = ADDRBUFSIZE; 125 svcaddr.buf = addrbuf; 126 127 if (svcaddr.buf == NULL) { 128 printf("5\n"); 129 exit(5); 130 } 131 132 if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) { 133 fprintf(stderr, "rpcb_getaddr failed!!\n"); 134 printf("5\n"); 135 exit(5); 136 } 137 //Call tested function several times 138 for (i = 0; i < maxIter; i++) { 139 //Tic 140 gettimeofday(&tv1, &tz); 141 142 //Call function 143 cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, PROCNUM, 144 (xdrproc_t) xdr_int, (char *)&var_snd, 145 (xdrproc_t) xdr_int, (char *)&var_rec, 146 tv, &svcaddr); 147 148 //Toc 149 gettimeofday(&tv2, &tz); 150 151 //Add function execution time (toc-tic) 152 diff = 153 (tv2.tv_sec - tv1.tv_sec) * 1000000L + (tv2.tv_usec - 154 tv1.tv_usec); 155 rslt = (double)diff / 1000; 156 157 if (cs == RPC_SUCCESS) { 158 resultTbl[i] = rslt; 159 } else { 160 test_status = 1; 161 break; 162 } 163 164 if (run_mode) { 165 fprintf(stderr, "lf time = %lf usecn\n", resultTbl[i]); 166 } 167 } 168 169 //This last printf gives the result status to the tests suite 170 //normally should be 0: test has passed or 1: test has failed 171 printf("%d\n", test_status); 172 printf("%lf %d\n", average(resultTbl), maxIter); 173 printf("%lf\n", mini(resultTbl)); 174 printf("%lf\n", maxi(resultTbl)); 175 176 return test_status; 177 } 178