Home | History | Annotate | Download | only in tirpc_bottomlevel_clnt_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 <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 		//syslog(LOG_ERR, "getnetconfigent for udp failed");
     79 		fprintf(stderr, "err nconf\n");
     80 		printf("5\n");
     81 		exit(1);
     82 	}
     83 
     84 	svcaddr.len = 0;
     85 	svcaddr.maxlen = ADDRBUFSIZE;
     86 	svcaddr.buf = addrbuf;
     87 
     88 	if (svcaddr.buf == NULL) {
     89 		/* if malloc() failed, print error messages and exit */
     90 		printf("5\n");
     91 		exit(1);
     92 	}
     93 	//printf("svcaddr reserved (%s)\n", argc[1]);
     94 
     95 	if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) {
     96 		fprintf(stderr, "rpcb_getaddr failed!!\n");
     97 		printf("5\n");
     98 		exit(1);
     99 	}
    100 	//printf("svc get\n");
    101 
    102 	client = clnt_dg_create(RPC_ANYFD, &svcaddr,
    103 				progNum, VERSNUM, 1024, 1024);
    104 
    105 	if (client == NULL) {
    106 		clnt_pcreateerror("ERR");
    107 		exit(1);
    108 	}
    109 	//Call tested procedure several times
    110 	//Int test : call INTPROCNUM RPC
    111 	intSnd = -65536;
    112 
    113 	cs = clnt_call(client, INTPROCNUM,
    114 		       (xdrproc_t) xdr_int, (char *)&intSnd,
    115 		       (xdrproc_t) xdr_int, (char *)&intRec, tv);
    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 	//Test positive number
    123 	intSnd = 16777216;
    124 
    125 	cs = clnt_call(client, INTPROCNUM,
    126 		       (xdrproc_t) xdr_int, (char *)&intSnd,
    127 		       (xdrproc_t) xdr_int, (char *)&intRec, tv);
    128 
    129 	if (intSnd != intRec)
    130 		test_status = 1;
    131 	if (run_mode == 1)
    132 		printf("Send (int) : %d, Received : %d\n", intSnd, intRec);
    133 
    134 	//Long test : call LNGPROCNUM RPC
    135 	lngSnd = -430000;
    136 
    137 	cs = clnt_call(client, LNGPROCNUM,
    138 		       (xdrproc_t) xdr_long, (char *)&lngSnd,
    139 		       (xdrproc_t) xdr_long, (char *)&lngRec, tv);
    140 
    141 	if (lngSnd != lngRec)
    142 		test_status = 1;
    143 	if (run_mode == 1)
    144 		printf("Send (long) : %ld, Received : %ld\n", lngSnd, lngRec);
    145 
    146 	//Double test : call DBLPROCNUM RPC
    147 	dblSnd = -1735.63000f;
    148 
    149 	cs = clnt_call(client, DBLPROCNUM,
    150 		       (xdrproc_t) xdr_double, (char *)&dblSnd,
    151 		       (xdrproc_t) xdr_double, (char *)&dblRec, tv);
    152 
    153 	if (dblSnd != dblRec)
    154 		test_status = 1;
    155 	if (run_mode == 1)
    156 		printf("Send (double) : %lf, Received : %lf\n", dblSnd, dblRec);
    157 
    158 	//String test : call STRPROCNUM RPC
    159 	strSnd = "text to send.";
    160 	strRec = malloc(64 * sizeof(char));
    161 
    162 	cs = clnt_call(client, STRPROCNUM,
    163 		       (xdrproc_t) xdr_wrapstring, (char *)&strSnd,
    164 		       (xdrproc_t) xdr_wrapstring, (char *)&strRec, tv);
    165 
    166 	if (strcmp(strSnd, strRec))
    167 		test_status = 1;
    168 	if (run_mode == 1)
    169 		printf("Send (string) : %s, Received : %s\n", strSnd, strRec);
    170 
    171 	//This last printf gives the result status to the tests suite
    172 	//normally should be 0: test has passed or 1: test has failed
    173 	printf("%d\n", test_status);
    174 
    175 	return test_status;
    176 }
    177