PERFORCE change 44569 for review

John Baldwin jhb at FreeBSD.org
Tue Dec 30 13:46:38 PST 2003


http://perforce.freebsd.org/chv.cgi?CH=44569

Change 44569 by jhb at jhb_laptop on 2003/12/30 13:46:24

	Add another test case for try lock and recursive mutexes.

Affected files ...

.. //depot/projects/smpng/sys/modules/crash/crash.c#6 edit

Differences ...

==== //depot/projects/smpng/sys/modules/crash/crash.c#6 (text+ko) ====

@@ -51,7 +51,7 @@
 #include <sys/sysctl.h>
 #include <sys/systm.h>
 
-#define	MAX_EVENT	17
+#define	MAX_EVENT	18
 
 static struct sx foo, bar, bar2;
 static struct cv event_cv;
@@ -76,7 +76,8 @@
 	"assert that Giant is locked while it is unlocked",
 	"assert that foo is slocked while it is xlocked",
 	"lock test, slock foo, sunlock foo, unlock test",
-	"use test1 and test2 mutexes to test witness removal"
+	"use test1 and test2 mutexes to test witness removal",
+	"try lock tests including recursion test"
 };
 
 static int	mod_event(struct module *module, int cmd, void *arg);
@@ -111,7 +112,7 @@
 static void
 crash_thread(void *arg)
 {
-	int ev;
+	int ev, status;
 
 	while (1) {
 		mtx_lock(&event_mtx);
@@ -231,6 +232,35 @@
 			mtx_destroy(&test2_mtx);
 			Debugger("test1 and test2 should be gone");
 			break;
+		case 18:
+			bzero(&test1_mtx, sizeof(test1_mtx));
+			bzero(&test1_mtx, sizeof(test2_mtx));
+			mtx_init(&test1_mtx, "test1", NULL, MTX_DEF);
+			mtx_init(&test1_mtx, "test2", NULL, MTX_DEF |
+			    MTX_RECURSE);
+			status = mtx_trylock(&test1_mtx);
+			printf("Try lock of unlocked test1: %d\n", status);
+			if (status)
+				mtx_unlock(&test1_mtx);
+			mtx_lock(&test1_mtx);
+			status = mtx_trylock(&test1_mtx);
+			printf("Try lock of non-recursive locked test1: %d\n",
+			    status);
+			if (status)
+				mtx_unlock(&test1_mtx);
+			mtx_unlock(&test1_mtx);
+			status = mtx_trylock(&test2_mtx);
+			printf("Try lock of unlocked test2: %d\n", status);
+			if (status)
+				mtx_unlock(&test2_mtx);
+			mtx_lock(&test2_mtx);
+			status = mtx_trylock(&test2_mtx);
+			printf("Try lock of recursive locked test2: %d\n",
+			    status);
+			if (status)
+				mtx_unlock(&test2_mtx);
+			mtx_unlock(&test2_mtx);
+			break;
 		default:
 			panic("event %d is bogus\n", event);
 		}


More information about the p4-projects mailing list