[complement-svn] SF.net SVN: complement: [1459] trunk/complement/explore/test
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-12-18 13:04:04
|
Revision: 1459 http://svn.sourceforge.net/complement/?rev=1459&view=rev Author: complement Date: 2006-12-18 05:04:02 -0800 (Mon, 18 Dec 2006) Log Message: ----------- clean tests for signal catchers; add test for block/unblock signal Modified Paths: -------------- trunk/complement/explore/test/mt/Makefile.inc trunk/complement/explore/test/mt/signal-1.cc trunk/complement/explore/test/mt/unit_test.cc Added Paths: ----------- trunk/complement/explore/test/mt/signal-3.cc Removed Paths: ------------- trunk/complement/explore/test/libmt/signal-3/ trunk/complement/explore/test/libmt/signal-4/ Modified: trunk/complement/explore/test/mt/Makefile.inc =================================================================== --- trunk/complement/explore/test/mt/Makefile.inc 2006-12-15 12:26:46 UTC (rev 1458) +++ trunk/complement/explore/test/mt/Makefile.inc 2006-12-18 13:04:02 UTC (rev 1459) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <06/12/14 11:11:10 ptr> +# -*- makefile -*- Time-stamp: <06/12/16 00:37:10 ptr> PRGNAME = mt_ut SRC_CC = unit_test.cc timespec.cc mutex_test.cc spinlock_test.cc \ - recursive_mutex.cc join.cc signal-1.cc signal-2.cc flck.cc lfs.cc \ + recursive_mutex.cc join.cc signal-1.cc signal-2.cc signal-3.cc flck.cc lfs.cc \ mt_test.cc mt_test_suite.cc Modified: trunk/complement/explore/test/mt/signal-1.cc =================================================================== --- trunk/complement/explore/test/mt/signal-1.cc 2006-12-15 12:26:46 UTC (rev 1458) +++ trunk/complement/explore/test/mt/signal-1.cc 2006-12-18 13:04:02 UTC (rev 1459) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/15 10:40:53 ptr> +// -*- C++ -*- Time-stamp: <06/12/16 00:28:34 ptr> /* * Copyright (c) 2003, 2006 @@ -16,6 +16,15 @@ using namespace xmt; + +/* + * thread 2: v = 1; create thread 1 ----------------------------------- join; v == 4? + * \ / + * thread 1: set handler; v == 1? - kill ----------- exit + * \ + * handler (within thread 1): v == 1?; v = 4 + */ + static Thread::ret_code thread_one( void * ); static Thread::ret_code thread_two( void * ); @@ -24,6 +33,8 @@ static int v = 0; +static Condition cnd; + extern "C" { static void handler( int ); @@ -55,29 +66,10 @@ BOOST_CHECK( v == 1 ); -// pm.lock(); -// cerr << "thread_one: unblock signal SIGINT" << endl; -// cerr << "thread_one: set own handler for signal SIGINT" << endl; -// pm.unlock(); + cnd.try_wait(); - - // wait while set thread's pointer (from thread_two) - xmt::timespec t(1,0); - - while ( th_one == 0 ) { - xmt::sleep( t ); - } - -// pm.lock(); -// cerr << "thread_one: send SIGINT" << endl; -// pm.unlock(); th_one->kill( SIGINT ); // send signal SIGINT to self -// pm.lock(); -// cerr << "thread_one: after send SIGINT" << endl; -// pm.unlock(); - // v = 2; // not reached (exit before) - Thread::ret_code rt; rt.iword = 0; @@ -86,22 +78,16 @@ Thread::ret_code thread_two( void * ) { - // pm.lock(); - // cerr << "thread_two: create thread one" << endl; - // pm.unlock(); + cnd.set( false ); v = 1; Thread t( thread_one ); // start thread_one - th_one = &t; // store address to be called from thread_one + th_one = &t; // store address to be called from thread_one - // pm.lock(); - // cerr << "thread_two: wait termination of thread one" << endl; - // pm.unlock(); + cnd.set( true ); + t.join(); - // pm.lock(); - // cerr << "thread_two: EOL of thread one" << endl; - // pm.unlock(); BOOST_CHECK( v == 4 ); Added: trunk/complement/explore/test/mt/signal-3.cc =================================================================== --- trunk/complement/explore/test/mt/signal-3.cc (rev 0) +++ trunk/complement/explore/test/mt/signal-3.cc 2006-12-18 13:04:02 UTC (rev 1459) @@ -0,0 +1,114 @@ +// -*- C++ -*- Time-stamp: <06/12/16 00:35:45 ptr> + +/* + * Copyright (c) 2003, 2006 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#include <boost/test/unit_test.hpp> + +using namespace boost::unit_test_framework; + +#include <mt/xmt.h> + +using namespace xmt; + +/* + * This is the same as signal-1, but instead of unblock signal, I block one + * so I don't take this signal. + */ + +/* + * handler (within thread 2): v == 1?; v = 4 + * / + * thread 2: v = 1; create thread 1 ----------------------------------- join; v == 4? + * \ / / + * thread 1: set handler; v == 1? - kill ------ exit + * + */ + +static Thread::ret_code thread_one( void * ); +static Thread::ret_code thread_two( void * ); + +static Thread *th_one = 0; +static Thread *th_two = 0; + +static int v = 0; + +static Condition cnd; + +extern "C" { + static void handler( int ); + + void handler( int ) + { + BOOST_CHECK( v == 1 ); + v = 4; + /* + Note: you have very restricted list of system calls that you can use here + (in the handler of signal) safely. In particular, you can't call pthread_* + functions. Reason: async-signal-safe calls, Unix 98, POSIX 1002.1 + */ + // cerr << "thread_one: Handler" << endl; + // Thread::signal_exit( SIGTERM ); + // send signal to caller thread to exit: + // th_one->kill( SIGTERM ); + + // v = 3; // not reached + } +} + +Thread::ret_code thread_one( void * ) +{ + BOOST_CHECK( v == 1 ); + + cnd.try_wait(); + + th_two->kill( SIGINT ); // send signal SIGINT to self + + Thread::ret_code rt; + rt.iword = 0; + + return rt; +} + +Thread::ret_code thread_two( void * ) +{ + xmt::signal_handler( SIGINT, handler ); + xmt::block_signal( SIGINT ); // block signal + + v = 1; + + Thread t( thread_one ); // start thread_one + + t.join(); + + BOOST_CHECK( v == 1 ); // signal was blocked! + + xmt::unblock_signal( SIGINT ); // unblock signal + + BOOST_CHECK( v == 4 ); + + Thread::ret_code rt; + rt.iword = 0; + + return rt; +} + +void signal_3_test() +{ + cnd.set( false ); + + Thread t( thread_two ); + + th_two = &t; // store address to be called from thread_one + + cnd.set( true ); + + t.join(); + + BOOST_CHECK( v == 4 ); +} Modified: trunk/complement/explore/test/mt/unit_test.cc =================================================================== --- trunk/complement/explore/test/mt/unit_test.cc 2006-12-15 12:26:46 UTC (rev 1458) +++ trunk/complement/explore/test/mt/unit_test.cc 2006-12-18 13:04:02 UTC (rev 1459) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/14 10:47:39 ptr> +// -*- C++ -*- Time-stamp: <06/12/16 00:36:47 ptr> /* * Copyright (c) 2002, 2003, 2004, 2006 @@ -24,6 +24,7 @@ void recursive_mutex_test(); void signal_1_test(); void signal_2_test(); +void signal_3_test(); void flock_test(); void lfs_test(); @@ -48,6 +49,7 @@ // (stack saved/restored, that confuse stack unwind); // by this reason next test is commented: // ts->add( BOOST_TEST_CASE( &signal_2_test ) ); + ts->add( BOOST_TEST_CASE( &signal_3_test ) ); // flock requre revision, commented now. // ts->add( BOOST_TEST_CASE( &flock_test ) ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |