Date: Sun, 15 Jul 2012 22:05:22 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r239441 - in soc2012/gmiller/locking-head: . tools/regression/lib/libthr/lockprof Message-ID: <20120715220522.DC0EC1065672@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gmiller Date: Sun Jul 15 22:05:22 2012 New Revision: 239441 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239441 Log: r239382@FreeBSD-dev: root | 2012-07-13 16:32:20 -0500 Factor out the functions for recording and displaying test results to eliminate code duplication. Added: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.c soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.h 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 soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.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 21:46:19 2012 (r239440) +++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/Makefile Sun Jul 15 22:05:22 2012 (r239441) @@ -11,8 +11,8 @@ clean: -rm -f ${TESTS} -lock-cycle: lock-cycle.c - ${CC} -o lock-cycle lock-cycle.c ${CFLAGS} +lock-cycle: lock-cycle.c check.c + ${CC} -o lock-cycle lock-cycle.c check.c ${CFLAGS} -recurse: recurse.c - ${CC} -o recurse recurse.c ${CFLAGS} +recurse: recurse.c check.c + ${CC} -o recurse recurse.c check.c ${CFLAGS} Added: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.c Sun Jul 15 22:05:22 2012 (r239441) @@ -0,0 +1,36 @@ + +#include <stdio.h> + +#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); + } + } +} Added: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/check.h Sun Jul 15 22:05:22 2012 (r239441) @@ -0,0 +1,3 @@ + +void check(char cond); +void show_test_results(void); 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 21:46:19 2012 (r239440) +++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c Sun Jul 15 22:05:22 2012 (r239441) @@ -1,10 +1,11 @@ #include <pthread.h> #include <pthread_np.h> -#include <stdio.h> #include <string.h> #include <unistd.h> +#include "check.h" + pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; void @@ -81,40 +82,6 @@ pthread_join(thread1, 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) { @@ -131,7 +98,7 @@ check(record_count == 1); check(strcmp(stats.file, "lock-cycle.c") == 0); - check(stats.line == 16); + check(stats.line == 17); check(stats.wait_max.tv_sec == 0 && stats.wait_max.tv_nsec == 0); @@ -165,7 +132,7 @@ check(record_count == 1); check(strcmp(stats.file, "lock-cycle.c") == 0); - check(stats.line == 16); + check(stats.line == 17); tm = stats.hold_max.tv_sec * 1000000L + stats.hold_max.tv_nsec / 1000; check(tm >= 30); Modified: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.c ============================================================================== --- soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.c Sun Jul 15 21:46:19 2012 (r239440) +++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/recurse.c Sun Jul 15 22:05:22 2012 (r239441) @@ -1,10 +1,11 @@ #include <pthread.h> #include <pthread_np.h> -#include <stdio.h> #include <string.h> #include <unistd.h> +#include "check.h" + void recursion_test(void) { @@ -25,40 +26,6 @@ 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) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120715220522.DC0EC1065672>