Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jul 2012 21:28:23 +0000
From:      gmiller@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r239437 - in soc2012/gmiller/locking-head: . tools/regression/lib/libthr/lockprof
Message-ID:  <20120715212823.1FD31106564A@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gmiller
Date: Sun Jul 15 21:28:22 2012
New Revision: 239437
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239437

Log:
   r239381@FreeBSD-dev:  root | 2012-07-13 16:00:37 -0500
   Add a regression test for the previously-fixed recursive mutex bug.

Added:
  soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.c
  soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.t
Modified:
  soc2012/gmiller/locking-head/   (props changed)
  soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/Makefile
  soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c

Modified: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/Makefile
==============================================================================
--- soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/Makefile	Sun Jul 15 20:51:41 2012	(r239436)
+++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/Makefile	Sun Jul 15 21:28:22 2012	(r239437)
@@ -1,6 +1,6 @@
 # $FreeBSD$
 
-TESTS=	lock-cycle
+TESTS=	lock-cycle recurse
 CFLAGS+= -DLOCK_PROFILING -g -Wall -Wextra -Werror -lthr_profile
 
 .PHONY: tests
@@ -12,4 +12,7 @@
 	-rm -f ${TESTS}
 
 lock-cycle: lock-cycle.c
-	${CC} -o lock-cycle lock-cycle.c ${CFLAGS}
\ No newline at end of file
+	${CC} -o lock-cycle lock-cycle.c ${CFLAGS}
+
+recurse: recurse.c
+	${CC} -o recurse recurse.c ${CFLAGS}

Modified: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c
==============================================================================
--- soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c	Sun Jul 15 20:51:41 2012	(r239436)
+++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c	Sun Jul 15 21:28:22 2012	(r239437)
@@ -130,10 +130,6 @@
 
 	check(record_count == 1);
 
-	pthread_statistics_begin_np(&stats);
-	pthread_statistics_next_np(&stats);
-	pthread_statistics_end_np(&stats);
-
 	check(strcmp(stats.file, "lock-cycle.c") == 0);
 	check(stats.line == 16);
 
@@ -168,10 +164,6 @@
 
 	check(record_count == 1);
 
-	pthread_statistics_begin_np(&stats);
-	pthread_statistics_next_np(&stats);
-	pthread_statistics_end_np(&stats);
-
 	check(strcmp(stats.file, "lock-cycle.c") == 0);
 	check(stats.line == 16);
 
@@ -182,8 +174,6 @@
 	    stats.hold_time.tv_nsec / 1000;
 	check(tm >= 30000);
 
-	printf("count = %d\n", stats.acq_count);
-
 	check(stats.acq_count == 3000);
 }
 
@@ -217,10 +207,6 @@
 
 	check(record_count == 1);
 
-	pthread_statistics_begin_np(&stats);
-	pthread_statistics_next_np(&stats);
-	pthread_statistics_end_np(&stats);
-
 	check(stats.contest_count == 1);
 
 	tm = stats.wait_time.tv_sec * 1000000L +

Added: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.c	Sun Jul 15 21:28:22 2012	(r239437)
@@ -0,0 +1,104 @@
+
+#include <pthread.h>
+#include <pthread_np.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+void
+recursion_test(void)
+{
+	pthread_mutex_t mutex;
+	pthread_mutexattr_t attr;
+
+	pthread_mutexattr_init(&attr);
+	pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+	pthread_mutex_init(&mutex, &attr);
+
+	pthread_mutex_lock(&mutex);
+	pthread_mutex_lock(&mutex);
+
+	pthread_mutex_unlock(&mutex);
+
+	sleep(1);
+
+	pthread_mutex_unlock(&mutex);
+}
+
+#define	MAX_TESTS	(100)
+
+int success_count = 0;
+int fail_count = 0;
+char result[MAX_TESTS];
+
+void
+check(char cond)
+{
+	result[success_count + fail_count] = cond;
+
+	if (cond) {
+		success_count++;
+	} else {
+		fail_count++;
+	}
+}
+
+void
+show_test_results(void)
+{
+	int		i;
+
+	printf("1..%d\n", success_count + fail_count);
+
+	for (i = 1; i <= success_count + fail_count; i++) {
+		if (result[i - 1]) {
+			printf("ok %d\n", i);
+		} else {
+			printf("not ok %d\n", i);
+		}
+	}
+}
+
+void
+check_stats_recursion(void)
+{
+	int		record_count = 0;
+	struct pthread_statistics_np stats;
+	long		tm;
+
+	pthread_statistics_begin_np(&stats);
+	while (pthread_statistics_next_np(&stats)) {
+		record_count++;
+	}
+	pthread_statistics_end_np(&stats);
+
+	check(record_count == 1);
+
+	check(strcmp(stats.file, "recurse.c") == 0);
+
+	check(stats.wait_max.tv_sec == 0 && stats.wait_max.tv_nsec == 0);
+
+	check(stats.contest_count == 0);
+
+	check(stats.wait_time.tv_sec == 0 && stats.wait_time.tv_nsec == 0);
+
+	check(stats.acq_count == 1);
+
+	tm = stats.hold_max.tv_sec * 1000000L + stats.hold_max.tv_nsec / 1000;
+	check(tm >= 1000000);
+
+	tm = stats.hold_time.tv_sec * 1000000L +
+	    stats.hold_time.tv_nsec / 1000;
+	check(tm >= 1000000);
+}
+
+int
+main(void)
+{
+	recursion_test();
+	check_stats_recursion();
+
+	show_test_results();
+
+	return 0;
+}

Added: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.t
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.t	Sun Jul 15 21:28:22 2012	(r239437)
@@ -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?20120715212823.1FD31106564A>