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 33 //Standard define 34 #define PROCNUM 1 35 #define VERSNUM 1 36 37 //Set number of test call 38 int maxIter; 39 40 double average(double *tbl) 41 { 42 //Return average of values in tbl 43 int i; 44 double rslt = 0; 45 46 for (i = 0; i < maxIter; i++) { 47 rslt += tbl[i]; 48 } 49 rslt = rslt / maxIter; 50 return rslt; 51 } 52 53 double mini(double *tbl) 54 { 55 //Return minimal of values in tbl 56 int i; 57 double rslt = tbl[0]; 58 59 for (i = 0; i < maxIter; i++) { 60 if (rslt > tbl[i]) 61 rslt = tbl[i]; 62 } 63 return rslt; 64 } 65 66 double maxi(double *tbl) 67 { 68 //Return maximal of values in tbl 69 int i; 70 double rslt = tbl[0]; 71 72 for (i = 0; i < maxIter; i++) { 73 if (rslt < tbl[i]) 74 rslt = tbl[i]; 75 } 76 return rslt; 77 } 78 79 int main(int argn, char *argc[]) 80 { 81 //Program parameters : argc[1] : HostName or Host IP 82 // argc[2] : Server Program Number 83 // argc[3] : Number of test call 84 // other arguments depend on test case 85 86 //run_mode can switch into stand alone program or program launch by shell script 87 //1 : stand alone, debug mode, more screen information 88 //0 : launch by shell script as test case, only one printf -> result status 89 int run_mode = 0; 90 int test_status = 0; //Default test result set to FAILED 91 int i; 92 double *resultTbl; 93 struct timeval tv1, tv2; 94 struct timezone tz; 95 long long diff; 96 double rslt; 97 int progNum = atoi(argc[2]); 98 char proto[8] = "udp"; 99 CLIENT *clnt = NULL; 100 enum clnt_stat cs; 101 struct timeval to; 102 int varSnd = 10; 103 int varRec = -1; 104 105 //Test initialisation 106 maxIter = atoi(argc[3]); 107 resultTbl = malloc(maxIter * sizeof(double)); 108 to.tv_sec = 1; 109 to.tv_usec = 100; 110 111 clnt = clnt_create(argc[1], progNum, VERSNUM, proto); 112 if (clnt == NULL) { 113 clnt_pcreateerror("err"); 114 printf("5\n"); 115 return 5; 116 } 117 //Call tested function several times 118 for (i = 0; i < maxIter; i++) { 119 //Tic 120 gettimeofday(&tv1, &tz); 121 122 //Call function 123 cs = clnt_call(clnt, PROCNUM, 124 (xdrproc_t) xdr_int, (char *)&varSnd, 125 (xdrproc_t) xdr_int, (char *)&varRec, to); 126 127 if (cs != RPC_SUCCESS) 128 clnt_perrno(cs); 129 130 //Toc 131 gettimeofday(&tv2, &tz); 132 133 //Add function execution time (toc-tic) 134 diff = 135 (tv2.tv_sec - tv1.tv_sec) * 1000000L + (tv2.tv_usec - 136 tv1.tv_usec); 137 rslt = (double)diff / 1000; 138 139 if (cs == RPC_SUCCESS) { 140 resultTbl[i] = rslt; 141 } else { 142 test_status = 1; 143 break; 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