socsvn commit: r238936 - in soc2012/gmiller/locking-head: .
tools/regression/lib/libthr tools/regression/lib/libthr/lockprof
tools/regression/lib/libwitness
gmiller at FreeBSD.org
gmiller at FreeBSD.org
Tue Jul 3 22:45:12 UTC 2012
Author: gmiller
Date: Tue Jul 3 22:45:09 2012
New Revision: 238936
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238936
Log:
r238827 at FreeBSD-dev: root | 2012-07-03 05:12:44 -0500
Add the first round of lock profiling tests.
Added:
soc2012/gmiller/locking-head/tools/regression/lib/libthr/
soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/
soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/Makefile
soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c
soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.t
soc2012/gmiller/locking-head/tools/regression/lib/libwitness/
soc2012/gmiller/locking-head/tools/regression/lib/libwitness/witness.t
Modified:
soc2012/gmiller/locking-head/ (props changed)
Added: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/Makefile
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/Makefile Tue Jul 3 22:45:09 2012 (r238936)
@@ -0,0 +1,15 @@
+# $FreeBSD$
+
+TESTS= lock-cycle
+CFLAGS+= -DLOCK_PROFILING -g -Wall -Wextra -Werror -lthr_profile
+
+.PHONY: tests
+tests: ${TESTS}
+ for p in ${TESTS}; do ${.OBJDIR}/$$p; done
+
+.PHONY: clean
+clean:
+ -rm -f ${TESTS}
+
+lock-cycle: lock-cycle.c
+ ${CC} -o lock-cycle lock-cycle.c ${CFLAGS}
\ No newline at end of file
Added: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c Tue Jul 3 22:45:09 2012 (r238936)
@@ -0,0 +1,138 @@
+
+#include <pthread.h>
+#include <pthread_np.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+void
+lock_cycle(void)
+{
+ int i;
+
+ for (i = 0; i < 1000; i++) {
+ pthread_mutex_lock(&mutex);
+
+ usleep(10);
+
+ pthread_mutex_unlock(&mutex);
+ }
+}
+
+void *
+thread_func(void *v)
+{
+ v = v;
+
+ lock_cycle();
+
+ return NULL;
+}
+
+void
+multi_cycle()
+{
+ pthread_t thread1;
+ pthread_t thread2;
+
+ pthread_create(&thread1, NULL, thread_func, NULL);
+ pthread_create(&thread2, NULL, thread_func, NULL);
+
+ lock_cycle();
+
+ pthread_join(thread1, NULL);
+ pthread_join(thread2, NULL);
+}
+
+#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_single(void)
+{
+ int record_count = 0;
+ struct pthread_statistics_np stats;
+ long tm;
+
+ pthread_getstatistics_begin_np(&stats);
+ while (pthread_getstatistics_next_np(&stats)) {
+ record_count++;
+ }
+ pthread_getstatistics_end_np(&stats);
+
+ check(record_count == 1);
+
+ pthread_getstatistics_begin_np(&stats);
+ pthread_getstatistics_next_np(&stats);
+ pthread_getstatistics_end_np(&stats);
+
+ check(strcmp(stats.file, "lock-cycle.c") == 0);
+ check(stats.line == 16);
+
+ check(stats.wait_max.tv_sec == 0 && stats.wait_max.tv_nsec == 0);
+
+ tm = stats.hold_max.tv_sec * 1000000L + stats.hold_max.tv_nsec / 1000;
+ check(tm >= 10);
+
+ check(stats.contest_count == 0);
+
+ check(stats.wait_time.tv_sec == 0 && stats.wait_time.tv_nsec == 0);
+
+ tm = stats.hold_time.tv_sec * 1000000L +
+ stats.hold_time.tv_nsec / 1000;
+ check(tm >= 10000);
+
+ check(stats.acq_count == 1000);
+}
+
+void
+check_stats_multi(void)
+{
+}
+
+int
+main(void)
+{
+ lock_cycle();
+ check_stats_single();
+
+ multi_cycle();
+ check_stats_multi();
+
+ show_test_results();
+
+ return 0;
+}
Added: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.t
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.t Tue Jul 3 22:45:09 2012 (r238936)
@@ -0,0 +1,10 @@
+#!/bin/sh
+# $FreeBSD$
+
+cd `dirname $0`
+
+executable=`basename $0 .t`
+
+make $executable 2>&1 > /dev/null
+
+exec ./$executable
Added: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/witness.t
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/witness.t Tue Jul 3 22:45:09 2012 (r238936)
@@ -0,0 +1,5 @@
+#!/bin/sh
+# $FreeBSD$
+
+echo 1..1
+echo ok 1
More information about the svn-soc-all
mailing list