[complement-svn] SF.net SVN: complement: [1460] trunk/complement/explore/test/mt
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-12-18 17:27:37
|
Revision: 1460 http://svn.sourceforge.net/complement/?rev=1460&view=rev Author: complement Date: 2006-12-18 09:27:35 -0800 (Mon, 18 Dec 2006) Log Message: ----------- check getpid and getppid 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 2006-12-18 13:04:02 UTC (rev 1459) +++ trunk/complement/explore/test/mt/mt_test.cc 2006-12-18 17:27:35 UTC (rev 1460) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/14 11:10:26 ptr> +// -*- C++ -*- Time-stamp: <06/12/18 20:00:15 ptr> /* * Copyright (c) 2006 @@ -75,3 +75,65 @@ shmdt( buf ); shmctl( id, IPC_RMID, &ds ); } + +void mt_test::pid() +{ + shmid_ds ds; + int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); + BOOST_REQUIRE( id != -1 ); + // if ( id == -1 ) { + // cerr << "Error on shmget" << endl; + // } + BOOST_REQUIRE( shmctl( id, IPC_STAT, &ds ) != -1 ); + // if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { + // cerr << "Error on shmctl" << endl; + // } + void *buf = shmat( id, 0, 0 ); + BOOST_REQUIRE( buf != reinterpret_cast<void *>(-1) ); + // if ( buf == reinterpret_cast<void *>(-1) ) { + // cerr << "Error on shmat" << endl; + // } + + xmt::__Condition<true>& fcnd = *new( buf ) xmt::__Condition<true>(); + fcnd.set( false ); + pid_t my_pid = xmt::getpid(); + + try { + xmt::fork(); + + try { + + // Child code + BOOST_CHECK( my_pid == xmt::getppid() ); + *reinterpret_cast<pid_t *>(static_cast<char *>(buf) + sizeof(xmt::__Condition<true>)) = xmt::getpid(); + + fcnd.set( true ); + + } + catch ( ... ) { + } + + exit( 0 ); + } + catch ( xmt::fork_in_parent& child ) { + try { + BOOST_CHECK( child.pid() > 0 ); + + fcnd.try_wait(); + + BOOST_CHECK( *reinterpret_cast<pid_t *>(static_cast<char *>(buf) + sizeof(xmt::__Condition<true>)) == child.pid() ); + + int stat; + BOOST_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + } + catch ( ... ) { + } + } + catch ( ... ) { + } + + (&fcnd)->~__Condition<true>(); + + shmdt( buf ); + shmctl( id, IPC_RMID, &ds ); +} Modified: trunk/complement/explore/test/mt/mt_test.h =================================================================== --- trunk/complement/explore/test/mt/mt_test.h 2006-12-18 13:04:02 UTC (rev 1459) +++ trunk/complement/explore/test/mt/mt_test.h 2006-12-18 17:27:35 UTC (rev 1460) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/14 10:45:35 ptr> +// -*- C++ -*- Time-stamp: <06/12/18 19:49:04 ptr> /* * Copyright (c) 2006 @@ -14,6 +14,7 @@ struct mt_test { void fork(); + void pid(); }; #endif // __MT_TEST_H Modified: trunk/complement/explore/test/mt/mt_test_suite.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test_suite.cc 2006-12-18 13:04:02 UTC (rev 1459) +++ trunk/complement/explore/test/mt/mt_test_suite.cc 2006-12-18 17:27:35 UTC (rev 1460) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/14 11:12:02 ptr> +// -*- C++ -*- Time-stamp: <06/12/18 19:58:56 ptr> /* * Copyright (c) 2006 @@ -19,8 +19,10 @@ boost::shared_ptr<mt_test> instance( new mt_test() ); test_case *fork_tc = BOOST_CLASS_TEST_CASE( &mt_test::fork, instance ); + test_case *pid_tc = BOOST_CLASS_TEST_CASE( &mt_test::pid, instance ); - // basic2_tc->depends_on( basic1_tc ); + pid_tc->depends_on( fork_tc ); add( fork_tc ); + add( pid_tc ); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |