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 //Set number of test call 38 int maxIter; 39 40 //Sys define 41 #define ADDRBUFSIZE 100 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 CLIENT *client = NULL; 102 struct netconfig *nconf = NULL; 103 struct netbuf svcaddr; 104 char addrbuf[ADDRBUFSIZE]; 105 enum clnt_stat cs; 106 int var_snd = 0; 107 int var_rec = -1; 108 struct timeval tv; 109 110 //Test initialisation 111 maxIter = atoi(argc[3]); 112 resultTbl = malloc(maxIter * sizeof(double)); 113 114 if (run_mode) { 115 printf("Before creation\n"); 116 } 117 118 tv.tv_sec = 0; 119 tv.tv_usec = 100; 120 121 nconf = getnetconfigent("udp"); 122 if (nconf == NULL) { 123 fprintf(stderr, "err nconf\n"); 124 printf("5\n"); 125 exit(5); 126 } 127 128 svcaddr.len = 0; 129 svcaddr.maxlen = ADDRBUFSIZE; 130 svcaddr.buf = addrbuf; 131 132 if (svcaddr.buf == NULL) { 133 printf("5\n"); 134 exit(5); 135 } 136 137 if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) { 138 fprintf(stderr, "rpcb_getaddr failed!!\n"); 139 printf("5\n"); 140 exit(5); 141 } 142 143 client = clnt_tli_create(RPC_ANYFD, nconf, &svcaddr, 144 progNum, VERSNUM, 0, 0); 145 146 if (client == NULL) { 147 printf("5\n"); 148 exit(1); 149 } 150 //Call tested function several times 151 for (i = 0; i < maxIter; i++) { 152 //Tic 153 gettimeofday(&tv1, &tz); 154 155 //Call function 156 cs = clnt_call(client, PROCNUM, 157 (xdrproc_t) xdr_int, (char *)&var_snd, 158 (xdrproc_t) xdr_int, (char *)&var_rec, tv); 159 160 //Toc 161 gettimeofday(&tv2, &tz); 162 163 //Add function execution time (toc-tic) 164 diff = 165 (tv2.tv_sec - tv1.tv_sec) * 1000000L + (tv2.tv_usec - 166 tv1.tv_usec); 167 rslt = (double)diff / 1000; 168 169 if (cs == RPC_SUCCESS) { 170 resultTbl[i] = rslt; 171 } else { 172 test_status = 1; 173 break; 174 } 175 176 if (run_mode) { 177 fprintf(stderr, "lf time = %lf usecn\n", resultTbl[i]); 178 } 179 } 180 181 //This last printf gives the result status to the tests suite 182 //normally should be 0: test has passed or 1: test has failed 183 printf("%d\n", test_status); 184 printf("%lf %d\n", average(resultTbl), maxIter); 185 printf("%lf\n", mini(resultTbl)); 186 printf("%lf\n", maxi(resultTbl)); 187 188 return test_status; 189 } 190