Date: Mon, 23 Jul 2012 20:21:37 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r239713 - in soc2012/gmiller/locking-head: . tools/regression/lib/libwitness Message-ID: <20120723202137.D19F81065673@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gmiller Date: Mon Jul 23 20:21:37 2012 New Revision: 239713 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239713 Log: r239753@FreeBSD-dev: root | 2012-07-23 13:35:03 -0500 Add tests for blessed locks. Added: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.c soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.t - copied unchanged from r239709, soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setorder.t Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile Modified: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile ============================================================================== --- soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile Mon Jul 23 20:21:21 2012 (r239712) +++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile Mon Jul 23 20:21:37 2012 (r239713) @@ -1,6 +1,6 @@ # $FreeBSD$ -TESTS= lor-basic setorder +TESTS= lor-basic setorder bless CFLAGS+= -g -Wall -Wextra -Werror -lwitness .PHONY: tests @@ -16,3 +16,6 @@ setorder: setorder.c check.c ${CC} -o setorder setorder.c check.c ${CFLAGS} + +bless: bless.c check.c + ${CC} -o bless bless.c check.c ${CFLAGS} Added: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.c Mon Jul 23 20:21:37 2012 (r239713) @@ -0,0 +1,121 @@ +/*- + * Copyright (c) 2012 Greg Miller <gmiller@freebsd.org>.. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include <pthread.h> +#include <pthread_np.h> +#include <stdio.h> + +#include "check.h" + +void +unbless_test(void) +{ + pthread_spinlock_t spin1; + pthread_spinlock_t spin2; + + pthread_spin_init(&spin1, PTHREAD_PROCESS_PRIVATE); + pthread_spin_init(&spin2, PTHREAD_PROCESS_PRIVATE); + + pthread_spin_lock(&spin1); + pthread_spin_lock(&spin2); + + pthread_spin_unlock(&spin2); + pthread_spin_unlock(&spin1); + + pthread_spin_lock(&spin2); + pthread_spin_lock(&spin1); + + pthread_spin_unlock(&spin1); + pthread_spin_unlock(&spin2); +} + +void +bless_test(void) +{ + pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; + pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER; + + pthread_lor_clear_np(); + pthread_lockorder_reset_np(); + pthread_lockorder_bless_np(&mutex1, &mutex2); + + pthread_mutex_lock(&mutex1); + pthread_mutex_lock(&mutex2); + + pthread_mutex_unlock(&mutex2); + pthread_mutex_unlock(&mutex1); + + pthread_mutex_lock(&mutex2); + pthread_mutex_lock(&mutex1); + + pthread_mutex_unlock(&mutex1); + pthread_mutex_unlock(&mutex2); +} + +void +check_unbless(void) +{ + int record_count = 0; + struct pthread_lor_np lor; + + pthread_lor_begin_np(&lor); + while (pthread_lor_next_np(&lor)) { + record_count++; + } + pthread_lor_end_np(&lor); + + check(record_count == 1); +} + +void +check_bless(void) +{ + int record_count = 0; + struct pthread_lor_np lor; + + pthread_lor_begin_np(&lor); + while (pthread_lor_next_np(&lor)) { + record_count++; + } + pthread_lor_end_np(&lor); + + check(record_count == 0); +} + +int +main(void) +{ + unbless_test(); + check_unbless(); + + bless_test(); + check_bless(); + + show_test_results(); + + return (0); +} Copied: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.t (from r239709, soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setorder.t) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/bless.t Mon Jul 23 20:21:37 2012 (r239713, copy of r239709, soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setorder.t) @@ -0,0 +1,10 @@ +#!/bin/sh +# $FreeBSD$ + +cd `dirname $0` + +executable=`basename $0 .t` + +make $executable 2>&1 > /dev/null + +exec ./$executable
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120723202137.D19F81065673>