From owner-p4-projects@FreeBSD.ORG Fri Feb 3 21:36:19 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id D4DC616A423; Fri, 3 Feb 2006 21:36:18 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 95B1E16A420 for ; Fri, 3 Feb 2006 21:36:18 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3F51943D46 for ; Fri, 3 Feb 2006 21:36:18 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k13LaIH2041444 for ; Fri, 3 Feb 2006 21:36:18 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k13LaHN8041441 for perforce@freebsd.org; Fri, 3 Feb 2006 21:36:17 GMT (envelope-from jhb@freebsd.org) Date: Fri, 3 Feb 2006 21:36:17 GMT Message-Id: <200602032136.k13LaHN8041441@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 90999 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Feb 2006 21:36:19 -0000 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) {