1c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak/*
2c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* Copyright (c) Bull S.A.  2007 All Rights Reserved.
3c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak*
4c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* This program is free software; you can redistribute it and/or modify it
5c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* under the terms of version 2 of the GNU General Public License as
6c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* published by the Free Software Foundation.
7c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak*
8c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* This program is distributed in the hope that it would be useful, but
9c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* WITHOUT ANY WARRANTY; without even the implied warranty of
10c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak*
12c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* Further, this software is distributed without any warranty that it is
13c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* free of the rightful claim of any third person regarding infringement
14c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* or the like.  Any license provided herein, whether implied or
15c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* otherwise, applies only to this software file.  Patent licenses, if
16c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* any, provided herein do not apply to combinations of this program with
17c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* other software, or any other product whatsoever.
18c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak*
19c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* You should have received a copy of the GNU General Public License along
20fed9641096e27f79a0f2d9adfe9839dd8d11dc0fWanlong Gao* with this program; if not, write the Free Software Foundation, Inc.,
21fed9641096e27f79a0f2d9adfe9839dd8d11dc0fWanlong Gao* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak*
23c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* History:
24c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak* Created by: Cyril Lacabanne (Cyril.Lacabanne@bull.net)
25c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak*
262c28215423293e443469a07ae7011135d058b671Garrett Cooper*/
27c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak
28c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak#include <stdio.h>
29c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak#include <stdlib.h>
30c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak#include <time.h>
31c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak#include <rpc/rpc.h>
32c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak#include <sys/types.h>
33c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak#include <sys/socket.h>
34c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak#include <sys/socketvar.h>
35c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak
36c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak//Standard define
37c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak#define PROCNUM 1
38c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak#define VERSNUM 1
39c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak
407c7aeb5d8beb7b0d634d792e09893cc2206514f1subrata_modakint main(int argn, char *argc[])
41c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak{
42c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	//Program parameters : argc[1] : HostName or Host IP
43354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	//                                         argc[2] : Server Program Number
44354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	//                                         argc[3] : Number of testes function calls
45354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	//                                         other arguments depend on test case
462c28215423293e443469a07ae7011135d058b671Garrett Cooper
47c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	//run_mode can switch into stand alone program or program launch by shell script
48c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	//1 : stand alone, debug mode, more screen information
49c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	//0 : launch by shell script as test case, only one printf -> result status
50c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	int run_mode = 0;
51354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	int test_status = 1;	//Default test result set to FAILED
52c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	int sock = 600;
53c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	SVCXPRT *svcr = NULL;
54354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	int nbCall = atoi(argc[3]);
55c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	int nbOk = 0;
56c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	int i;
572c28215423293e443469a07ae7011135d058b671Garrett Cooper
58c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	//create a server
59c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	sock = socket(AF_UNIX, SOCK_DGRAM, IPPROTO_TCP);
60354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	for (i = 0; i < nbCall; i++) {
61c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak		svcr = svctcp_create(sock, 0, 0);
62df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper		if (svcr != NULL)
63c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak			nbOk++;
64c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	}
652c28215423293e443469a07ae7011135d058b671Garrett Cooper
66c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	//If we are here, macro call was successful
67354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao	if (run_mode == 1) {
68c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak		printf("Aimed : %d\n", nbCall);
69c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak		printf("Got : %d\n", nbOk);
70c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	}
712c28215423293e443469a07ae7011135d058b671Garrett Cooper
72c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	test_status = (nbOk == nbCall) ? 0 : 1;
732c28215423293e443469a07ae7011135d058b671Garrett Cooper
74c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	//clean up
75c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	svc_destroy(svcr);
762c28215423293e443469a07ae7011135d058b671Garrett Cooper
77c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	//This last printf gives the result status to the tests suite
78c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	//normally should be 0: test has passed or 1: test has failed
79c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	printf("%d\n", test_status);
802c28215423293e443469a07ae7011135d058b671Garrett Cooper
81c0caf8f23e4c43743fcac7e5a308d085b2f09107subrata_modak	return test_status;
82ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman}
83