From 367fdf384762b04391502dcaa73171f8da417ef3 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Fri, 2 Jan 2009 09:27:04 +0100 Subject: [PATCH] multithreading and resource tracker tests --- tests/20multithreading_alpha.tests | 87 ++++++++++++++++++++++++++++++++++++++ tests/30resource.tests | 69 ++++++++++++++++++++++++++++++ tests/Makefile.am | 71 +++++-------------------------- tests/test_nobug_resources.c | 39 +++++++++-------- 4 files changed, 187 insertions(+), 79 deletions(-) create mode 100644 tests/20multithreading_alpha.tests create mode 100644 tests/30resource.tests diff --git a/tests/20multithreading_alpha.tests b/tests/20multithreading_alpha.tests new file mode 100644 index 0000000..9b17f63 --- /dev/null +++ b/tests/20multithreading_alpha.tests @@ -0,0 +1,87 @@ + +TESTING "example ALPHA build" ./example_mt_alpha + +TEST "example_alpha, multithreading/alpha" <b != 8\) +return: 134 +END + +TEST "Dumping, multithreading/alpha" 11 <recursive +err: RESOURCE_ENTER: .*: type1: test1@.*: user1@.*: recursive +err: RESOURCE_ENTER: .*: type1: test1@.*: user2@.*: exclusive +err: +err: type1:test1 thread_1:.* hold by 2 entities: +err: user1 thread_1:.* recursive 2 +err: user2 thread_1:.* exclusive 1 +err: +err: type2:test2 thread_1:.* hold by 0 entities: +err: +err: registered resources: +err: type1:test1 thread_1: +err: type2:test2 thread_1: +err: +err: RESOURCE_LEAVE: .*: type1: test1@.*: user1@.*: recursive +err: ECHO: .*: e1 left +err: +err: type1:test1 thread_1:.* hold by 2 entities: +err: user1 thread_1:.* recursive 1 +err: user2 thread_1:.* exclusive 1 +err: +err: type2:test2 thread_1:.* hold by 0 entities: +err: +err: registered resources: +err: type1:test1 thread_1: +err: type2:test2 thread_1: +err: +err: RESOURCE_LEAVE: .*: type1: test1@.*: @ +err: ECHO: .*: t1 left +err: +err: type1:test1 thread_1:.* hold by 1 entities: +err: user2 thread_1:.* exclusive 1 +err: +err: type2:test2 thread_1:.* hold by 0 entities: +err: +err: RESOURCE_LEAVE: .*: type1: test1@.*: user2@.*: exclusive +err: ECHO: .*: e2 left +err: +err: type1:test1 thread_1:.* hold by 0 entities: +err: +err: type2:test2 thread_1:.* hold by 0 entities: +err: +err: RESOURCE_FORGET: .*: type1: test1@ +err: +err: type2:test2 thread_1:.* hold by 0 entities: +err: +err: RESOURCE_FORGET: .*: type2: test2@ +err: registered resources: +err: +err: ECHO: .*: done +END + + + + + + + + + + diff --git a/tests/Makefile.am b/tests/Makefile.am index 2b47351..3a61eb2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -45,48 +45,17 @@ test_nobug_release_SOURCES = tests/test_nobug.c test_nobug_release_CPPFLAGS = -I$(top_srcdir)/src -DNOBUG_USE_PTHREAD=0 -DNDEBUG test_nobug_release_LDADD = libnobug.la -check_PROGRAMS += test_nobug_resources test_nobug_resources_alpha test_nobug_resources_beta -test_nobug_resources_SOURCES = tests/test_nobug_resources.c -test_nobug_resources_CPPFLAGS = -I$(top_srcdir)/src -DNOBUG_USE_PTHREAD=0 -DNDEBUG -test_nobug_resources_LDADD = libnobug.la -test_nobug_resources_alpha_SOURCES = tests/test_nobug_resources.c -test_nobug_resources_alpha_CPPFLAGS = -I$(top_srcdir)/src -DNOBUG_USE_PTHREAD=0 -DEBUG_ALPHA -test_nobug_resources_alpha_LDADD = libnobug.la -test_nobug_resources_beta_SOURCES = tests/test_nobug_resources.c -test_nobug_resources_beta_CPPFLAGS = -I$(top_srcdir)/src -DNOBUG_USE_PTHREAD=0 -DEBUG_BETA -test_nobug_resources_beta_LDADD = libnobug.la - -check_PROGRAMS += test_nobug_thread test_nobug_thread_alpha test_nobug_thread_beta -test_nobug_thread_SOURCES = tests/test_nobug_thread.c -test_nobug_thread_CPPFLAGS = -I$(top_srcdir)/src -DNOBUG_USE_PTHREAD=0 -DNDEBUG -test_nobug_thread_LDADD = libnobug.la -test_nobug_thread_alpha_SOURCES = tests/test_nobug_thread.c -test_nobug_thread_alpha_CPPFLAGS = -I$(top_srcdir)/src -DNOBUG_USE_PTHREAD=0 -DEBUG_ALPHA -test_nobug_thread_alpha_LDADD = libnobug.la -test_nobug_thread_beta_SOURCES = tests/test_nobug_thread.c -test_nobug_thread_beta_CPPFLAGS = -I$(top_srcdir)/src -DNOBUG_USE_PTHREAD=0 -DEBUG_BETA -test_nobug_thread_beta_LDADD = libnobug.la ##### multi-threading variant if HAVE_THREADING -check_PROGRAMS += example_mt example_mt_alpha example_mt_beta -example_mt_SOURCES = tests/example.c -example_mt_CPPFLAGS = -I$(top_srcdir)/src -DNDEBUG -example_mt_CFLAGS = @PTHREAD_CFLAGS@ -example_mt_LDFLAGS = @PTHREAD_CFLAGS@ -example_mt_LDADD = @PTHREAD_LIBS@ libnobugmt.la +check_PROGRAMS += example_mt_alpha example_mt_alpha_SOURCES = tests/example.c example_mt_alpha_CPPFLAGS = -I$(top_srcdir)/src -DEBUG_ALPHA example_mt_alpha_CFLAGS = @PTHREAD_CFLAGS@ -example_mt_alpha_LDFLAGS = @PTHREAD_CFLAGS@ +example_mt_alpha_LDFLAGS = @PTHREAD_CFLAGS@ example_mt_alpha_LDADD = @PTHREAD_LIBS@ libnobugmt.la -example_mt_beta_SOURCES = tests/example.c -example_mt_beta_CPPFLAGS = -I$(top_srcdir)/src -DEBUG_BETA -example_mt_beta_CFLAGS = @PTHREAD_CFLAGS@ -example_mt_beta_LDFLAGS = @PTHREAD_CFLAGS@ -example_mt_beta_LDADD = @PTHREAD_LIBS@ libnobugmt.la check_PROGRAMS += test_nobug_mt_alpha test_nobug_mt_alpha_SOURCES = tests/test_nobug.c @@ -95,39 +64,19 @@ test_nobug_mt_alpha_CFLAGS = @PTHREAD_CFLAGS@ test_nobug_mt_alpha_LDFLAGS = @PTHREAD_CFLAGS@ test_nobug_mt_alpha_LDADD = @PTHREAD_LIBS@ libnobugmt.la -check_PROGRAMS += test_nobug_deadlock_mt test_nobug_deadlock_mt_alpha test_nobug_deadlock_mt_beta -test_nobug_deadlock_mt_SOURCES = tests/test_nobug_deadlock.c -test_nobug_deadlock_mt_CPPFLAGS = -I$(top_srcdir)/src -DNDEBUG -test_nobug_deadlock_mt_CFLAGS = @PTHREAD_CFLAGS@ -test_nobug_deadlock_mt_LDFLAGS = @PTHREAD_CFLAGS@ -test_nobug_deadlock_mt_LDADD = @PTHREAD_LIBS@ libnobugmt.la -test_nobug_deadlock_mt_alpha_SOURCES = tests/test_nobug_deadlock.c -test_nobug_deadlock_mt_alpha_CPPFLAGS = -I$(top_srcdir)/src -DEBUG_ALPHA -test_nobug_deadlock_mt_alpha_CFLAGS = @PTHREAD_CFLAGS@ -test_nobug_deadlock_mt_alpha_LDFLAGS = @PTHREAD_CFLAGS@ -test_nobug_deadlock_mt_alpha_LDADD = @PTHREAD_LIBS@ libnobugmt.la -test_nobug_deadlock_mt_beta_SOURCES = tests/test_nobug_deadlock.c -test_nobug_deadlock_mt_beta_CPPFLAGS = -I$(top_srcdir)/src -DEBUG_BETA -test_nobug_deadlock_mt_beta_CFLAGS = @PTHREAD_CFLAGS@ -test_nobug_deadlock_mt_beta_LDFLAGS = @PTHREAD_CFLAGS@ -test_nobug_deadlock_mt_beta_LDADD = @PTHREAD_LIBS@ libnobugmt.la - -check_PROGRAMS += test_nobug_resources_mt test_nobug_resources_mt_alpha test_nobug_resources_mt_beta -test_nobug_resources_mt_SOURCES = tests/test_nobug_resources.c -test_nobug_resources_mt_CPPFLAGS = -I$(top_srcdir)/src -DNDEBUG -test_nobug_resources_mt_CFLAGS = @PTHREAD_CFLAGS@ -test_nobug_resources_mt_LDFLAGS = @PTHREAD_CFLAGS@ -test_nobug_resources_mt_LDADD = @PTHREAD_LIBS@ libnobugmt.la +check_PROGRAMS += test_nobug_resources_mt_alpha test_nobug_resources_mt_alpha_SOURCES = tests/test_nobug_resources.c test_nobug_resources_mt_alpha_CPPFLAGS = -I$(top_srcdir)/src -DEBUG_ALPHA test_nobug_resources_mt_alpha_CFLAGS = @PTHREAD_CFLAGS@ test_nobug_resources_mt_alpha_LDFLAGS = @PTHREAD_CFLAGS@ test_nobug_resources_mt_alpha_LDADD = @PTHREAD_LIBS@ libnobugmt.la -test_nobug_resources_mt_beta_SOURCES = tests/test_nobug_resources.c -test_nobug_resources_mt_beta_CPPFLAGS = -I$(top_srcdir)/src -DEBUG_BETA -test_nobug_resources_mt_beta_CFLAGS = @PTHREAD_CFLAGS@ -test_nobug_resources_mt_beta_LDFLAGS = @PTHREAD_CFLAGS@ -test_nobug_resources_mt_beta_LDADD = @PTHREAD_LIBS@ libnobugmt.la + +check_PROGRAMS += test_nobug_deadlock_mt_alpha +test_nobug_deadlock_mt_alpha_SOURCES = tests/test_nobug_deadlock.c +test_nobug_deadlock_mt_alpha_CPPFLAGS = -I$(top_srcdir)/src -DEBUG_ALPHA +test_nobug_deadlock_mt_alpha_CFLAGS = @PTHREAD_CFLAGS@ +test_nobug_deadlock_mt_alpha_LDFLAGS = @PTHREAD_CFLAGS@ +test_nobug_deadlock_mt_alpha_LDADD = @PTHREAD_LIBS@ libnobugmt.la check_PROGRAMS += test_nobug_thread_mt test_nobug_thread_mt_alpha test_nobug_thread_mt_beta test_nobug_thread_mt_SOURCES = tests/test_nobug_thread.c diff --git a/tests/test_nobug_resources.c b/tests/test_nobug_resources.c index 82571b6..157c567 100644 --- a/tests/test_nobug_resources.c +++ b/tests/test_nobug_resources.c @@ -1,58 +1,61 @@ +#include "test.h" #include "nobug.h" -NOBUG_DEFINE_FLAG_LIMIT(test, LOG_DEBUG); +TESTS_BEGIN - -int main() +TEST(resources) { - nobug_init(); RESOURCE_HANDLE(t1); NOBUG_RESOURCE_HANDLE_INIT (t1); RESOURCE_HANDLE(t2); NOBUG_RESOURCE_HANDLE_INIT (t2); - RESOURCE_ANNOUNCE(test, "type1", "test1", main, t1); - RESOURCE_ANNOUNCE(test, "type2", "test2", main+1, t2); + RESOURCE_ANNOUNCE(NOBUG_ON, "type1", "test1", main, t1); + RESOURCE_ANNOUNCE(NOBUG_ON, "type2", "test2", main+1, t2); RESOURCE_HANDLE(e1); NOBUG_RESOURCE_HANDLE_INIT (e1); RESOURCE_HANDLE(e2); NOBUG_RESOURCE_HANDLE_INIT (e2); - WARN(NOBUG_ON, "foo"); + ECHO ("Handles initialized"); - RESOURCE_ENTER(test, t1, "user1", main, NOBUG_RESOURCE_WAITING, e1); - RESOURCE_STATE(test, e1, NOBUG_RESOURCE_RECURSIVE); - RESOURCE_ENTER(test, t1, "user1", main, NOBUG_RESOURCE_RECURSIVE, e1); + RESOURCE_ENTER(NOBUG_ON, t1, "user1", main, NOBUG_RESOURCE_WAITING, e1); + RESOURCE_STATE(NOBUG_ON, e1, NOBUG_RESOURCE_RECURSIVE); + RESOURCE_ENTER(NOBUG_ON, t1, "user1", main, NOBUG_RESOURCE_RECURSIVE, e1); - RESOURCE_ENTER(test, t1, "user2", main+1, NOBUG_RESOURCE_EXCLUSIVE, e2); + RESOURCE_ENTER(NOBUG_ON, t1, "user2", main+1, NOBUG_RESOURCE_EXCLUSIVE, e2); nobug_resource_dump_all (stderr); - nobug_resource_dump_resources (stderr); - RESOURCE_LEAVE(test, e1); + RESOURCE_LEAVE(NOBUG_ON, e1); + ECHO ("e1 left"); nobug_resource_dump_all (stderr); nobug_resource_dump_resources (stderr); - NOBUG_RESOURCE_LEAVE_LOOKUP(test, t1, main); + NOBUG_RESOURCE_LEAVE_LOOKUP(NOBUG_ON, t1, main); + ECHO ("t1 left"); nobug_resource_dump_all (stderr); - RESOURCE_LEAVE(test, e2); + RESOURCE_LEAVE(NOBUG_ON, e2); + ECHO ("e2 left"); nobug_resource_dump_all (stderr); - RESOURCE_FORGET(test, t1); + RESOURCE_FORGET(NOBUG_ON, t1); nobug_resource_dump_all (stderr); - RESOURCE_FORGET(test, t2); + RESOURCE_FORGET(NOBUG_ON, t2); nobug_resource_dump_resources (stderr); - return 0; + ECHO ("done"); } + +TESTS_END -- 2.11.4.GIT