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