示例#1
0
int main(int argc, char **argv)
{
     CLIENT *clnt = NULL;
     SVCXPRT *svc = NULL;
	 int progNum = atoi(argv[2]);
	 int test_status = 0;
	 int run_mode = 0;
	 struct timeval tv;
	 long long resTbl[MAXITER];
	 struct timeval tv1,tv2;
     struct timezone tz;
     long long diff;
     int intSnd = 0;
     int intRec;
	 int i;
	 int sum;
	 
	 //Initialization
	 tv.tv_sec = 0;
	 tv.tv_usec = 100;
	 
	 for (i = 0; i < MAXITER; i++)
	 	resTbl[i] = -1;
	 
	 //Create both client and server handle
     svc = svcraw_create();
	 
     if (svc == (SVCXPRT *)NULL) 
     {
          fprintf(stderr,"Could not create server handle\n");
          exit(5);
     }

     if (!svc_register(svc, progNum, VERSNUM, (void *)serverDisp, 0))
     {
     	fprintf(stderr, "Error svc_register\n");
     	exit(5);
     }
     
     clnt = clntraw_create(progNum, VERSNUM);

     if (clnt == (CLIENT *)NULL) 
     {
          clnt_pcreateerror("raw");
          exit(1);
     }
     
     if (run_mode == 1)
     {
     	printf("CLNT %d\n", clnt);
     	printf("SVC %d\n", svc);
     }

	 //Call RPC using testing mode (raw)
	 for (i = 0; i < MAXITER; i++)
	 {
	 	intSnd = i;
     	
     	gettimeofday(&tv1, &tz);
     	if (clnt_call(clnt, PROCNUM, (xdrproc_t)xdr_int, (char *)&intSnd, (xdrproc_t)xdr_int, (char *)&intRec,
       	tv) != RPC_SUCCESS) 
       	{
          	clnt_perror(clnt, "raw");
         	exit(1);
     	}
     	else
     	{
     		gettimeofday(&tv2, &tz);
     		diff = (tv2.tv_sec - tv1.tv_sec) * 1000000L + (tv2.tv_usec - tv1.tv_usec);
     		resTbl[i] = diff;
     	}
     }
     
     //Test all returned values, calc. average
     for (i = 0; i < MAXITER; i++)
     {
	 	if (resTbl[i] == -1)
	 	{
	 		test_status = 1;
	 		break;
	 	}
	 	sum += resTbl[i];
	 	if (run_mode == 1)
	 		fprintf(stderr, "%d\n", resTbl[i]);
	 }
	 sum = (int)(sum / MAXITER);
     
     printf("%d\n", test_status);
}
示例#2
0
int main()
{
    SVCXPRT *rpcServiceTransport = svcraw_create();
    svc_destroy(rpcServiceTransport);
    return 0;
}
示例#3
0
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;
    SVCXPRT *svcr = NULL;

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

    //Call tested function several times
    for (i = 0; i < maxIter; i++)
    {
        //Tic
        gettimeofday(&tv1, &tz);

        //Call function
        svcr = svcraw_create();

        //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 (svcr != NULL)
        {
            resultTbl[i] = rslt;
        }
        else
        {
            test_status = 1;
        }

        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;
}