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@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
average(double * tbl)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
mini(double * tbl)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
maxi(double * tbl)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
main(int argn,char * argc[])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 enum clnt_stat cs;
99 int varSnd = 10;
100 int varRec = -1;
101
102 //Test initialisation
103 maxIter = atoi(argc[3]);
104 resultTbl = malloc(maxIter * sizeof(double));
105
106 //Call tested function several times
107 for (i = 0; i < maxIter; i++) {
108 //Tic
109 gettimeofday(&tv1, &tz);
110
111 //Call function
112 cs = callrpc(argc[1], progNum, VERSNUM, PROCNUM,
113 (xdrproc_t) xdr_int, (char *)&varSnd,
114 (xdrproc_t) xdr_int, (char *)&varRec);
115
116 if (cs != RPC_SUCCESS)
117 clnt_perrno(cs);
118
119 //Toc
120 gettimeofday(&tv2, &tz);
121
122 //Add function execution time (toc-tic)
123 diff =
124 (tv2.tv_sec - tv1.tv_sec) * 1000000L + (tv2.tv_usec -
125 tv1.tv_usec);
126 rslt = (double)diff / 1000;
127
128 if (cs == RPC_SUCCESS) {
129 resultTbl[i] = rslt;
130 } else {
131 test_status = 1;
132 break;
133 }
134
135 if (run_mode) {
136 fprintf(stderr, "lf time = %lf usecn\n", resultTbl[i]);
137 }
138 }
139
140 //This last printf gives the result status to the tests suite
141 //normally should be 0: test has passed or 1: test has failed
142 printf("%d\n", test_status);
143 printf("%lf %d\n", average(resultTbl), maxIter);
144 printf("%lf\n", mini(resultTbl));
145 printf("%lf\n", maxi(resultTbl));
146
147 return test_status;
148 }
149