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.
24 * Created by: Cyril Lacabanne (Cyril.Lacabanne@bull.net)
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>
42 static int *thread_array_result
;
48 int eachresult (char *out
, struct sockaddr_in
*addr
)
50 //Nothing to do for that test
54 void *my_thread_process (void * arg
)
57 int sndVar
= (int)arg
;
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
);
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
94 int test_status
= 1; //Default test result set to FAILED
95 int threadNb
= atoi(argc
[3]);
97 pthread_t
*pThreadArray
;
101 progNum
= atoi(argc
[2]);
102 callNb
= atoi(argc
[4]);
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));
117 pThreadArray
= (pthread_t
*)malloc(threadNb
* sizeof(pthread_t
));
118 for (i
= 0; i
< threadNb
; i
++)
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");
130 for (i
= 0; i
< threadNb
; i
++)
132 (void)pthread_join (pThreadArray
[i
], &ret
);
135 //Check if all threads results are ok
137 for (i
= 0; i
< threadNb
; i
++)
139 if (thread_array_result
[i
] != callNb
)
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
);