Home | History | Annotate | Download | only in tirpc_expertlevel_rpcb_rmtcall
      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 <time.h>
     31 #include "lapi/rpc.h"
     32 
     33 //Standard define
     34 #define INTPROCNUM 10
     35 #define DBLPROCNUM 20
     36 #define LNGPROCNUM 30
     37 #define STRPROCNUM 40
     38 #define VERSNUM 1
     39 
     40 //Sys define
     41 #define ADDRBUFSIZE 100
     42 
     43 int main(int argn, char *argc[])
     44 {
     45 	//Program parameters : argc[1] : HostName or Host IP
     46 	//                                         argc[2] : Server Program Number
     47 	//                                         other arguments depend on test case
     48 
     49 	//run_mode can switch into stand alone program or program launch by shell script
     50 	//1 : stand alone, debug mode, more screen information
     51 	//0 : launch by shell script as test case, only one printf -> result status
     52 	int run_mode = 0;
     53 	int test_status = 0;	//Default test result set to PASSED
     54 	int progNum = atoi(argc[2]);
     55 	CLIENT *client = NULL;
     56 	struct netconfig *nconf = NULL;
     57 	struct netbuf svcaddr;
     58 	char addrbuf[ADDRBUFSIZE];
     59 	enum clnt_stat cs;
     60 	struct timeval tv;
     61 	//Sent variables
     62 	int intSnd;
     63 	double dblSnd;
     64 	long lngSnd;
     65 	char *strSnd;
     66 	//Received variables
     67 	int intRec;
     68 	double dblRec;
     69 	long lngRec;
     70 	char *strRec;
     71 
     72 	//Test initialization
     73 	tv.tv_sec = 0;
     74 	tv.tv_usec = 100;
     75 
     76 	nconf = getnetconfigent("udp");
     77 	if (nconf == NULL) {
     78 		fprintf(stderr, "err nconf\n");
     79 		printf("5\n");
     80 		exit(5);
     81 	}
     82 
     83 	svcaddr.len = 0;
     84 	svcaddr.maxlen = ADDRBUFSIZE;
     85 	svcaddr.buf = addrbuf;
     86 
     87 	if (svcaddr.buf == NULL) {
     88 		printf("5\n");
     89 		exit(5);
     90 	}
     91 
     92 	if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) {
     93 		fprintf(stderr, "rpcb_getaddr failed!!\n");
     94 		printf("5\n");
     95 		exit(1);
     96 	}
     97 	//Call tested procedure several times
     98 	//Int test : call INTPROCNUM RPC
     99 	intSnd = -65536;
    100 
    101 	cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, INTPROCNUM,
    102 			  (xdrproc_t) xdr_int, (char *)&intSnd,
    103 			  (xdrproc_t) xdr_int, (char *)&intRec, tv, &svcaddr);
    104 
    105 	if (intSnd != intRec)
    106 		test_status = 1;
    107 	if (run_mode == 1)
    108 		printf("Send (int) : %d, Received : %d\n", intSnd, intRec);
    109 
    110 	//Test positive number
    111 	intSnd = 16777216;
    112 
    113 	cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, INTPROCNUM,
    114 			  (xdrproc_t) xdr_int, (char *)&intSnd,
    115 			  (xdrproc_t) xdr_int, (char *)&intRec, tv, &svcaddr);
    116 
    117 	if (intSnd != intRec)
    118 		test_status = 1;
    119 	if (run_mode == 1)
    120 		printf("Send (int) : %d, Received : %d\n", intSnd, intRec);
    121 
    122 	//Long test : call LNGPROCNUM RPC
    123 	lngSnd = -430000;
    124 
    125 	cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, LNGPROCNUM,
    126 			  (xdrproc_t) xdr_long, (char *)&lngSnd,
    127 			  (xdrproc_t) xdr_long, (char *)&lngRec, tv, &svcaddr);
    128 
    129 	if (lngSnd != lngRec)
    130 		test_status = 1;
    131 	if (run_mode == 1)
    132 		printf("Send (long) : %ld, Received : %ld\n", lngSnd, lngRec);
    133 
    134 	//Double test : call DBLPROCNUM RPC
    135 	dblSnd = -1735.63000f;
    136 
    137 	cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, DBLPROCNUM,
    138 			  (xdrproc_t) xdr_double, (char *)&dblSnd,
    139 			  (xdrproc_t) xdr_double, (char *)&dblRec,
    140 			  tv, &svcaddr);
    141 
    142 	if (dblSnd != dblRec)
    143 		test_status = 1;
    144 	if (run_mode == 1)
    145 		printf("Send (double) : %lf, Received : %lf\n", dblSnd, dblRec);
    146 
    147 	//String test : call STRPROCNUM RPC
    148 	strSnd = "text to send.";
    149 	strRec = malloc(64 * sizeof(char));
    150 
    151 	cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, STRPROCNUM,
    152 			  (xdrproc_t) xdr_wrapstring, (char *)&strSnd,
    153 			  (xdrproc_t) xdr_wrapstring, (char *)&strRec,
    154 			  tv, &svcaddr);
    155 
    156 	if (strcmp(strSnd, strRec))
    157 		test_status = 1;
    158 	if (run_mode == 1)
    159 		printf("Send (string) : %s, Received : %s\n", strSnd, strRec);
    160 
    161 	//This last printf gives the result status to the tests suite
    162 	//normally should be 0: test has passed or 1: test has failed
    163 	printf("%d\n", test_status);
    164 
    165 	return test_status;
    166 }
    167