From owner-svn-soc-all@FreeBSD.ORG Sun Jul 15 22:05:24 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id DC0EC1065672 for ; Sun, 15 Jul 2012 22:05:22 +0000 (UTC) (envelope-from gmiller@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Sun, 15 Jul 2012 22:05:22 +0000 Date: Sun, 15 Jul 2012 22:05:22 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120715220522.DC0EC1065672@hub.freebsd.org> Cc: Subject: socsvn commit: r239441 - in soc2012/gmiller/locking-head: . tools/regression/lib/libthr/lockprof X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Jul 2012 22:05:25 -0000 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 + +#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 #include -#include #include #include +#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 #include -#include #include #include +#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) {