[complement-svn] SF.net SVN: complement: [1453] trunk/complement/explore/test/mt
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-12-14 08:26:46
|
Revision: 1453 http://svn.sourceforge.net/complement/?rev=1453&view=rev Author: complement Date: 2006-12-14 00:26:44 -0800 (Thu, 14 Dec 2006) Log Message: ----------- established better test order; test for fork added Modified Paths: -------------- trunk/complement/explore/test/mt/Makefile.inc trunk/complement/explore/test/mt/unit_test.cc Added 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 trunk/complement/explore/test/mt/mt_test_suite.h Modified: trunk/complement/explore/test/mt/Makefile.inc =================================================================== --- trunk/complement/explore/test/mt/Makefile.inc 2006-12-14 07:27:44 UTC (rev 1452) +++ trunk/complement/explore/test/mt/Makefile.inc 2006-12-14 08:26:44 UTC (rev 1453) @@ -1,6 +1,6 @@ -# -*- makefile -*- Time-stamp: <04/05/06 18:40:56 ptr> -# $Id$ +# -*- makefile -*- Time-stamp: <06/12/14 11:11: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 flck.cc lfs.cc \ + mt_test.cc mt_test_suite.cc Added: trunk/complement/explore/test/mt/mt_test.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test.cc (rev 0) +++ trunk/complement/explore/test/mt/mt_test.cc 2006-12-14 08:26:44 UTC (rev 1453) @@ -0,0 +1,77 @@ +// -*- C++ -*- Time-stamp: <06/12/14 11:10:26 ptr> + +/* + * Copyright (c) 2006 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#include <boost/test/unit_test.hpp> + +#include "mt_test.h" + +#include <mt/xmt.h> + +#include <sys/shm.h> +#include <sys/wait.h> + +#include <signal.h> + +using namespace boost::unit_test_framework; + +void mt_test::fork() +{ + 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 ); + + try { + xmt::Thread::fork(); + + try { + + // Child code + + } + catch ( ... ) { + } + + exit( 0 ); + } + catch ( xmt::fork_in_parent& child ) { + try { + BOOST_CHECK( child.pid() > 0 ); + + fcnd.set( true ); + + int stat; + BOOST_CHECK( waitpid( child.pid(), &stat, 0 ) == child.pid() ); + } + catch ( ... ) { + } + } + catch ( ... ) { + } + + (&fcnd)->~__Condition<true>(); + + shmdt( buf ); + shmctl( id, IPC_RMID, &ds ); +} Added: trunk/complement/explore/test/mt/mt_test.h =================================================================== --- trunk/complement/explore/test/mt/mt_test.h (rev 0) +++ trunk/complement/explore/test/mt/mt_test.h 2006-12-14 08:26:44 UTC (rev 1453) @@ -0,0 +1,19 @@ +// -*- C++ -*- Time-stamp: <06/12/14 10:45:35 ptr> + +/* + * Copyright (c) 2006 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#ifndef __MT_TEST_H +#define __MT_TEST_H + +struct mt_test +{ + void fork(); +}; + +#endif // __MT_TEST_H Added: trunk/complement/explore/test/mt/mt_test_suite.cc =================================================================== --- trunk/complement/explore/test/mt/mt_test_suite.cc (rev 0) +++ trunk/complement/explore/test/mt/mt_test_suite.cc 2006-12-14 08:26:44 UTC (rev 1453) @@ -0,0 +1,26 @@ +// -*- C++ -*- Time-stamp: <06/12/14 11:12:02 ptr> + +/* + * Copyright (c) 2006 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#include "mt_test_suite.h" +#include "mt_test.h" + +using namespace boost::unit_test_framework; + +mt_test_suite::mt_test_suite() : + test_suite( "mt test suite" ) +{ + boost::shared_ptr<mt_test> instance( new mt_test() ); + + test_case *fork_tc = BOOST_CLASS_TEST_CASE( &mt_test::fork, instance ); + + // basic2_tc->depends_on( basic1_tc ); + + add( fork_tc ); +}; Added: trunk/complement/explore/test/mt/mt_test_suite.h =================================================================== --- trunk/complement/explore/test/mt/mt_test_suite.h (rev 0) +++ trunk/complement/explore/test/mt/mt_test_suite.h 2006-12-14 08:26:44 UTC (rev 1453) @@ -0,0 +1,22 @@ +// -*- C++ -*- Time-stamp: <06/12/14 10:42:18 ptr> + +/* + * Copyright (c) 2006 + * Petr Ovtchenkov + * + * Licensed under the Academic Free License Version 3.0 + * + */ + +#ifndef __MT_TEST_SUITE_H +#define __MT_TEST_SUITE_H + +#include <boost/test/unit_test.hpp> + +struct mt_test_suite : + public boost::unit_test_framework::test_suite +{ + mt_test_suite(); +}; + +#endif // __MT_TEST_SUITE_H Modified: trunk/complement/explore/test/mt/unit_test.cc =================================================================== --- trunk/complement/explore/test/mt/unit_test.cc 2006-12-14 07:27:44 UTC (rev 1452) +++ trunk/complement/explore/test/mt/unit_test.cc 2006-12-14 08:26:44 UTC (rev 1453) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/12/14 10:01:14 ptr> +// -*- C++ -*- Time-stamp: <06/12/14 10:47:39 ptr> /* * Copyright (c) 2002, 2003, 2004, 2006 @@ -11,6 +11,8 @@ #include <boost/test/unit_test.hpp> #include <config/feature.h> +#include "mt_test_suite.h" + using namespace boost::unit_test_framework; void timespec_diff(); @@ -25,6 +27,7 @@ void flock_test(); void lfs_test(); + #ifdef WIN32 test_suite *__cdecl init_unit_test_suite( int argc, char * * const argv ) #else @@ -50,5 +53,7 @@ // ts->add( BOOST_TEST_CASE( &flock_test ) ); // ts->add( BOOST_TEST_CASE( &lfs_test ) ); + ts->add( new mt_test_suite() ); + return ts; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |