void *my_thread_process (void * arg) { CLIENT *client = NULL; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; enum clnt_stat cs; int var_snd = 0; int var_rec = -1; struct timeval tv; int i; if (run_mode == 1) { fprintf(stderr, "Thread %d\n", atoi(arg)); } tv.tv_sec = 0; tv.tv_usec = 100; nconf = getnetconfigent("udp"); if (nconf == (struct netconfig *) NULL) { //syslog(LOG_ERR, "getnetconfigent for udp failed"); fprintf(stderr, "err nconf\n"); pthread_exit(5); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == (char *)NULL) { /* if malloc() failed, print error messages and exit */ pthread_exit(5); } //printf("svcaddr reserved (%s)\n", argc[1]); if (!rpcb_getaddr(progNum + atoi(arg), VERSNUM, nconf, &svcaddr, hostname)) { fprintf(stderr, "rpcb_getaddr failed!!\n"); pthread_exit (5); } for (i = 0; i < callNb; i++) { cs = rpcb_rmtcall(nconf, hostname, progNum + atoi(arg), VERSNUM, PROCNUM, (xdrproc_t)xdr_int, (char *)&var_snd, (xdrproc_t)xdr_int, (char *)&var_rec, tv, &svcaddr); thread_array_result[atoi(arg)] += (cs == RPC_SUCCESS); } pthread_exit (0); }
void *my_thread_process (void * arg) { int i; CLIENT *client = NULL; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; int var_snd = 0; int var_rec = -1; struct timeval tv; if (run_mode == 1) { fprintf(stderr, "Thread %d\n", atoi(arg)); } tv.tv_sec = 0; tv.tv_usec = 100; nconf = getnetconfigent("udp"); if (nconf == (struct netconfig *) NULL) { fprintf(stderr, "err nconf\n"); printf("5\n"); exit(5); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == (char *)NULL) { printf("5\n"); exit(5); } if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, hostname)) { fprintf(stderr, "rpcb_getaddr failed!!\n"); printf("5\n"); exit(5); } for (i = 0; i < callNb; i++) { rpcb_rmtcall(nconf, hostname, progNum, VERSNUM, PROCNUM, (xdrproc_t)xdr_int, (char *)&var_snd, (xdrproc_t)xdr_int, (char *)&var_rec, tv, &svcaddr); } pthread_exit (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; int progNum = atoi(argc[2]); CLIENT *client = NULL; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; enum clnt_stat cs; int var_snd = 0; int var_rec = -1; struct timeval tv; //Test initialisation maxIter = atoi(argc[3]); resultTbl = (double *)malloc(maxIter * sizeof(double)); tv.tv_sec = 0; tv.tv_usec = 100; nconf = getnetconfigent("udp"); if (nconf == (struct netconfig *) NULL) { fprintf(stderr, "err nconf\n"); printf("5\n"); exit(5); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == NULL) { printf("5\n"); exit(5); } if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) { fprintf(stderr, "rpcb_getaddr failed!!\n"); printf("5\n"); exit(5); } //Call tested function several times for (i = 0; i < maxIter; i++) { //Tic gettimeofday(&tv1, &tz); //Call function cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, PROCNUM, (xdrproc_t)xdr_int, (char *)&var_snd, (xdrproc_t)xdr_int, (char *)&var_rec, tv, &svcaddr); //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; }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // argc[3] : Number of testes function calls // 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 netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; enum clnt_stat cs; int var_snd = 0; int var_rec = -1; struct timeval tv; int nbCall = atoi(argc[3]); int nbOk = 0; int i; //Initialization if (run_mode) { printf("Before creation\n"); printf("client : %d\n", client); printf("nconf : %d\n", nconf); } tv.tv_sec = 0; tv.tv_usec = 100; nconf = getnetconfigent("udp"); if (nconf == (struct netconfig *) NULL) { //syslog(LOG_ERR, "getnetconfigent for udp failed"); fprintf(stderr, "err nconf\n"); printf("5\n"); exit(5); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == NULL) { printf("5\n"); exit(5); } //printf("svcaddr reserved (%s)\n", argc[1]); if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) { fprintf(stderr, "rpcb_getaddr failed!!\n"); printf("5\n"); exit(5); } for (i = 0; i < nbCall; i++) { cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, PROCNUM, (xdrproc_t)xdr_int, (char *)&var_snd, (xdrproc_t)xdr_int, (char *)&var_rec, tv, &svcaddr); if (cs == RPC_SUCCESS) nbOk++; } if (run_mode == 1) { printf("Aimed : %d\n", nbCall); printf("Got : %d\n", nbOk); } test_status = (nbOk == nbCall) ? 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; }
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]); CLIENT *client = NULL; struct netconfig *nconf = NULL; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; enum clnt_stat cs; struct timeval tv; //Sent variables int intSnd; double dblSnd; long lngSnd; char *strSnd; //Received variables int intRec; double dblRec; long lngRec; char *strRec; //Test initialization tv.tv_sec = 0; tv.tv_usec = 100; nconf = getnetconfigent("udp"); if (nconf == (struct netconfig *) NULL) { fprintf(stderr, "err nconf\n"); printf("5\n"); exit(5); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == NULL) { printf("5\n"); exit(5); } if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, argc[1])) { fprintf(stderr, "rpcb_getaddr failed!!\n"); printf("5\n"); exit(1); } //Call tested procedure several times //Int test : call INTPROCNUM RPC intSnd = -65536; cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, INTPROCNUM, (xdrproc_t) xdr_int, (char *)&intSnd, (xdrproc_t) xdr_int, (char *)&intRec, tv, &svcaddr); if (intSnd != intRec) test_status = 1; if (run_mode == 1) printf("Send (int) : %d, Received : %d\n", intSnd, intRec); //Test positive number intSnd = 16777216; cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, INTPROCNUM, (xdrproc_t) xdr_int, (char *)&intSnd, (xdrproc_t) xdr_int, (char *)&intRec, tv, &svcaddr); 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; cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, LNGPROCNUM, (xdrproc_t) xdr_long, (char *)&lngSnd, (xdrproc_t) xdr_long, (char *)&lngRec, tv, &svcaddr); 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; cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, DBLPROCNUM, (xdrproc_t) xdr_double, (char *)&dblSnd, (xdrproc_t) xdr_double, (char *)&dblRec, tv, &svcaddr); 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)); cs = rpcb_rmtcall(nconf, argc[1], progNum, VERSNUM, STRPROCNUM, (xdrproc_t) xdr_wrapstring, (char *)&strSnd, (xdrproc_t) xdr_wrapstring, (char *)&strRec, tv, &svcaddr); 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; }
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; struct netbuf svcaddr; char addrbuf[ADDRBUFSIZE]; 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); } svcaddr.len = 0; svcaddr.maxlen = ADDRBUFSIZE; svcaddr.buf = addrbuf; if (svcaddr.buf == NULL) { printf("5\n"); pthread_exit(5); } if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, hostname)) { fprintf(stderr, "rpcb_getaddr failed!!\n"); 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); rpcb_rmtcall(nconf, hostname, progNum, VERSNUM, CALCTHREADPROC, (xdrproc_t)xdr_datas, (char *)&vars, (xdrproc_t)xdr_double, (char *)&resTbl[atoi(arg)].svcRes, total_timeout, &svcaddr); 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); }