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 <string.h>
31 #include <time.h>
32 #include <rpc/rpc.h>
33
34 //Standard define
35 #define INTPROCNUM 1000
36 #define DBLPROCNUM 2000
37 #define LNGPROCNUM 3000
38 #define STRPROCNUM 4000
39 #define VERSNUM 1
40
main(int argn,char * argc[])41 int main(int argn, char *argc[])
42 {
43 //Program parameters : argc[1] : HostName or Host IP
44 // argc[2] : Server Program Number
45 // other arguments depend on test case
46
47 //run_mode can switch into stand alone program or program launch by shell script
48 //1 : stand alone, debug mode, more screen information
49 //0 : launch by shell script as test case, only one printf -> result status
50 int run_mode = 0;
51 int test_status = 0; //Default test result set to PASSED
52 int progNum = atoi(argc[2]);
53 //Sent variables
54 int intSnd;
55 double dblSnd;
56 long lngSnd;
57 char *strSnd;
58 //Received variables
59 int intRec;
60 double dblRec;
61 long lngRec;
62 char *strRec;
63
64 //Test initialization
65
66 //Call tested procedure several times
67 //Int test : call INTPROCNUM RPC
68 intSnd = -65536;
69
70 callrpc(argc[1], progNum, VERSNUM, INTPROCNUM,
71 (xdrproc_t) xdr_int, (char *)&intSnd,
72 (xdrproc_t) xdr_int, (char *)&intRec);
73
74 if (intSnd != intRec)
75 test_status = 1;
76 if (run_mode == 1)
77 printf("Send (int) : %d, Received : %d\n", intSnd, intRec);
78
79 //Test positive number
80 intSnd = 16777216;
81
82 callrpc(argc[1], progNum, VERSNUM, INTPROCNUM,
83 (xdrproc_t) xdr_int, (char *)&intSnd,
84 (xdrproc_t) xdr_int, (char *)&intRec);
85
86 if (intSnd != intRec)
87 test_status = 1;
88 if (run_mode == 1)
89 printf("Send (int) : %d, Received : %d\n", intSnd, intRec);
90
91 //Long test : call LNGPROCNUM RPC
92 lngSnd = -430000;
93
94 callrpc(argc[1], progNum, VERSNUM, LNGPROCNUM,
95 (xdrproc_t) xdr_long, (char *)&lngSnd,
96 (xdrproc_t) xdr_long, (char *)&lngRec);
97
98 if (lngSnd != lngRec)
99 test_status = 1;
100 if (run_mode == 1)
101 printf("Send (long) : %ld, Received : %ld\n", lngSnd, lngRec);
102
103 //Double test : call DBLPROCNUM RPC
104 dblSnd = -1735.63000f;
105
106 callrpc(argc[1], progNum, VERSNUM, DBLPROCNUM,
107 (xdrproc_t) xdr_double, (char *)&dblSnd,
108 (xdrproc_t) xdr_double, (char *)&dblRec);
109
110 if (dblSnd != dblRec)
111 test_status = 1;
112 if (run_mode == 1)
113 printf("Send (double) : %lf, Received : %lf\n", dblSnd, dblRec);
114
115 //String test : call STRPROCNUM RPC
116 strSnd = "text to send.";
117 strRec = malloc(64 * sizeof(char));
118
119 callrpc(argc[1], progNum, VERSNUM, STRPROCNUM,
120 (xdrproc_t) xdr_wrapstring, (char *)&strSnd,
121 (xdrproc_t) xdr_wrapstring, (char *)&strRec);
122
123 if (strcmp(strSnd, strRec))
124 test_status = 1;
125 if (run_mode == 1)
126 printf("Send (string) : %s, Received : %s\n", strSnd, strRec);
127
128 //This last printf gives the result status to the tests suite
129 //normally should be 0: test has passed or 1: test has failed
130 printf("%d\n", test_status);
131
132 return test_status;
133 }
134