[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] cluster/dlm/tests/usertest flood.c



CVSROOT:	/cvs/cluster
Module name:	cluster
Branch: 	STABLE
Changes by:	pcaulfield sourceware org	2007-07-18 15:13:26

Modified files:
	dlm/tests/usertest: flood.c 

Log message:
	Add timeout

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/dlm/tests/usertest/flood.c.diff?cvsroot=cluster&only_with_tag=STABLE&r1=1.1.2.2&r2=1.1.2.3

--- cluster/dlm/tests/usertest/flood.c	2005/12/19 16:43:59	1.1.2.2
+++ cluster/dlm/tests/usertest/flood.c	2007/07/18 15:13:26	1.1.2.3
@@ -37,6 +37,7 @@
     fprintf(file, "   -m <num>   Maximum number of locks to hold (default MAX_INT)\n");
     fprintf(file, "   -i <num>   Show progress in <n> increments (default 1000)\n");
     fprintf(file, "   -n <num>   Number of resources (default 10)\n");
+    fprintf(file, "   -t <secs>  Seconds to run for\n");
     fprintf(file, "   -q         Quit\n");
 
 
@@ -49,15 +50,20 @@
     struct dlm_lksb *lksb = arg;
 
     if (lksb->sb_status == 0) {
+	if (lksb->sb_lkid & 0x80000000) {
+		fprintf(stderr, "got -ve lock ID : %x\n", lksb->sb_lkid);
+	}
 	dlm_unlock(lksb->sb_lkid, 0, lksb, lksb);
 	return;
     }
 
     if (lksb->sb_status == EUNLOCK) {
 	    count--;
-	    free(lksb);
+	    //free(lksb);
+	    return;
     }
-
+    fprintf(stderr, "lock failed: %s\n", strerror(lksb->sb_status));
+    exit(1);
 }
 
 int main(int argc, char *argv[])
@@ -68,16 +74,19 @@
     int  rescount = 10;
     int  increment = 1000;
     int  quiet = 0;
+    int  runtime = 0;
     int  status;
     int  i;
     int  mode = LKM_CRMODE;
     signed char opt;
     char **resources;
+    clock_t start;
+    time_t starttime;
 
     /* Deal with command-line arguments */
     opterr = 0;
     optind = 0;
-    while ((opt=getopt(argc,argv,"?m:i:qn:vV")) != EOF)
+    while ((opt=getopt(argc,argv,"?m:i:qn:t:vV")) != EOF)
     {
 	switch(opt)
 	{
@@ -101,6 +110,10 @@
 	    rescount = atoi(optarg);
 	    break;
 
+	case 't':
+	    runtime = atoi(optarg);
+	    break;
+
 	case 'q':
 	    quiet = 1;
 	    break;
@@ -124,10 +137,12 @@
     pthread_mutex_lock(&mutex);
 
     dlm_pthread_init();
+    start = times(NULL);
 
-    while (1) {
+    starttime = time(NULL);
+    while (runtime?(time(NULL)-starttime<runtime):1) {
 	    char *resource = resources[rand() % rescount];
-	    struct dlm_lksb *lksb = malloc(sizeof(struct dlm_lksb));
+	    struct dlm_lksb *lksb = malloc(sizeof(struct dlm_lksb)+64);
 	    if (!lksb)
 		    exit(1);
 
@@ -150,13 +165,19 @@
 	    count++;
 	    lockops++;
 	    if ((lockops % increment) == 0 && !quiet)
-		    fprintf(stderr, "%d lockops, %d locks\n", lockops, count);
+	    {
+		    fprintf(stderr, "%d lockops, %d locks. Time = %ld\n", lockops, count,
+				times(NULL)-start);
+    		    start = times(NULL);
+	    }
 
 	    while (count > maxlocks) {
 		    sleep(1);
 	    }
 
     }
+    if (runtime)
+	printf("finished %d lock operations\n", lockops);
 
     return 0;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]