diff options
author | Sven Gothel <[email protected]> | 2022-05-03 06:30:55 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-05-03 06:30:55 +0200 |
commit | 4c46f56125ca6fb0241b62a76725f6b96a457bcf (patch) | |
tree | 5c1c11c22420291045e94c0f71dea9e29653876b /trial/direct_bt | |
parent | b41582f33e0a0f393e6f6703342a00b6b9d9109b (diff) |
Trial Unit Test C++: Fix, have test_client_server00 pass successful
Diffstat (limited to 'trial/direct_bt')
-rw-r--r-- | trial/direct_bt/dbt_base_client_server.hpp | 17 | ||||
-rw-r--r-- | trial/direct_bt/dbt_endpoint.hpp | 1 | ||||
-rw-r--r-- | trial/direct_bt/dbt_server00.hpp | 19 | ||||
-rw-r--r-- | trial/direct_bt/dbt_utils.hpp | 6 | ||||
-rw-r--r-- | trial/direct_bt/test_client_server00.cpp | 27 |
5 files changed, 46 insertions, 24 deletions
diff --git a/trial/direct_bt/dbt_base_client_server.hpp b/trial/direct_bt/dbt_base_client_server.hpp index 6e731a98..9746aca8 100644 --- a/trial/direct_bt/dbt_base_client_server.hpp +++ b/trial/direct_bt/dbt_base_client_server.hpp @@ -34,38 +34,41 @@ class BaseDBTClientServer { private: - static constexpr const bool DEBUG = true; + static constexpr const bool debug = true; + + jau::fraction_i64 test_timeout = 0_s; jau::simple_timer timeour_timer = jau::simple_timer("DBTTrial-Timeout", 1_s /* shutdown timeout */); jau::fraction_i64 timeout_func(jau::simple_timer& timer) { if( !timer.shall_stop() ) { - fprintf(stderr, "DBTTrial Timeout -> abort\n"); + fprintf(stderr, "***** DBTTrial Timeout %s sec -> abort *****\n", test_timeout.to_string(true).c_str()); abort(); } return 0_s; } BaseDBTClientServer() noexcept { - if( DEBUG ) { + if( debug ) { setenv("direct_bt.debug", "true", 1 /* overwrite */); // setenv("direct_bt.debug", "true,gatt.data", 1 /* overwrite */); } - REQUIRE( DBTUtils::rmKeyFolder() ); - REQUIRE( DBTUtils::mkdirKeyFolder() ); + DBTUtils::rmKeyFolder(); + DBTUtils::mkdirKeyFolder(); } void close() { timeour_timer.stop(); BTManager& manager = BTManager::get(); - +#if 0 jau::darray<BTAdapterRef> adapters = manager.getAdapters(); for(BTAdapterRef a : adapters) { a->stopAdvertising(); a->stopDiscovery(); a->setPowered(false); } +#endif // All implicit via destructor or shutdown hook! manager.close(); /* implies: adapter.close(); */ } @@ -89,6 +92,7 @@ class BaseDBTClientServer { */ void setupTest(const jau::fraction_i64 timeout = 0_s) { timeour_timer.stop(); + test_timeout = timeout; BTManager& manager = BTManager::get(); jau::darray<BTAdapterRef> adapters = manager.getAdapters(); for(BTAdapterRef a : adapters) { @@ -114,6 +118,7 @@ class BaseDBTClientServer { */ void cleanupTest() { timeour_timer.stop(); + test_timeout = 0_s; BTManager& manager = BTManager::get(); jau::darray<BTAdapterRef> adapters = manager.getAdapters(); for(BTAdapterRef a : adapters) { diff --git a/trial/direct_bt/dbt_endpoint.hpp b/trial/direct_bt/dbt_endpoint.hpp index df5ee714..9653ddf0 100644 --- a/trial/direct_bt/dbt_endpoint.hpp +++ b/trial/direct_bt/dbt_endpoint.hpp @@ -113,7 +113,6 @@ class DBTEndpoint { } jau::fprintf_td(stderr, "****** Adapter REMOVED: Ignored: %s\n", adapter->toString().c_str()); } - BTManager::get().removeChangedAdapterSetCallback(myChangedAdapterSetFunc); return true; } diff --git a/trial/direct_bt/dbt_server00.hpp b/trial/direct_bt/dbt_server00.hpp index 5bcce73c..5d496aa1 100644 --- a/trial/direct_bt/dbt_server00.hpp +++ b/trial/direct_bt/dbt_server00.hpp @@ -149,6 +149,7 @@ class DBTServer00 : public DBTServerTest { ) ); + jau::sc_atomic_bool sync_data; std::mutex mtx_sync; BTDeviceRef connectedDevice; @@ -160,11 +161,13 @@ class DBTServer00 : public DBTServerTest { void setDevice(BTDeviceRef cd) { const std::lock_guard<std::mutex> lock(mtx_sync); // RAII-style acquire and relinquish via destructor + // jau::sc_atomic_critical sync(sync_data); connectedDevice = cd; } BTDeviceRef getDevice() { const std::lock_guard<std::mutex> lock(mtx_sync); // RAII-style acquire and relinquish via destructor + // jau::sc_atomic_critical sync(sync_data); return connectedDevice; } @@ -323,6 +326,7 @@ class DBTServer00 : public DBTServerTest { bool shallStopPulseSender() { const std::lock_guard<std::mutex> lock(parent.mtx_sync); // RAII-style acquire and relinquish via destructor + // jau::sc_atomic_critical sync(parent.sync_data); return stopPulseSenderFlag; } @@ -330,7 +334,7 @@ class DBTServer00 : public DBTServerTest { { const BTDeviceRef connectedDevice_ = parent.getDevice(); const std::string connectedDeviceStr = nullptr != connectedDevice_ ? connectedDevice_->toString() : "n/a"; - fprintf_td(stderr, "****** Server GATT::PULSE Start %s\n", connectedDeviceStr); + fprintf_td(stderr, "****** Server GATT::PULSE Start %s\n", connectedDeviceStr.c_str()); } while( !shallStopPulseSender() ) { BTDeviceRef connectedDevice_ = parent.getDevice(); @@ -356,7 +360,7 @@ class DBTServer00 : public DBTServerTest { { const BTDeviceRef connectedDevice_ = parent.getDevice(); const std::string connectedDeviceStr = nullptr != connectedDevice_ ? connectedDevice_->toString() : "n/a"; - fprintf_td(stderr, "****** Server GATT::PULSE End %s\n", connectedDeviceStr); + fprintf_td(stderr, "****** Server GATT::PULSE End %s\n", connectedDeviceStr.c_str()); } } @@ -388,6 +392,7 @@ class DBTServer00 : public DBTServerTest { void clear() { const std::lock_guard<std::mutex> lock(parent.mtx_sync); // RAII-style acquire and relinquish via destructor + // jau::sc_atomic_critical sync(parent.sync_data); handlePulseDataNotify = 0; handlePulseDataIndicate = 0; @@ -400,9 +405,12 @@ class DBTServer00 : public DBTServerTest { void close() noexcept { { - const std::lock_guard<std::mutex> lock(parent.mtx_sync); // RAII-style acquire and relinquish via destructor clear(); - stopPulseSenderFlag = true; + { + const std::lock_guard<std::mutex> lock(parent.mtx_sync); // RAII-style acquire and relinquish via destructor + // jau::sc_atomic_critical sync(parent.sync_data); + stopPulseSenderFlag = true; + } } if( pulseSenderThread.joinable() ) { pulseSenderThread.join(); @@ -415,6 +423,7 @@ class DBTServer00 : public DBTServerTest { match, (int)initialMTU, device->toString().c_str()); if( match ) { const std::lock_guard<std::mutex> lock(parent.mtx_sync); // RAII-style acquire and relinquish via destructor + // jau::sc_atomic_critical sync(parent.sync_data); usedMTU = initialMTU; } } @@ -432,6 +441,7 @@ class DBTServer00 : public DBTServerTest { const uint16_t usedMTU_old = usedMTU; if( match ) { const std::lock_guard<std::mutex> lock(parent.mtx_sync); // RAII-style acquire and relinquish via destructor + // jau::sc_atomic_critical sync(parent.sync_data); usedMTU = mtu; } fprintf_td(stderr, "****** Server GATT::mtuChanged(match %d): %d -> %d, %s\n", @@ -525,6 +535,7 @@ class DBTServer00 : public DBTServerTest { device->toString().c_str(), s->toString().c_str(), c->toString().c_str(), d->toString().c_str(), value.toString().c_str()); } if( match ) { + // jau::sc_atomic_critical sync(parent.sync_data); if( c->getValueType()->equivalent( DBTConstants::PulseDataUUID ) ) { const std::lock_guard<std::mutex> lock(parent.mtx_sync); // RAII-style acquire and relinquish via destructor handlePulseDataNotify = notificationEnabled ? c->getValueHandle() : 0; diff --git a/trial/direct_bt/dbt_utils.hpp b/trial/direct_bt/dbt_utils.hpp index 2a9a132a..8db548bc 100644 --- a/trial/direct_bt/dbt_utils.hpp +++ b/trial/direct_bt/dbt_utils.hpp @@ -62,8 +62,8 @@ class DBTUtils { name.c_str(), errno, strerror(errno)); return errno; } - is_file = S_ISDIR( s.st_mode ); - is_dir = S_ISREG( s.st_mode ); + is_file = S_ISREG( s.st_mode ); + is_dir = S_ISDIR( s.st_mode ); return 0; } @@ -149,12 +149,14 @@ class DBTUtils { if( 0 != ::remove( file.c_str() ) ) { if( ENOENT == errno ) { // not existing + jau::fprintf_td(stderr, "****** PATH '%s': remove OK, not existing\n", file.c_str()); return true; } else { jau::fprintf_td(stderr, "****** PATH '%s': remove failed: %d %s\n", file.c_str(), errno, strerror(errno)); return false; } } else { + jau::fprintf_td(stderr, "****** PATH '%s': remove OK, removed\n", file.c_str()); return true; } #if 0 diff --git a/trial/direct_bt/test_client_server00.cpp b/trial/direct_bt/test_client_server00.cpp index 17454b1d..4bcd2597 100644 --- a/trial/direct_bt/test_client_server00.cpp +++ b/trial/direct_bt/test_client_server00.cpp @@ -51,14 +51,15 @@ TEST_CASE( "BTManager Bringup Trial 00", "[trial][BTManager][bringup]" ) { jau::fprintf_td(stderr, "Direct-BT Native Version %s (API %s)\n", DIRECT_BT_VERSION, DIRECT_BT_VERSION_API); BTManager & manager = BTManager::get(); - jau::darray<BTAdapterRef> adapters = manager.getAdapters(); - jau::fprintf_td(stderr, "Adapter: Count %u\n", adapters.size()); + { + jau::fprintf_td(stderr, "Adapter: Count %u\n", adapters.size()); - for(jau::nsize_t i=0; i<adapters.size(); i++) { - jau::fprintf_td(stderr, "%u: %s\n", i, adapters[i]->toString().c_str()); + for(jau::nsize_t i=0; i<adapters.size(); i++) { + jau::fprintf_td(stderr, "%u: %s\n", i, adapters[i]->toString().c_str()); + } + REQUIRE( adapters.size() >= 1 ); } - REQUIRE( adapters.size() >= 1 ); jau::fprintf_td(stderr, "Adapter: Status Checks\n"); for(BTAdapterRef a : adapters) { @@ -68,11 +69,6 @@ TEST_CASE( "BTManager Bringup Trial 00", "[trial][BTManager][bringup]" ) { REQUIRE( 4 <= a->getBTMajorVersion() ); } - jau::fprintf_td(stderr, "Manager: Closing\n"); - manager.close(); /* implies: adapter.close(); */ - - jau::fprintf_td(stderr, "Test: Done\n"); - base_test_framework.cleanupTest(); } @@ -82,10 +78,19 @@ TEST_CASE( "BTManager Bringup Trial 00", "[trial][BTManager][bringup]" ) { * - test that at least one adapter are present * - validating basic default adapter status */ -TEST_CASE( "BTManager Bringup Trial 00", "[trial][BTManager][bringup]" ) { +TEST_CASE( "Server StartStop and SwitchRole Trial 10", "[trial][server][client][startstop][switchrole]" ) { base_test_framework.setupTest(); BTManager & manager = BTManager::get(); + { + jau::darray<BTAdapterRef> adapters = manager.getAdapters(); + jau::fprintf_td(stderr, "Adapter: Count %u\n", adapters.size()); + + for(jau::nsize_t i=0; i<adapters.size(); i++) { + jau::fprintf_td(stderr, "%u: %s\n", i, adapters[i]->toString().c_str()); + } + REQUIRE( adapters.size() >= 1 ); + } REQUIRE( manager.getAdapterCount() >= 1 ); const std::string serverName = "TestDBTCS00-S-T10"; |