Date: Fri, 3 Feb 2006 21:36:17 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 90999 for review Message-ID: <200602032136.k13LaHN8041441@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=90999 Change 90999 by jhb@jhb_slimer on 2006/02/03 21:35:34 Add some simple rwlock tests. Affected files ... .. //depot/projects/smpng/sys/modules/crash/crash.c#29 edit Differences ... ==== //depot/projects/smpng/sys/modules/crash/crash.c#29 (text+ko) ==== @@ -86,6 +86,95 @@ /* Events. */ #ifdef WITNESS + +static void +rw_sleep(void) +{ + rw_init(&baz, "baz"); + rw_rlock(&baz); + tsleep(&baz, curthread->td_priority, "-", 1); + rw_runlock(&baz); + rw_destroy(&baz); +} +CRASH_EVENT("test sleeping with rw lock held", rw_sleep); + +static void +rw_order_sx(void) +{ + rw_init(&baz, "baz"); + printf("Should get a LOR due to baz -> foo:\n"); + rw_wlock(&baz); + sx_slock(&foo); + rw_wunlock(&baz); + sx_sunlock(&foo); + rw_destroy(&baz); +} +CRASH_EVENT("test sx and rw orders", rw_order_sx); + +static void +rw_order_mtx(void) +{ + + rw_init(&baz, "baz"); + mtx_lock(&test_mtx); + rw_rlock(&baz); + rw_runlock(&baz); + mtx_unlock(&test_mtx); + printf("Should get a LOR due to baz -> test_mtx:\n"); + rw_wlock(&baz); + mtx_lock(&test_mtx); + mtx_unlock(&test_mtx); + rw_wunlock(&baz); + rw_destroy(&baz); +} +CRASH_EVENT("test mutex and rw orders", rw_order_mtx); + +#endif + +static void +rw_assert_false(void) +{ + + printf("All of these tests should trigger. You probably want to hack witness and\nrw_assert() to use printf in place of panic first.\n"); + rw_init(&baz, "baz"); + printf("Asserting when unlocked:\n"); + rw_assert(&baz, RA_LOCKED); + rw_assert(&baz, RA_RLOCKED); + rw_assert(&baz, RA_WLOCKED); + printf("Asserting when read locked:\n"); + rw_rlock(&baz); + rw_assert(&baz, RA_WLOCKED); + rw_assert(&baz, RA_UNLOCKED); + rw_runlock(&baz); + printf("Asserting when write locked:\n"); + rw_wlock(&baz); + rw_assert(&baz, RA_RLOCKED); + rw_assert(&baz, RA_UNLOCKED); + rw_wunlock(&baz); + rw_destroy(&baz); +} +CRASH_EVENT("rwlock assertions that should faile", rw_assert_false); + +static void +rw_assert_true(void) +{ + + rw_init(&baz, "baz"); + rw_assert(&baz, RA_UNLOCKED); + rw_rlock(&baz); + rw_assert(&baz, RA_RLOCKED); + rw_assert(&baz, RA_LOCKED); + rw_runlock(&baz); + rw_wlock(&baz); + rw_assert(&baz, RA_WLOCKED); + rw_assert(&baz, RA_LOCKED); + rw_wunlock(&baz); + rw_destroy(&baz); + printf("Passed all tests\n"); +} +CRASH_EVENT("rwlock assertions that should pass", rw_assert_true); + +#ifdef WITNESS static void fault_with_lock(void) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200602032136.k13LaHN8041441>