示例#1
0
/*
 * Generic client creation: takes (servers name, program-number, netconf) and
 * returns client handle. Default options are set, which the user can
 * change using the rpc equivalent of _ioctl()'s : clnt_control()
 * It finds out the server address from rpcbind and calls clnt_tli_create().
 *
 * It calls clnt_tp_create_timed() with the default timeout.
 */
CLIENT *
clnt_tp_create(const char *hostname, rpcprog_t prog, rpcvers_t vers,
    const struct netconfig *nconf)
{

	return (clnt_tp_create_timed(hostname, prog, vers, nconf, NULL));
}
示例#2
0
void *my_thread_process (void * arg)
{
	int i;
	CLIENT *clnt = NULL;
	struct datas vars;
	static double result = 0;
    struct timeval total_timeout;
	struct netconfig *nconf = NULL;
    
    total_timeout.tv_sec = 1;
	total_timeout.tv_usec = 1;
	
	nconf = getnetconfigent("udp");
	
    if ((struct netconfig *)nconf == NULL) 
    {
    	//Test failed
    	printf("5\n");
    	pthread_exit (5);
    }
	
	clnt = clnt_tp_create_timed(hostname, progNum,
                                VERSNUM, (struct netconfig *)nconf, &total_timeout);
	
	if (clnt == (CLIENT *)NULL)
	{
		printf("5\n");
		pthread_exit (5);
	}
	
	if (run_mode == 1)
	{
		fprintf(stderr, "Thread %d\n", atoi(arg));
	}
	
	vars.a = getRand();
	vars.b = getRand();
	vars.c = getRand();
		
	resTbl[atoi(arg)].locRes = vars.a + (vars.b * vars.c);
	
    clnt_call((CLIENT *)clnt, CALCTHREADPROC, 
				(xdrproc_t)xdr_datas, (char *)&vars, // xdr_in
                (xdrproc_t)xdr_double, (char *)&resTbl[atoi(arg)].svcRes, // xdr_out
				total_timeout);
	
	thread_array_result[atoi(arg)] = (resTbl[atoi(arg)].svcRes == resTbl[atoi(arg)].locRes) ? 0 : 1;
	
	if (run_mode == 1)
	{
		fprintf(stderr, "Thread #%d calc : %lf, received : %lf\n", 
		        atoi(arg), resTbl[atoi(arg)].locRes,
		        resTbl[atoi(arg)].svcRes);
	}
    
    pthread_exit (0);
}
示例#3
0
int main(int argn, char *argc[])
{
	//Program parameters : argc[1] : HostName or Host IP
	//                                         argc[2] : Server Program Number
	//                                         other arguments depend on test case

	//run_mode can switch into stand alone program or program launch by shell script
	//1 : stand alone, debug mode, more screen information
	//0 : launch by shell script as test case, only one printf -> result status
	int run_mode = 0;
	int test_status = 1;	//Default test result set to FAILED
	int progNum = atoi(argc[2]);
	CLIENT *client = NULL;
	struct netconfig *nconf = NULL;
	struct timeval tv;
	bool_t rslt = 0;
	int fd = 0;

	//First, test initialization
	nconf = getnetconfigent("udp");

	if ((struct netconfig *)nconf == NULL) {
		//Test failed
		printf("1\n");
		return 1;
	}

	tv.tv_sec = 1;
	tv.tv_usec = 1;

	client = clnt_tp_create_timed(argc[1], progNum,
				      VERSNUM, (struct netconfig *)nconf, &tv);

	//Call routine
	rslt = clnt_control(client, CLGET_FD, (int *)&fd);
	if (run_mode) {
		printf("client : %p\n", client);
		printf("nconf : %p\n", nconf);
		printf("F. Desc. : %d\n", fd);
	}

	test_status = (rslt == 1) ? 0 : 1;

	//This last printf gives the result status to the tests suite
	//normally should be 0: test has passed or 1: test has failed
	printf("%d\n", test_status);

	//clnt_destroy(client);

	return test_status;
}
int main(int argn, char *argc[])
{
	//Program parameters : argc[1] : HostName or Host IP
	//                                         argc[2] : Server Program Number
	//                                         other arguments depend on test case

	//run_mode can switch into stand alone program or program launch by shell script
	//1 : stand alone, debug mode, more screen information
	//0 : launch by shell script as test case, only one printf -> result status
	int run_mode = 0;
	int test_status = 1;	//Default test result set to FAILED
	int progNum = atoi(argc[2]);
	int sndVar = 0;
	int recVar = -1;
	CLIENT *client = NULL;
	struct netconfig *nconf = NULL;
	struct timeval tv;
	enum clnt_stat rslt;

	//First, test initialization : create client using intermediate level API
	nconf = getnetconfigent("udp");

	if ((struct netconfig *)nconf == NULL) {
		//Test failed
		printf("5\n");
		return 5;
	}

	tv.tv_sec = 1;
	tv.tv_usec = 1;

	client = clnt_tp_create_timed(argc[1], progNum,
				      VERSNUM, (struct netconfig *)nconf, &tv);

	if (client == NULL) {
		printf("5\n");
		return 5;
	}
	//Call routine
	rslt = clnt_call(client, PROCNUM, (xdrproc_t) xdr_int, (char *)&sndVar,	// xdr_in
			 (xdrproc_t) xdr_int, (char *)&recVar,	// xdr_out
			 tv);

	test_status = (rslt == RPC_SUCCESS) ? 0 : 1;

	//This last printf gives the result status to the tests suite
	//normally should be 0: test has passed or 1: test has failed
	printf("%d\n", test_status);

	return test_status;
}
示例#5
0
文件: 4-mt.c 项目: shubmit/shub-ltp
void *my_thread_process (void * arg)
{
	int sndVar = 0;
	int recVar = -1;
    CLIENT *client = NULL;
	struct netconfig *nconf = NULL;
	struct timeval tv;
	enum clnt_stat rslt;
	int i;

	if (run_mode == 1)
	{
		fprintf(stderr, "Thread %d\n", atoi(arg));
	}

	//First, test initialization : create client using intermediate level API
	nconf = getnetconfigent("udp");

    if ((struct netconfig *)nconf == NULL)
    {
    	//Test failed
    	printf("5\n");
    	pthread_exit (5);
    }

    tv.tv_sec = 1;
	tv.tv_usec = 1;

    client = clnt_tp_create_timed(hostname, progNum,
                                  VERSNUM, (struct netconfig *)nconf, &tv);

    if (client == NULL)
    {
    	clnt_pcreateerror("ERR");
    	thread_array_result[atoi(arg)] = 0;
    	pthread_exit (5);
    }

	//Call routine
	for (i = 0; i < callNb; i++)
	{
		rslt = clnt_call(client, PROCNUM,
					 	 (xdrproc_t)xdr_int, (char *)&sndVar, // xdr_in
                     	 (xdrproc_t)xdr_int, (char *)&recVar, // xdr_out
                     	 tv);

		thread_array_result[atoi(arg)] += (rslt == RPC_SUCCESS);
	}

    pthread_exit (0);
}
示例#6
0
void *my_thread_process (void * arg)
{
	int i;
	int sndVar = 0;
    int recVar = -1;
    CLIENT *client = NULL;
	struct netconfig *nconf = NULL;
	struct timeval tv;
	
	//First, test initialization : create client using intermediate level API
	nconf = getnetconfigent("udp");
	
    if ((struct netconfig *)nconf == NULL) 
    {
    	//Test failed
    	printf("5\n");
    	pthread_exit((void *)5);
    }
    
    tv.tv_sec = 1;
	tv.tv_usec = 1;
	
    client = clnt_tp_create_timed(hostname, progNum,
                                  VERSNUM, (struct netconfig *)nconf, &tv);
                                  
    if (client == (CLIENT *)NULL)
    {
    	printf("5\n");
    	pthread_exit((void *)5);
    }
	
	if (run_mode == 1)
	{
		fprintf(stderr, "Thread %d\n", atoi(arg));
	}
	
	for (i = 0; i < callNb; i++)
	{
		clnt_call(client, PROCNUM,
					 (xdrproc_t)xdr_int, (char *)&sndVar, // xdr_in
                     (xdrproc_t)xdr_int, (char *)&recVar, // xdr_out
                     tv);
	}
	
	clnt_destroy(client);
    
    pthread_exit (0);
}
示例#7
0
int main(int argn, char *argc[])
{
	//Program parameters : argc[1] : HostName or Host IP
	//					   argc[2] : Server Program Number
	//					   other arguments depend on test case
	
	//run_mode can switch into stand alone program or program launch by shell script
	//1 : stand alone, debug mode, more screen information
	//0 : launch by shell script as test case, only one printf -> result status
	int run_mode = 0;
	int test_status = 0; //Default test result set to PASS
	int progNum = atoi(argc[2]);
	int i;
	params paramList[NBCASE];
	CLIENT *client = NULL;
	struct netconfig *nconf = NULL;
	struct timeval tv;

	//First, test initialization
	nconf = getnetconfigent("udp");
	
    if ((struct netconfig *)nconf == NULL) 
    {
    	//Test failed
    	printf("1\n");
    	return 1;
    }
	
	//Test arguments initialization
	paramList[0].init_tout = 0;
	paramList[0].next_tout = 1;
	paramList[1].init_tout = 1;
	paramList[1].next_tout = 0;
	paramList[2].init_tout = 1;
	paramList[2].next_tout = 1;
	
	//Call tested function using all tests cases
	for (i = 0; i < NBCASE; i++)
	{
		//Debug mode prints
		if (run_mode == 1)
		{
			printf("Test using values : %d ", paramList[i].init_tout);
			printf("%d", paramList[i].next_tout);
			printf("\n");
		}
		
		//Call function
		tv.tv_sec = paramList[i].init_tout;
		tv.tv_usec = paramList[i].next_tout;

		//Call routine
    	client = clnt_tp_create_timed(argc[1], progNum,
                                  	 VERSNUM, (struct netconfig *)nconf, &tv);
		//Check result
		if (client == (CLIENT *)NULL)
		{
			//test has failed
			test_status = 1;
			break;
		}
	}
	
	//This last printf gives the result status to the tests suite
	//normally should be 0: test has passed or 1: test has failed
	printf("%d\n", test_status);
	
	return test_status;
}
示例#8
0
/*
 * This the routine has the same definition as clnt_create(),
 * except it takes an additional timeout parameter - a pointer to
 * a timeval structure.  A NULL value for the pointer indicates
 * that the default timeout value should be used.
 *
 * This function calls clnt_tp_create_timed().
 */
CLIENT *
clnt_create_timed(const char *hostname, rpcprog_t prog, rpcvers_t vers,
    const char *netclass, const struct timeval *tp)
{
	struct netconfig *nconf;
	CLIENT *clnt = NULL;
	void *handle;
	enum clnt_stat	save_cf_stat = RPC_SUCCESS;
	struct rpc_err	save_cf_error;
	char nettype_array[NETIDLEN];
	char *nettype = &nettype_array[0];

	if (netclass == NULL)
		nettype = NULL;
	else {
		size_t len = strlen(netclass);
		if (len >= sizeof (nettype_array)) {
			rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
			return (NULL);
		}
		strcpy(nettype, netclass);
	}

	if ((handle = __rpc_setconf((char *)nettype)) == NULL) {
		rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
		return (NULL);
	}
	rpc_createerr.cf_stat = RPC_SUCCESS;
	while (clnt == NULL) {
		if ((nconf = __rpc_getconf(handle)) == NULL) {
			if (rpc_createerr.cf_stat == RPC_SUCCESS)
				rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
			break;
		}
#ifdef CLNT_DEBUG
		printf("trying netid %s\n", nconf->nc_netid);
#endif
		clnt = clnt_tp_create_timed(hostname, prog, vers, nconf, tp);
		if (clnt)
			break;
		else {
			/*
			 *	Since we didn't get a name-to-address
			 *	translation failure here, we remember
			 *	this particular error.  The object of
			 *	this is to enable us to return to the
			 *	caller a more-specific error than the
			 *	unhelpful ``Name to address translation
			 *	failed'' which might well occur if we
			 *	merely returned the last error (because
			 *	the local loopbacks are typically the
			 *	last ones in /etc/netconfig and the most
			 *	likely to be unable to translate a host
			 *	name).  We also check for a more
			 *	meaningful error than ``unknown host
			 *	name'' for the same reasons.
			 */
			if (rpc_createerr.cf_stat != RPC_N2AXLATEFAILURE &&
			    rpc_createerr.cf_stat != RPC_UNKNOWNHOST) {
				save_cf_stat = rpc_createerr.cf_stat;
				save_cf_error = rpc_createerr.cf_error;
			}
		}
	}

	/*
	 *	Attempt to return an error more specific than ``Name to address
	 *	translation failed'' or ``unknown host name''
	 */
	if ((rpc_createerr.cf_stat == RPC_N2AXLATEFAILURE ||
	     rpc_createerr.cf_stat == RPC_UNKNOWNHOST) &&
	    (save_cf_stat != RPC_SUCCESS)) {
		rpc_createerr.cf_stat = save_cf_stat;
		rpc_createerr.cf_error = save_cf_error;
	}
	__rpc_endconf(handle);
	return (clnt);
}
示例#9
0
int main(int argn, char *argc[])
{
	//Program parameters : argc[1] : HostName or Host IP
	//					   argc[2] : Server Program Number
	//					   other arguments depend on test case

	//run_mode can switch into stand alone program or program launch by shell script
	//1 : stand alone, debug mode, more screen information
	//0 : launch by shell script as test case, only one printf -> result status
	int run_mode = 0;
	int test_status = 0; //Default test result set to PASSED
	int progNum = atoi(argc[2]);
    int recVar = -1;
    CLIENT *client = NULL;
	struct netconfig *nconf = NULL;
	struct timeval tv;
	enum clnt_stat rslt;
	//Sent variables
	int intSnd;
	double dblSnd;
	long lngSnd;
	char *strSnd;
	//Received variables
	int intRec;
	double dblRec;
	long lngRec;
	char *strRec;

	//Test initialization
	//create client using intermediate level API
	nconf = getnetconfigent("udp");

    if ((struct netconfig *)nconf == NULL)
    {
    	//Test failed
    	printf("5\n");
    	return 5;
    }

    tv.tv_sec = 1;
	tv.tv_usec = 1;

    client = clnt_tp_create_timed(argc[1], progNum,
                                  VERSNUM, (struct netconfig *)nconf, &tv);

    if (client == NULL)
    {
    	printf("5\n");
    	return 5;
    }

	//Call tested procedure several times
	//Int test : call INTPROCNUM RPC
	intSnd = -65536;

	rslt = clnt_call(client, INTPROCNUM,
					 (xdrproc_t)xdr_int, (char *)&intSnd, // xdr_in
                     (xdrproc_t)xdr_int, (char *)&intRec, // xdr_out
                     tv);

	if (intSnd != intRec)
		test_status = 1;
	if (run_mode == 1)
		printf("Send (int) : %d, Received : %d\n", intSnd, intRec);

	//Test positive number
	intSnd = 16777216;

	rslt = clnt_call(client, INTPROCNUM,
					 (xdrproc_t)xdr_int, (char *)&intSnd, // xdr_in
                     (xdrproc_t)xdr_int, (char *)&intRec, // xdr_out
                     tv);

	if (intSnd != intRec)
		test_status = 1;
	if (run_mode == 1)
		printf("Send (int) : %d, Received : %d\n", intSnd, intRec);

	//Long test : call LNGPROCNUM RPC
	lngSnd = -430000;

	rslt = clnt_call(client, LNGPROCNUM,
					 (xdrproc_t)xdr_long, (char *)&lngSnd, // xdr_in
                     (xdrproc_t)xdr_long, (char *)&lngRec, // xdr_out
                     tv);

	if (lngSnd != lngRec)
		test_status = 1;
	if (run_mode == 1)
		printf("Send (long) : %ld, Received : %ld\n", lngSnd, lngRec);

	//Double test : call DBLPROCNUM RPC
	dblSnd = -1735.63000f;

	rslt = clnt_call(client, DBLPROCNUM,
					 (xdrproc_t)xdr_double, (char *)&dblSnd, // xdr_in
                     (xdrproc_t)xdr_double, (char *)&dblRec, // xdr_out
                     tv);

	if (dblSnd != dblRec)
		test_status = 1;
	if (run_mode == 1)
		printf("Send (double) : %lf, Received : %lf\n", dblSnd, dblRec);

	//String test : call STRPROCNUM RPC
	strSnd = "text to send.";
	strRec = (char *)malloc(64 * sizeof(char));

	rslt = clnt_call(client, STRPROCNUM,
					 (xdrproc_t)xdr_wrapstring, (char *)&strSnd, // xdr_in
                     (xdrproc_t)xdr_wrapstring, (char *)&strRec, // xdr_out
                     tv);

	if (strcmp(strSnd, strRec))
		test_status = 1;
	if (run_mode == 1)
		printf("Send (string) : %s, Received : %s\n", strSnd, strRec);

	//This last printf gives the result status to the tests suite
	//normally should be 0: test has passed or 1: test has failed
	printf("%d\n", test_status);

	return test_status;
}
示例#10
0
int main(int argn, char *argc[])
{
	//Program parameters : argc[1] : HostName or Host IP
	//					   argc[2] : Server Program Number
	//					   other arguments depend on test case
	
	//run_mode can switch into stand alone program or program launch by shell script
	//1 : stand alone, debug mode, more screen information
	//0 : launch by shell script as test case, only one printf -> result status
	int run_mode = 0;
	int test_status = 0; //Default test result set to PASS
	int progNum = atoi(argc[2]);
	char nettype[16] = "visible";
	CLIENT *client = NULL;
	struct netconfig *nconf = NULL;
	struct timeval tv;
	bool_t rslt = 0;
	int fd = 0;
	struct netconfig *tst_nconf;
	unsigned long clver;

	//First, test initialization
	nconf = getnetconfigent("udp");
	
    if ((struct netconfig *)nconf == NULL) 
    {
    	//Test failed
    	printf("1\n");
    	return 1;
    }
    
    tv.tv_sec = 10;
	tv.tv_usec = 20;

    client = clnt_tp_create_timed(argc[1], progNum,
                                  VERSNUM, (struct netconfig *)nconf, &tv);
    if (client == (CLIENT *)NULL)
    {
    	//No client creation
    	printf("1\n");
    	return 1;
    }
	
	//Call tested function using all tests cases
	rslt = clnt_control(client, CLGET_SVC_ADDR, (struct netbuf *)&tst_nconf);
	if (rslt == 0)
	{
		test_status = 1;
	}
	
	rslt = clnt_control(client, CLGET_TIMEOUT, (struct timeval *)&tv);
	if (rslt == 0)
	{
		test_status = 1;
	}
	
	rslt = clnt_control(client, CLGET_FD, (int *)&fd);
	if (rslt == 0)
	{
		test_status = 1;
	}
	
	rslt = clnt_control(client, CLGET_VERS, (unsigned long *)&clver);
	if (rslt == 0)
	{
		test_status = 1;
	}
	
	//This last printf gives the result status to the tests suite
	//normally should be 0: test has passed or 1: test has failed
	printf("%d\n", test_status);
	
	return test_status;
}
int main(int argn, char *argc[])
{
	//Program parameters : argc[1] : HostName or Host IP
	//                                         argc[2] : Server Program Number
	//                                         argc[3] : Number of test call
	//                                         other arguments depend on test case

	//run_mode can switch into stand alone program or program launch by shell script
	//1 : stand alone, debug mode, more screen information
	//0 : launch by shell script as test case, only one printf -> result status
	int run_mode = 0;
	int test_status = 0;	//Default test result set to FAILED
	int i;
	double *resultTbl;
	struct timeval tv1, tv2;
	struct timezone tz;
	long long diff;
	double rslt;
	int progNum = atoi(argc[2]);
	int sndVar = 0;
	int recVar = -1;
	CLIENT *client = NULL;
	struct netconfig *nconf = NULL;
	struct timeval tv;
	enum clnt_stat cs;

	//Test initialisation
	maxIter = atoi(argc[3]);
	resultTbl = (double *)malloc(maxIter * sizeof(double));

	nconf = getnetconfigent("udp");

	if ((struct netconfig *)nconf == NULL) {
		//Test failed
		printf("5\n");
		return 5;
	}

	tv.tv_sec = 1;
	tv.tv_usec = 1;

	client = clnt_tp_create_timed(argc[1], progNum,
				      VERSNUM, (struct netconfig *)nconf, &tv);

	if (client == NULL) {
		printf("5\n");
		return 5;
	}
	//Call tested function several times
	for (i = 0; i < maxIter; i++) {
		//Tic
		gettimeofday(&tv1, &tz);

		//Call function
		cs = clnt_call(client, PROCNUM, (xdrproc_t) xdr_int, (char *)&sndVar,	// xdr_in
			       (xdrproc_t) xdr_int, (char *)&recVar,	// xdr_out
			       tv);

		//Toc
		gettimeofday(&tv2, &tz);

		//Add function execution time (toc-tic)
		diff =
		    (tv2.tv_sec - tv1.tv_sec) * 1000000L + (tv2.tv_usec -
							    tv1.tv_usec);
		rslt = (double)diff / 1000;

		if (cs == RPC_SUCCESS) {
			resultTbl[i] = rslt;
		} else {
			test_status = 1;
			break;
		}

		if (run_mode) {
			fprintf(stderr, "lf time  = %lf usecn\n", resultTbl[i]);
		}
	}

	//This last printf gives the result status to the tests suite
	//normally should be 0: test has passed or 1: test has failed
	printf("%d\n", test_status);
	printf("%lf %d\n", average(resultTbl), maxIter);
	printf("%lf\n", mini(resultTbl));
	printf("%lf\n", maxi(resultTbl));

	return test_status;
}