From ed55cb8bfbff946940bf53f787edf7bd54d4b6bb Mon Sep 17 00:00:00 2001 From: tworm Date: Fri, 15 May 1998 16:17:43 +0000 Subject: Added one more test. Added more user friendly diagnostics. --- TAO/orbsvcs/tests/Concurrency/CC_client.cpp | 90 +++++++++++++++++++- TAO/orbsvcs/tests/Concurrency/CC_client.h | 4 + .../tests/Concurrency/CC_naming_service.cpp | 19 +++-- TAO/orbsvcs/tests/Concurrency/CC_naming_service.h | 2 +- TAO/orbsvcs/tests/Concurrency/CC_tests.cpp | 95 +++++++++++++++++++++- TAO/orbsvcs/tests/Concurrency/CC_tests.h | 22 +++++ 6 files changed, 215 insertions(+), 17 deletions(-) diff --git a/TAO/orbsvcs/tests/Concurrency/CC_client.cpp b/TAO/orbsvcs/tests/Concurrency/CC_client.cpp index db561609396..3f029a53788 100644 --- a/TAO/orbsvcs/tests/Concurrency/CC_client.cpp +++ b/TAO/orbsvcs/tests/Concurrency/CC_client.cpp @@ -119,12 +119,16 @@ CC_Client::run (void) if (this->run_basic_tests_ && success == CC_SUCCESS) { success = run_basic_tests (); + if(success==CC_FAIL) + ACE_DEBUG((LM_DEBUG, "Basic tests did not succeed\n")); tests_run = 1; } if (this->run_extended_tests_ && success == CC_SUCCESS) { success = run_extended_tests (this->extended_tests_params_); + if(success==CC_FAIL) + ACE_DEBUG((LM_DEBUG, "Extended tests did not succeed\n")); tests_run = 1; } @@ -160,25 +164,94 @@ CC_Client::run_basic_tests (void) CosConcurrencyControl::intention_read); Test_Single_Lock_With_Mode t5 (naming_service_, CosConcurrencyControl::intention_write); + // This test should be run for several different lock mode, but + // since we do not support + Test_Release_Not_Held_Lock t6 (naming_service_, + CosConcurrencyControl::read); if (t1.run () == CC_SUCCESS && t2.run () == CC_SUCCESS && t3.run () == CC_SUCCESS && t4.run () == CC_SUCCESS && - t5.run () == CC_SUCCESS) + t5.run () == CC_SUCCESS && + t6.run () == CC_SUCCESS ) return CC_SUCCESS; else return CC_FAIL; } +int +CC_Client::check_extended_test_params(char *params) +{ + // Format (regexp): [0-9]+;.*;.* + int index = 0; + int no_of_params = 0; + char *cp = params; // pointer to walk along the string + enum {START, NUMBER, ARG, ERROR} state = START; + + while(*cp!='\0') + { + switch(state) + { + case START: + if(isdigit(*cp)) + state = NUMBER; + else + state = ERROR; + break; + + case NUMBER: + if((*cp)==';') + { + state = ARG; + no_of_params++; + } + else + if(!isdigit(*cp)) + state = ERROR; + break; + + case ARG: + if((*cp)==';') + { + no_of_params++; + } + break; + + case ERROR: + return -1; + break; + + otherwise: + ACE_ERROR_RETURN((LM_ERROR, + "CC_Client::check_extended_test_params\n"), -1); + } + cp++; + } + if (state==ERROR) // there was only one character given and it was wrong + return -1; + else + return no_of_params; +} + int CC_Client::run_extended_tests (char *params) { int success = CC_FAIL; + int no_of_args = 0; ACE_DEBUG ((LM_DEBUG, "Params: %s\n", params)); + no_of_args = check_extended_test_params(params); + if(no_of_args==-1) + { + ACE_ERROR_RETURN((LM_ERROR, + "Error in parameter string (%s). Format: ';;'\n", params), CC_FAIL); + } + + ACE_DEBUG((LM_DEBUG, "Number of arguments: %i\n", no_of_args)); + char *cmd = ACE_OS::strtok (params, ";"); char *arg1 = ACE_OS::strtok (NULL, ";"); char *arg2 = ACE_OS::strtok (NULL, ";"); @@ -230,9 +303,18 @@ CC_Client::print_usage (void) int CC_Client::init_naming_service (void) { - ACE_NEW_RETURN (naming_service_, - CC_naming_service (this->orb_), - -1); + TAO_TRY + { + ACE_NEW_RETURN (naming_service_, + CC_naming_service (this->orb_, TAO_TRY_ENV), + -1); + TAO_CHECK_ENV; + } + TAO_CATCHANY + { + return -1; + } + TAO_ENDTRY; return 0; } diff --git a/TAO/orbsvcs/tests/Concurrency/CC_client.h b/TAO/orbsvcs/tests/Concurrency/CC_client.h index 46cd53b2060..976b67595ce 100644 --- a/TAO/orbsvcs/tests/Concurrency/CC_client.h +++ b/TAO/orbsvcs/tests/Concurrency/CC_client.h @@ -69,6 +69,10 @@ private: // Runs the extended tests (on more lock sets). Returns CC_SUCCESS // upon success CC_FAIL otherwise. + int check_extended_test_params(char *params); + // Checks the parameters given to the run_extended_tests() function. + // returns -1 if an error is found. + CC_naming_service *naming_service_; // A pointer to the naming service used for this test. diff --git a/TAO/orbsvcs/tests/Concurrency/CC_naming_service.cpp b/TAO/orbsvcs/tests/Concurrency/CC_naming_service.cpp index 314ee898a36..1d43bcb1b3c 100644 --- a/TAO/orbsvcs/tests/Concurrency/CC_naming_service.cpp +++ b/TAO/orbsvcs/tests/Concurrency/CC_naming_service.cpp @@ -20,7 +20,7 @@ #include "CC_naming_service.h" -CC_naming_service::CC_naming_service (CORBA::ORB_var orb) +CC_naming_service::CC_naming_service (CORBA::ORB_var orb, CORBA::Environment &_env) : naming_context_ (0), cc_factory_key_ (0), orb_ (0), @@ -28,7 +28,10 @@ CC_naming_service::CC_naming_service (CORBA::ORB_var orb) { this->orb_ = orb; - init_naming_service (); + int success = init_naming_service (); + if(success<0) + TAO_THROW (CORBA::INTERNAL (CORBA::COMPLETED_NO)); + } CC_naming_service::~CC_naming_service (void) @@ -78,7 +81,7 @@ CC_naming_service::bind_name (char *n, CORBA::Environment &_env) { ACE_DEBUG ((LM_DEBUG, "CC_Client::bind_name\n")); - + TAO_TRY { CosNaming::Name ns_name (1); @@ -102,7 +105,7 @@ CC_naming_service::get_lock_set_factory (void) return this->factory_; } -int +int CC_naming_service::init_naming_service (void) { TAO_TRY @@ -118,17 +121,17 @@ CC_naming_service::init_naming_service (void) CosNaming::NamingContext::_narrow (naming_obj.in (), TAO_TRY_ENV); TAO_CHECK_ENV; - + CORBA::Object_var factory_obj = get_obj_from_name ("CosConcurrency", "LockSetFactory", TAO_TRY_ENV); TAO_CHECK_ENV; - + this->factory_ = CosConcurrencyControl::LockSetFactory::_narrow (factory_obj.in (),TAO_TRY_ENV); TAO_CHECK_ENV; - + if (CORBA::is_nil (this->factory_.in ())) ACE_ERROR_RETURN ((LM_ERROR, " could not resolve lock set factory in Naming service\n"), @@ -140,6 +143,6 @@ CC_naming_service::init_naming_service (void) return -1; } TAO_ENDTRY; - + return 0; } diff --git a/TAO/orbsvcs/tests/Concurrency/CC_naming_service.h b/TAO/orbsvcs/tests/Concurrency/CC_naming_service.h index 998d2e17895..8a994923558 100644 --- a/TAO/orbsvcs/tests/Concurrency/CC_naming_service.h +++ b/TAO/orbsvcs/tests/Concurrency/CC_naming_service.h @@ -35,7 +35,7 @@ class CC_naming_service // This class declares an interface to the naming service for the // concurrency service tests. public: - CC_naming_service (CORBA::ORB_var orb_); + CC_naming_service (CORBA::ORB_var orb_, CORBA::Environment &_env); // Default constructor ~CC_naming_service (void); diff --git a/TAO/orbsvcs/tests/Concurrency/CC_tests.cpp b/TAO/orbsvcs/tests/Concurrency/CC_tests.cpp index 72f25252e88..d44aecd7ddb 100644 --- a/TAO/orbsvcs/tests/Concurrency/CC_tests.cpp +++ b/TAO/orbsvcs/tests/Concurrency/CC_tests.cpp @@ -78,7 +78,8 @@ CC_Test::get_lock_mode_name (CosConcurrencyControl::lock_mode mode) return "unknown lock mode"; } -// Here is the test start. +// ================================ +// Here the tests start. Test_Single_Lock_With_Mode::Test_Single_Lock_With_Mode (CC_naming_service *naming_service, CosConcurrencyControl::lock_mode mode) @@ -157,6 +158,8 @@ Test_Single_Lock_With_Mode::run (int times_to_run) return CC_SUCCESS; } +// ================================ + Test_Setup_LockSet::Test_Setup_LockSet (CC_naming_service *naming_service, char *name) : CC_Test (naming_service), @@ -199,6 +202,8 @@ Test_Setup_LockSet::run (int times_to_run) return CC_SUCCESS; } +// ================================ + Test_Use_Already_Created_LockSet:: Test_Use_Already_Created_LockSet (CC_naming_service *naming_service, char *name) @@ -242,6 +247,8 @@ Test_Use_Already_Created_LockSet::run (int times_to_run) return CC_SUCCESS; } +// ================================ + Test_Unlock_Already_Created_LockSet:: Test_Unlock_Already_Created_LockSet (CC_naming_service *naming_service, char *name) @@ -271,15 +278,95 @@ Test_Unlock_Already_Created_LockSet::run (int times_to_run) ccls->unlock (CosConcurrencyControl::read, TAO_TRY_ENV); - TAO_CHECK_ENV; - } TAO_CATCHANY { - TAO_TRY_ENV.print_exception ("Test_Against_Other_LockSet::run"); + TAO_TRY_ENV.print_exception ("Test_Unlock_Already_Created_LockSet::run"); return CC_FAIL; } TAO_ENDTRY; return CC_SUCCESS; } + +// ================================ + +Test_Release_Not_Held_Lock::Test_Release_Not_Held_Lock (CC_naming_service *naming_service, + CosConcurrencyControl::lock_mode mode) + : CC_Test (naming_service), + mode_ (mode) +{ +} + +Test_Release_Not_Held_Lock::~Test_Release_Not_Held_Lock (void) +{ +} + +int +Test_Release_Not_Held_Lock::run (int times_to_run) +{ + CORBA::Boolean lock_not_held; + + // Create the lock set + CosConcurrencyControl::LockSet_ptr cc_lock_set_ = create_lock_set (); + + TAO_TRY + { + // lock the lock + cc_lock_set_->lock (mode_, TAO_TRY_ENV); + ACE_DEBUG ((LM_DEBUG, + "%s lock set\n", + get_lock_mode_name (mode_))); + + // check to see if the lock is held + lock_not_held = cc_lock_set_->try_lock (mode_, + TAO_TRY_ENV); + + if (lock_not_held) + { + ACE_DEBUG ((LM_DEBUG, + "%s lock not held\n", + get_lock_mode_name (mode_))); + return CC_FAIL; + } + else + ACE_DEBUG ((LM_DEBUG, + "%s lock held\n", + get_lock_mode_name (mode_))); + + // release the lock + cc_lock_set_->unlock (mode_, + TAO_TRY_ENV); + ACE_DEBUG ((LM_DEBUG, + "%s lock released\n", + get_lock_mode_name (mode_))); + + // release the lock again. this should raise an exception + cc_lock_set_->unlock (mode_, + TAO_TRY_ENV); + + ACE_DEBUG ((LM_DEBUG, + "attemptet to release %s lock\n", + get_lock_mode_name (mode_))); + + TAO_CHECK_ENV; + } + TAO_CATCH(CosConcurrencyControl::LockNotHeld, userex) + { + // We should end here + ACE_UNUSED_ARG (userex); + ACE_DEBUG((LM_DEBUG, "CosConcurrencyControl::LockNotHeld\n")); + return CC_SUCCESS; + } + + TAO_CATCHANY + { + TAO_TRY_ENV.print_exception ("Test_Release_Not_Held_Lock::run"); + return CC_FAIL; + } + TAO_ENDTRY; + + CORBA::release (cc_lock_set_); + + return CC_FAIL; +} diff --git a/TAO/orbsvcs/tests/Concurrency/CC_tests.h b/TAO/orbsvcs/tests/Concurrency/CC_tests.h index 9739c2aa4f4..3d9bca5b57e 100644 --- a/TAO/orbsvcs/tests/Concurrency/CC_tests.h +++ b/TAO/orbsvcs/tests/Concurrency/CC_tests.h @@ -159,4 +159,26 @@ private: // The name of the lock }; +class Test_Release_Not_Held_Lock : public CC_Test +{ + // = TITLE + // This class tests that the LockNotHeld exception is thrown if a + // not held lock is released. +public: + Test_Release_Not_Held_Lock (CC_naming_service *naming_service_, + CosConcurrencyControl::lock_mode mode_); + // Default constructor. The naming service must be initialized + // before calling this method. The mode is the mode of the lock + + virtual ~Test_Release_Not_Held_Lock (void); + // Destructor + + virtual int run (int times_to_run = 1); + // Runs the test the specified number of times. + +private: + CosConcurrencyControl::lock_mode mode_; + // The lock mode of the lock being tested +}; + #endif /* !defined (_CC_TESTS_H_) */ -- cgit v1.2.1