[complement-svn] SF.net SVN: complement: [1619] trunk/complement/explore/test/mt
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-07-17 12:05:18
|
Revision: 1619 http://svn.sourceforge.net/complement/?rev=1619&view=rev Author: complement Date: 2007-07-17 05:05:15 -0700 (Tue, 17 Jul 2007) Log Message: ----------- fix tests dependecies, add missed returns, refine tests structure Modified Paths: -------------- trunk/complement/explore/test/mt/mt_test.cc trunk/complement/explore/test/mt/mt_test.h trunk/complement/explore/test/mt/mt_test_suite.cc Modified: trunk/complement/explore/test/mt/mt_test.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test.cc 2007-07-17 06:33:12 UTC (rev 1618) +++ trunk/complement/explore/test/mt/mt_test.cc 2007-07-17 12:05:15 UTC (rev 1619) @@ -39,7 +39,7 @@ } /* ****************************************************** - * Start thread, join it. + * Start thread, join it. Check return value. */ static int x = 0; @@ -49,7 +49,7 @@ x = 1; xmt::Thread::ret_code rt; - rt.iword = 0; + rt.iword = 2; return rt; } @@ -60,7 +60,7 @@ xmt::Thread t( thread_entry_call ); - t.join(); + EXAM_CHECK( t.join().iword == 2 ); EXAM_CHECK( x == 1 ); @@ -74,7 +74,7 @@ xmt::Thread::ret_code thread2_entry_call( void *p ) { xmt::Thread::ret_code rt; - rt.iword = 0; + rt.iword = 1; xmt::barrier& b = *reinterpret_cast<xmt::barrier *>(p); b.wait(); @@ -89,8 +89,9 @@ xmt::Thread t1( thread2_entry_call, &b ); xmt::Thread t2( thread2_entry_call, &b ); - t2.join(); - t1.join(); + EXAM_CHECK( (t2.join().iword + t1.join().iword) == 2 ); + + return EXAM_RESULT; } /* ****************************************************** @@ -112,11 +113,15 @@ int EXAM_IMPL(mt_test::yield) { - xmt::barrier b; + { + xmt::barrier b; - xmt::Thread t1( thread2_entry_call, &b ); - xmt::Thread t2( thread3_entry_call, &b ); - // .join()'s are in Thread's destructors + xmt::Thread t1( thread2_entry_call, &b ); + xmt::Thread t2( thread3_entry_call, &b ); + // .join()'s are in Thread's destructors + } + + return EXAM_RESULT; } /* ****************************************************** @@ -455,7 +460,7 @@ try { // Child code - EXAM_CHECK( my_pid == xmt::getppid() ); + EXAM_CHECK_ASYNC( my_pid == xmt::getppid() ); *reinterpret_cast<pid_t *>(static_cast<char *>(buf) + sizeof(xmt::__condition<true>)) = xmt::getpid(); fcnd.set( true ); @@ -493,7 +498,7 @@ /* ****************************************************** */ -int EXAM_IMPL(mt_test::shm_segment) +int EXAM_IMPL(shm_test::shm_segment) { const char fname[] = "/tmp/mt_test.shm"; try { @@ -565,7 +570,7 @@ /* ****************************************************** */ -int EXAM_IMPL(mt_test::shm_alloc) +int EXAM_IMPL(shm_test::shm_alloc) { const char fname[] = "/tmp/mt_test.shm"; try { @@ -645,7 +650,7 @@ * This test is similar mt_test::fork() above, but instead plain shm_* * functions it use allocator based on shared memory segment */ -int EXAM_IMPL(mt_test::fork_shm) +int EXAM_IMPL(shm_test::fork_shm) { const char fname[] = "/tmp/mt_test.shm"; try { @@ -693,12 +698,14 @@ catch ( xmt::shm_bad_alloc& err ) { EXAM_ERROR( err.what() ); } + + return EXAM_RESULT; } /* ****************************************************** * Test: how to take named object in shared memory segment */ -int EXAM_IMPL(mt_test::shm_named_obj) +int EXAM_IMPL(shm_test::shm_named_obj) { const char fname[] = "/tmp/mt_test.shm"; enum { @@ -737,13 +744,13 @@ fcnd_ch.set( true ); } catch ( const xmt::shm_bad_alloc& err ) { - EXAM_ERROR( err.what() ); + EXAM_ERROR_ASYNC( err.what() ); } catch ( const std::invalid_argument& err ) { - EXAM_ERROR( err.what() ); + EXAM_ERROR_ASYNC( err.what() ); } catch ( ... ) { - EXAM_ERROR( "Fail in child" ); + EXAM_ERROR_ASYNC( "Fail in child" ); } exit( 0 ); @@ -779,29 +786,30 @@ /* ****************************************************** */ -static const char fname1[] = "/tmp/mt_test.shm.1"; -xmt::shm_alloc<1> seg1; +const char shm_test::fname1[] = "/tmp/mt_test.shm.1"; -int EXAM_IMPL(mt_test::shm_init) +shm_test::shm_test() { - seg1.allocate( fname1, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); - return EXAM_RESULT; + try { + seg1.allocate( fname1, 4*4096, xmt::shm_base::create | xmt::shm_base::exclusive, 0660 ); + } + catch ( xmt::shm_bad_alloc& err ) { + EXAM_ERROR_ASYNC( err.what() ); + } } /* ****************************************************** */ -int EXAM_IMPL(mt_test::shm_finit) +shm_test::~shm_test() { seg1.deallocate(); fs::remove( fname1 ); - - return EXAM_RESULT; } /* ****************************************************** */ -int EXAM_IMPL(mt_test::shm_named_obj_more) +int EXAM_IMPL(shm_test::shm_named_obj_more) { enum { ObjName = 1 @@ -827,7 +835,7 @@ nm_ch.release<xmt::__condition<true> >( ObjName ); } catch ( const std::invalid_argument& err ) { - EXAM_ERROR( err.what() ); + EXAM_ERROR_ASYNC( err.what() ); } exit( 0 ); } @@ -853,7 +861,7 @@ nm_ch.release<xmt::__condition<true> >( ObjName ); } catch ( const std::invalid_argument& err ) { - EXAM_ERROR( err.what() ); + EXAM_ERROR_ASYNC( err.what() ); } exit( 0 ); @@ -881,7 +889,7 @@ nm_ch.release<xmt::__barrier<true> >( ObjName ); } catch ( const std::invalid_argument& err ) { - EXAM_ERROR( err.what() ); + EXAM_ERROR_ASYNC( err.what() ); } exit( 0 ); Modified: trunk/complement/explore/test/mt/mt_test.h =================================================================== --- trunk/complement/explore/test/mt/mt_test.h 2007-07-17 06:33:12 UTC (rev 1618) +++ trunk/complement/explore/test/mt/mt_test.h 2007-07-17 12:05:15 UTC (rev 1619) @@ -14,6 +14,7 @@ #define FIT_EXAM #include <exam/suite.h> +#include <mt/shm.h> class mt_test { @@ -28,20 +29,29 @@ int EXAM_DECL(fork); int EXAM_DECL(pid); + int EXAM_DECL(thr_mgr); + + private: + // static xmt::Thread::ret_code thread_entry_call( void * ); + // static int x; +}; + +class shm_test +{ + public: + shm_test(); + ~shm_test(); + int EXAM_DECL(shm_segment); int EXAM_DECL(shm_alloc); int EXAM_DECL(fork_shm); int EXAM_DECL(shm_named_obj); - int EXAM_DECL(thr_mgr); - int EXAM_DECL(shm_init); - int EXAM_DECL(shm_finit); - int EXAM_DECL(shm_named_obj_more); private: - // static xmt::Thread::ret_code thread_entry_call( void * ); - // static int x; + xmt::shm_alloc<1> seg1; + static const char fname1[]; }; #endif // __MT_TEST_H Modified: trunk/complement/explore/test/mt/mt_test_suite.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test_suite.cc 2007-07-17 06:33:12 UTC (rev 1618) +++ trunk/complement/explore/test/mt/mt_test_suite.cc 2007-07-17 12:05:15 UTC (rev 1619) @@ -35,32 +35,33 @@ // t.add( signal_2_test, "signal_2_test" ); t.add( signal_3_test, "signal_3_test" ); - exam::test_suite::test_case_type tc[5]; + exam::test_suite::test_case_type tc[3]; tc[0] = t.add( &mt_test::barrier, test, "mt_test::barrier" ); tc[1] = t.add( &mt_test::join_test, test, "mt_test::join_test" ); tc[2] = t.add( &mt_test::yield, test, "mt_test::yield", t.add( &mt_test::barrier2, test, "mt_test::barrier2", - tc, tc+2 ) ); - tc[3] = t.add( &mt_test::mutex_test, test, "mt_test::mutex_test", tc[2] ); + tc, tc + 2 ) ); + t.add( &mt_test::recursive_mutex_test, test, "mt_test::recursive_mutex_test", + t.add( &mt_test::mutex_test, test, "mt_test::mutex_test", tc[2] ) ); #ifdef __FIT_PTHREAD_SPINLOCK t.add( &mt_test::spinlock_test, test, "mt_test::spinlock_test", tc[2] ); #endif - t.add( &mt_test::recursive_mutex_test, test, "mt_test::recursive_mutex_test", tc[3] ); t.add( &mt_test::pid, test, "mt_test::pid", t.add( &mt_test::fork, test, "mt_test::fork" ) ); - tc[4] = t.add( &mt_test::shm_alloc, test, "mt_test::shm_alloc", - t.add( &mt_test::shm_segment, test, "mt_test::shm_segment" ) ); - t.add( &mt_test::shm_named_obj, test, "mt_test::shm_named_obj", - t.add( &mt_test::fork_shm, test, "mt_test::fork_shm", tc[4] ) ); - t.add( &mt_test::shm_named_obj_more, test, "mt_test::shm_named_obj_more" ); - t.add( &mt_test::thr_mgr, test, "mt_test::thr_mgr" ); + t.add( &mt_test::thr_mgr, test, "mt_test::thr_mgr", tc[1] ); - t.add( &mt_test::shm_finit, test, "mt_test::shm_finit", - t.add( &mt_test::shm_init, test, "mt_test::shm_init", tc[4] ) ); + shm_test shmtest; + t.add( &shm_test::shm_named_obj_more, shmtest, "mt_test::shm_named_obj_more", + t.add( &shm_test::shm_named_obj, shmtest, "mt_test::shm_named_obj", + t.add( &shm_test::fork_shm, shmtest, "mt_test::fork_shm", + t.add( &shm_test::shm_alloc, shmtest, "mt_test::shm_alloc", + t.add( &shm_test::shm_segment, shmtest, "mt_test::shm_segment" ) ) ) ) + ); + // add( barrier_tc, 0, 2 ); // add( join_tc ); // add( barrier2_tc, 0, 3 ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |