Rev 63: ib: adjustment of a test scenario in http://samba.org/~tridge/psomogyi/

psomogyi at gamax.hu psomogyi at gamax.hu
Fri Feb 9 17:06:13 GMT 2007


------------------------------------------------------------
revno: 63
revision-id: psomogyi at gamax.hu-20070209170613-3vdva62qksacmu0h
parent: psomogyi at gamax.hu-20070208180858-5g7ldz23vhs6l19r
committer: Peter Somogyi <psomogyi at gamax.hu>
branch nick: ctdb
timestamp: Fri 2007-02-09 18:06:13 +0100
message:
  ib: adjustment of a test scenario
modified:
  tests/ibwrapper_test.c         ibwrapper_test.c-20061214171730-h11a2z5ed6pt66hj-1
=== modified file 'tests/ibwrapper_test.c'
--- a/tests/ibwrapper_test.c	2007-02-08 18:06:14 +0000
+++ b/tests/ibwrapper_test.c	2007-02-09 17:06:13 +0000
@@ -53,10 +53,11 @@
 	int	naddrs;
 
 	unsigned int	nsec; /* delta times between messages in nanosec */
-	unsigned int	sleep_nsec; /* nanosleep in the main loop to emulate overloading */
+	unsigned int	sleep_usec; /* microsecs to sleep in the main loop to emulate overloading */
 	uint32_t	maxsize; /* maximum variable message size */
 
 	int	cnt;
+	int	nsent;
 
 	int	nmsg; /* number of messages to send (client) */
 
@@ -78,26 +79,6 @@
 	TESTOP_SEND_RND = 3
 };
 
-int ibwtest_nanosleep(unsigned int sleep_nsec)
-{
-//	int nanosleep(const struct timespec *req, struct timespec *rem);
-	struct timespec req, rem;
-
-	memset(&req, 0, sizeof(struct timespec));
-	memset(&rem, 0, sizeof(struct timespec));
-	req.tv_sec = 0;
-	req.tv_nsec = sleep_nsec;
-
-	while (nanosleep(&req, &rem) < 0) {
-		if (errno != EINTR) {
-			DEBUG(0, ("nanosleep ERROR: %d\n", errno));
-			return -1;
-		}
-		memcpy(&req, &rem, sizeof(struct timespec));
-	}
-	return 0;
-}
-
 int ibwtest_connect_everybody(struct ibwtest_ctx *tcx)
 {
 	struct ibwtest_conn	*pconn = talloc_zero(tcx, struct ibwtest_conn);
@@ -136,6 +117,8 @@
 		DEBUG(0, ("send_id: ibw_send error\n"));
 		return -1;
 	}
+	tcx->nsent++;
+
 	return 0;
 }
 
@@ -164,6 +147,8 @@
 		DEBUG(0, ("send_test_msg: ibw_send error\n"));
 		return -1;
 	}
+	tcx->nsent++;
+
 	return 0;
 }
 
@@ -212,6 +197,8 @@
 		DEBUG(0, ("varsize/ibw_send failed\n"));
 		return -1;
 	}
+	tcx->nsent++;
+
 	return 0;
 }
 
@@ -358,6 +345,7 @@
 				fprintf(stderr, "ibw_send error #2\n");
 				return -2;
 			}
+			tcx->nsent++;
 		}
 	} else { /* client: */
 		if (op==TESTOP_SEND_ID && tcx->maxsize) {
@@ -527,7 +515,7 @@
 	printf("\t\t send message periodically and endless when nsec is non-zero\n");
 	printf("\t-s server mode (you have to give exactly one -d address:port in this case)\n");
 	printf("\t-n number of messages to send [default %d]\n", tcx->nmsg);
-	printf("\t-l nsec time to sleep in the main loop [default %d]\n", tcx->sleep_nsec);
+	printf("\t-l usec time to sleep in the main loop [default %d]\n", tcx->sleep_usec);
 	printf("\t-v max variable msg size in bytes [default %d], 0=don't send var. size\n", tcx->maxsize);
 	printf("Press ctrl+C to stop the program.\n");
 }
@@ -535,7 +523,7 @@
 int main(int argc, char *argv[])
 {
 	int	rc, op;
-	int	result = 1, nmsg;
+	int	result = 1;
 	struct event_context *ev = NULL;
 	struct ibwtest_ctx *tcx = NULL;
 	float	usec;
@@ -575,7 +563,7 @@
 			tcx->nmsg = atoi(optarg);
 			break;
 		case 'l':
-			tcx->sleep_nsec = (unsigned int)atoi(optarg);
+			tcx->sleep_usec = (unsigned int)atoi(optarg);
 			break;
 		case 'v':
 			tcx->maxsize = (unsigned int)atoi(optarg);
@@ -590,7 +578,6 @@
 		ibwtest_usage(tcx, argv[0]);
 		goto cleanup;
 	}
-	nmsg = tcx->nmsg;
 
 	ev = event_context_init(NULL);
 	assert(ev);
@@ -619,13 +606,11 @@
 
 		event_loop_once(ev);
 
-		if (tcx->sleep_nsec) {
-			if (ibwtest_nanosleep(tcx->sleep_nsec))
-				goto cleanup;
-		}
+		if (tcx->sleep_usec)
+			usleep(tcx->sleep_usec);
 	}
 
-	if (!tcx->is_server && nmsg!=0 && !tcx->error) {
+	if (!tcx->is_server && tcx->nsent!=0 && !tcx->error) {
 		if (gettimeofday(&tcx->end_time, NULL)) {
 			DEBUG(0, ("gettimeofday error %d\n", errno));
 			goto cleanup;
@@ -633,7 +618,7 @@
 		usec = (tcx->end_time.tv_sec - tcx->start_time.tv_sec) * 1000000 +
 				(tcx->end_time.tv_usec - tcx->start_time.tv_usec);
 		printf("usec: %f, nmsg: %d, usec/nmsg: %f\n",
-			usec, nmsg, usec/(float)nmsg);
+			usec, tcx->nsent, usec/(float)tcx->nsent);
 	}
 
 	if (!tcx->error)



More information about the samba-cvs mailing list