Imported Upstream version 20080331
[ltp-debian.git] / testcases / network / rpc / rpc-tirpc-full-test-suite / tests_pack / rpc_suite / tirpc / tirpc_simple_rpc_broadcast_exp / 4-mt.c
bloba060a832db028775ac231712e736ac912ba5a289
1 /*
2 * Copyright (c) Bull S.A. 2007 All Rights Reserved.
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.
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.
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.
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., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * History:
24 * Created by: Cyril Lacabanne (Cyril.Lacabanne@bull.net)
26 */
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <time.h>
31 #include <tirpc/netconfig.h>
32 #include <tirpc/rpc/rpc.h>
33 #include <tirpc/rpc/types.h>
34 #include <tirpc/rpc/xdr.h>
35 #include <tirpc/rpc/svc.h>
36 #include <errno.h>
38 //Standard define
39 #define PROCNUM 1
40 #define VERSNUM 1
42 static int *thread_array_result;
43 int run_mode;
44 int progNum;
45 char *nettype;
46 int callNb;
48 int eachresult (char *out, struct sockaddr_in *addr)
50 //Nothing to do for that test
51 return 1;
54 void *my_thread_process (void * arg)
56 enum clnt_stat rslt;
57 int sndVar = (int)arg;
58 int recVar;
59 int i;
61 int iTimeOut = 1;
62 int mTimeOut = 1;
64 if (run_mode == 1)
66 fprintf(stderr, "Thread %d\n", (int)arg);
69 for (i = 0; i < callNb; i++)
71 rslt = rpc_broadcast_exp(progNum, VERSNUM, PROCNUM,
72 (xdrproc_t)xdr_int, (char *)&recVar,
73 (xdrproc_t)xdr_int, (char *)&recVar,
74 eachresult, iTimeOut, mTimeOut, nettype);
76 thread_array_result[(int)arg] += (rslt == RPC_SUCCESS);
79 pthread_exit (0);
82 int main(int argn, int *argc[])
84 //Program parameters : argc[1] : HostName or Host IP
85 // argc[2] : Server Program Number
86 // argc[3] : Number of threads
87 // argc[4] : Number of calls per thread
88 // other arguments depend on test case
90 //run_mode can switch into stand alone program or program launch by shell script
91 //1 : stand alone, debug mode, more screen information
92 //0 : launch by shell script as test case, only one printf -> result status
93 run_mode = 0;
94 int test_status = 1; //Default test result set to FAILED
95 int threadNb = atoi(argc[3]);
96 int i;
97 pthread_t *pThreadArray;
98 void *ret;
100 nettype = "visible";
101 progNum = atoi(argc[2]);
102 callNb = atoi(argc[4]);
104 if (run_mode == 1)
106 printf("Server #%d\n", progNum);
107 printf("Thread to create %d\n", threadNb);
110 //Initialization : create threads results array, init elements to 0
111 //Each thread will put function result (pas/fail) into array
112 thread_array_result = (int *)malloc(threadNb * sizeof(int));
113 memset(&thread_array_result[0], 0, threadNb * sizeof(int));
115 //Create all threads
116 //Run all threads
117 pThreadArray = (pthread_t *)malloc(threadNb * sizeof(pthread_t));
118 for (i = 0; i < threadNb; i++)
120 if (run_mode == 1)
121 fprintf (stderr, "Try to create thread %d\n", i);
122 if (pthread_create (&pThreadArray[i], NULL, my_thread_process, i) < 0)
124 fprintf (stderr, "pthread_create error for thread 1\n");
125 exit (1);
129 //Clean threads
130 for (i = 0; i < threadNb; i++)
132 (void)pthread_join (pThreadArray[i], &ret);
135 //Check if all threads results are ok
136 test_status = 0;
137 for (i = 0; i < threadNb; i++)
139 if (thread_array_result[i] != callNb)
141 test_status = 1;
142 break;
146 if (run_mode == 1)
148 for (i = 0; i < threadNb; i++)
150 fprintf(stderr, "Result[%d]=%d\n", i, thread_array_result[i]);
154 //This last printf gives the result status to the tests suite
155 //normally should be 0: test has passed or 1: test has failed
156 printf("%d\n", test_status);
158 return test_status;