diff options
author | iliyan <iliyan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2007-02-20 18:17:48 +0000 |
---|---|---|
committer | iliyan <iliyan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2007-02-20 18:17:48 +0000 |
commit | 84b3bb54fa0c814b121b4776a23fb14f02c8add6 (patch) | |
tree | 553c85e8a105214908fed2b09a75b4af2d2eae3c | |
parent | 942ac00df48fd2b7c59ed95a3885a4dd79d480de (diff) | |
download | ATCD-84b3bb54fa0c814b121b4776a23fb14f02c8add6.tar.gz |
ChangeLogTag: Tue Feb 20 18:08:47 UTC 2007 Iliyan Jeliazkov <iliyan@ociweb.com>
-rw-r--r-- | ACE/ChangeLog | 11 | ||||
-rw-r--r-- | ACE/tests/Object_Manager_Flipping_Test.cpp | 128 | ||||
-rw-r--r-- | ACE/tests/tests.mpc | 7 |
3 files changed, 146 insertions, 0 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 8905edf7bbf..1c205191f99 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,14 @@ +Tue Feb 20 18:08:47 UTC 2007 Iliyan Jeliazkov <iliyan@ociweb.com> + + * tests/Object_Manager_Flipping_Test.cpp: + * tests/tests.mpc: + + Adding new test verifying that after ACE::fini has been called, + the correct pointer value has been stored in TSS for the Service + Config. A subsequent call to ACE::init may SEGV + otherwise. Thanks to Bjoern Rasmussen <bjoern.d.rasmussen at + gmail dot com> for reporting it. + Tue Feb 20 17:15:37 UTC 2007 Adam Mitz <mitza@ociweb.com> * ace/config-qnx-rtp.h: diff --git a/ACE/tests/Object_Manager_Flipping_Test.cpp b/ACE/tests/Object_Manager_Flipping_Test.cpp new file mode 100644 index 00000000000..e2dc4349d39 --- /dev/null +++ b/ACE/tests/Object_Manager_Flipping_Test.cpp @@ -0,0 +1,128 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// tests +// +// = FILENAME +// Object_Manager_Flipping_Test.cpp +// +// = DESCRIPTION + +// Tests the basic function of the ACE_Service_Config in scenarios +// where the ACE_Object_Manager is being +// flipped. i.e. ACE::init/ACE::fini() are called in sequence +// (which can occur with loading DLLs). More specifically we test +// that the OM correctly controlls the lifecycle of the default SC +// instance, which is pointed to by a TSS pointer. +// +// = AUTHOR +// Iliyan Jeliazkov <iliyan@ociweb.com> +// +// ============================================================================ + +#include "test_config.h" +#include "ace/Object_Manager.h" +#include "ace/OS_Memory.h" +#include "ace/ACE.h" +#include "ace/Service_Config.h" + +ACE_RCSID(tests, Object_Manager_Flipping_Test, "$Id$") + +static u_int *ip; + +static const bool is_static_object_manager = +#if defined (ACE_HAS_STATIC_OBJECT_MANAGER) + true; +#else + false; +#endif + +extern "C" +void +hook1 (void) +{ + delete ip; + ip = 0; +} + + +int run_main (int, ACE_TCHAR *[]) +{ + + // Causing the creation of a SC instance and the corresponding TSS + // key. It is not registered with the Object Manager, but beware - + // OM finalization will destroy it too. + ACE_Service_Gestalt *p0 = ACE_Service_Config::instance (); + + ACE_Service_Gestalt *p1 = 0; + u_int errors = 0; + + // ... + { + ACE::init (); + ACE_START_TEST (ACE_TEXT ("Object_Manager_Flipping_Test")); + + + // If hook1 never gets called, this will show up as a memory leak. + ACE_NEW_RETURN (ip, + u_int, + -1); + + if (ACE_OS::atexit (hook1) != 0) + { + ++errors; + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("ACE_OS::atexit () returned non-zero!!!!"))); + } + + // Obtain a SC instance which will be later used to compare with others. + p1 = ACE_Service_Config::instance (); + + // ACE_ASSERT uses Log_Msg::instance() and needs to be done only + // after ACE_START_TEST + + ACE_ASSERT (p0 == p1); + ACE_ASSERT (!p0->is_opened ()); + ACE_END_TEST; + + + // ACE::fini() destroys the SC (unmanaged) singleton ... + // Next time we ask for one, it will be a different instance. + ACE::fini (); + } + + p1 = ACE_Service_Config::instance (); + + // This is a legitimate test, but more importantly an + // attemp to dereference p1 should succeed. If SC's TSS + // was not cleaned correctly this will SEGV. As will the + // following ACE::init, as it tries to use the SC instance. + + if (p1->is_opened ()) + ++errors; + + // Not using ACE_ASSERT because ACE is not initialized yet. + + { + ACE::init(); + ACE_START_TEST (ACE_TEXT ("Object_Manager_Flipping_Test")); + + ACE_Service_Gestalt *p2 = ACE_Service_Config::instance (); + + // ACE_ASSERT uses Log_Msg::instance() and needs to be done only + // after ACE_START_TEST + ACE_ASSERT (p1 == p2); + + // An attempt to dereference should be fine. + ACE_ASSERT (!p2->is_opened ()); + + ACE_END_TEST; + ACE::fini(); // Flipped twice + } + + return errors == 0 ? 0 : 1; + +} diff --git a/ACE/tests/tests.mpc b/ACE/tests/tests.mpc index 72ddf8b6be7..c79b0d36eaf 100644 --- a/ACE/tests/tests.mpc +++ b/ACE/tests/tests.mpc @@ -646,6 +646,13 @@ project(Object Manager Test) : acetest { } } +project(Object Manager Flipping Test) : acetest { + exename = Object_Manager_Flipping_Test + Source_Files { + Object_Manager_Flipping_Test.cpp + } +} + project(Obstack Test) : acetest { exename = Obstack_Test Source_Files { |