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