diff options
author | Sven Gothel <[email protected]> | 2022-09-15 17:47:02 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-09-15 17:47:02 +0200 |
commit | 8bf5e8ef1804209fcd7ce69261e1b609d6c67087 (patch) | |
tree | ff20700ae1cd3d0ae28dd913d4b69ad22ed4d837 /trial/direct_bt | |
parent | 66d499469cf7173ef00b6441fc6c00a9c0b0cbe6 (diff) |
Trial Unit Tests: Reorg and cleanup to be expanded (for reset test)
- When passing client and server in test8x_fullCycle() overload, expect them to be setup already.
- client: KEEP_CONNECTED -> do_disconnect for clarity and along do_disconnect_randomly
Diffstat (limited to 'trial/direct_bt')
-rw-r--r-- | trial/direct_bt/dbt_client01.hpp | 31 | ||||
-rw-r--r-- | trial/direct_bt/dbt_client_server1x.hpp | 24 | ||||
-rw-r--r-- | trial/direct_bt/dbt_client_test.hpp | 4 | ||||
-rw-r--r-- | trial/direct_bt/dbt_server01.hpp | 12 | ||||
-rw-r--r-- | trial/direct_bt/test_provoke_client_server_i470.cpp | 34 |
5 files changed, 60 insertions, 45 deletions
diff --git a/trial/direct_bt/dbt_client01.hpp b/trial/direct_bt/dbt_client01.hpp index 6ce56d25..80f76ed9 100644 --- a/trial/direct_bt/dbt_client01.hpp +++ b/trial/direct_bt/dbt_client01.hpp @@ -42,9 +42,10 @@ using namespace jau::fractions_i64_literals; */ class DBTClient01 : public DBTClientTest { private: - bool KEEP_CONNECTED = false; + bool do_disconnect = true; + bool do_disconnect_randomly = false; - bool REMOVE_DEVICE = false; + bool do_remove_device = false; DiscoveryPolicy discoveryPolicy = DiscoveryPolicy::PAUSE_CONNECTED_UNTIL_READY; // default value @@ -62,8 +63,6 @@ class DBTClient01 : public DBTClientTest { jau::sc_atomic_int completedMeasurementsSuccess = 0; jau::sc_atomic_int measurementsLeft = 0; - bool do_disconnect = false; - const uint64_t timestamp_t0 = getCurrentMilliseconds(); // const fraction_i64 timestamp_t0 = jau::getMonotonicMicroseconds(); @@ -189,7 +188,7 @@ class DBTClient01 : public DBTClientTest { } } - void disconnectDevice(BTDeviceRef device) { + void disconnectDeviceRandomly(BTDeviceRef device) { // sleep range: 100 - 1500 ms // sleep range: 100 - 1500 ms static const int sleep_min = 100; @@ -219,9 +218,9 @@ class DBTClient01 : public DBTClientTest { dc.detach(); // processReadyDevice(device); // AdapterStatusListener::deviceReady() explicitly allows prolonged and complex code execution! - if( parent.do_disconnect ) { + if( parent.do_disconnect_randomly ) { parent.running_threads.count_up(); - std::thread disconnectThread(&MyAdapterStatusListener::disconnectDevice, this, device); + std::thread disconnectThread(&MyAdapterStatusListener::disconnectDeviceRandomly, this, device); disconnectThread.detach(); } } @@ -289,11 +288,11 @@ class DBTClient01 : public DBTClientTest { std::shared_ptr<AdapterStatusListener> myAdapterStatusListener = std::make_shared<MyAdapterStatusListener>(*this); public: - DBTClient01(const std::string& adapterName_, const EUI48 useAdapter_, const BTMode btMode_, const bool do_disconnect_) { + DBTClient01(const std::string& adapterName_, const EUI48 useAdapter_, const BTMode btMode_, const bool do_disconnect_randomly_=false) { this->adapterName = adapterName_; this->useAdapter = useAdapter_; this->btMode = btMode_; - this->do_disconnect = do_disconnect_; + this->do_disconnect_randomly = do_disconnect_randomly_; } ~DBTClient01() { @@ -328,11 +327,11 @@ class DBTClient01 : public DBTClientTest { void setDiscoveryPolicy(const DiscoveryPolicy v) override { discoveryPolicy = v; } - void setKeepConnected(const bool v) override { - KEEP_CONNECTED = v; + void setDisconnectDevice(const bool v) override { + do_disconnect = v; } void setRemoveDevice(const bool v) override { - REMOVE_DEVICE = v; + do_remove_device = v; } private: @@ -416,7 +415,7 @@ class DBTClient01 : public DBTClientTest { try { jau::darray<BTGattServiceRef> primServices = device->getGattServices(); if( 0 == primServices.size() ) { - fprintf_td(stderr, "****** Clinet Processing Ready Device: getServices() failed %s\n", device->toString().c_str()); + fprintf_td(stderr, "****** Client Processing Ready Device: getServices() failed %s\n", device->toString().c_str()); goto exit; } @@ -597,8 +596,8 @@ class DBTClient01 : public DBTClientTest { device->removeAllCharListener(); - if( !KEEP_CONNECTED ) { - if( REMOVE_DEVICE ) { + if( do_disconnect ) { + if( do_remove_device ) { device->remove(); } else { device->disconnect(); @@ -624,7 +623,7 @@ class DBTClient01 : public DBTClientTest { void removeDevice(BTDeviceRef device) { fprintf_td(stderr, "****** Client Remove Device: removing: %s\n", device->getAddressAndType().toString().c_str()); - if( REMOVE_DEVICE ) { + if( do_remove_device ) { device->remove(); } running_threads.count_down(); diff --git a/trial/direct_bt/dbt_client_server1x.hpp b/trial/direct_bt/dbt_client_server1x.hpp index faee48a8..3274b30f 100644 --- a/trial/direct_bt/dbt_client_server1x.hpp +++ b/trial/direct_bt/dbt_client_server1x.hpp @@ -64,17 +64,25 @@ class DBTClientServer1x { const BTSecurityLevel secLevelClient, const ExpectedPairing clientExpPairing) { std::shared_ptr<DBTServer01> server = std::make_shared<DBTServer01>("S-"+suffix, EUI48::ALL_DEVICE, BTMode::DUAL, - serverSC, secLevelServer, false /* do_disconnect_ */); - std::shared_ptr<DBTClient01> client = std::make_shared<DBTClient01>("C-"+suffix, EUI48::ALL_DEVICE, BTMode::DUAL, false /* do_disconnect_ */); + serverSC, secLevelServer); + std::shared_ptr<DBTClient01> client = std::make_shared<DBTClient01>("C-"+suffix, EUI48::ALL_DEVICE, BTMode::DUAL); + + server->setProtocolSessionsLeft( protocolSessionCount ); + + client->setProtocolSessionsLeft( protocolSessionCount ); + client->setDisconnectDevice( true ); // default, auto-disconnect after work is done + client->setRemoveDevice( false ); // default, test side-effects + client->setDiscoveryPolicy( DiscoveryPolicy::PAUSE_CONNECTED_UNTIL_DISCONNECTED ); + test8x_fullCycle(suffix, - protocolSessionCount, DBTConstants::max_connections_per_session, true /* expSuccess */, + DBTConstants::max_connections_per_session, true /* expSuccess */, server_client_order, server, secLevelServer, serverExpPairing, client, secLevelClient, clientExpPairing); } void test8x_fullCycle(const std::string& suffix, - const int protocolSessionCount, const int max_connections_per_session, const bool expSuccess, + const int max_connections_per_session, const bool expSuccess, const bool server_client_order, std::shared_ptr<DBTServerTest> server, const BTSecurityLevel secLevelServer, const ExpectedPairing serverExpPairing, std::shared_ptr<DBTClientTest> client, const BTSecurityLevel secLevelClient, const ExpectedPairing clientExpPairing) @@ -82,6 +90,7 @@ class DBTClientServer1x { (void)secLevelServer; (void)serverExpPairing; + const int protocolSessionCount = std::min(server->getProtocolSessionsLeft(), client->getProtocolSessionsLeft()); const jau::fraction_timespec t0 = jau::getMonotonicTime(); std::shared_ptr<BTManager> manager = BTManager::get(); @@ -95,13 +104,6 @@ class DBTClientServer1x { REQUIRE( adapters.size() >= 2 ); } - server->setProtocolSessionsLeft(protocolSessionCount); - - client->setProtocolSessionsLeft( protocolSessionCount ); - client->setKeepConnected( false ); // default, auto-disconnect after work is done - client->setRemoveDevice( false ); // default, test side-effects - client->setDiscoveryPolicy( DiscoveryPolicy::PAUSE_CONNECTED_UNTIL_DISCONNECTED ); - ChangedAdapterSetCallback myChangedAdapterSetFunc = DBTEndpoint::initChangedAdapterSetListener(manager, server_client_order ? std::vector<DBTEndpointRef>{ server, client } : std::vector<DBTEndpointRef>{ client, server } ); diff --git a/trial/direct_bt/dbt_client_test.hpp b/trial/direct_bt/dbt_client_test.hpp index d97bb3b3..ef389e67 100644 --- a/trial/direct_bt/dbt_client_test.hpp +++ b/trial/direct_bt/dbt_client_test.hpp @@ -43,9 +43,9 @@ class DBTClientTest : public DBTEndpoint { /** * Set disconnect after processing. * - * Default is `false`. + * Default is `true`. */ - virtual void setKeepConnected(const bool v) = 0; + virtual void setDisconnectDevice(const bool v) = 0; /** * Set remove device when disconnecting. diff --git a/trial/direct_bt/dbt_server01.hpp b/trial/direct_bt/dbt_server01.hpp index b0ee1cbc..ebe108dd 100644 --- a/trial/direct_bt/dbt_server01.hpp +++ b/trial/direct_bt/dbt_server01.hpp @@ -80,7 +80,7 @@ class DBTServer01 : public DBTServerTest { jau::sc_atomic_int servedProtocolSessionsSuccess = 0; jau::sc_atomic_int servingProtocolSessionsLeft = 1; - bool do_disconnect = false; + bool do_disconnect_randomly = false; DBGattServerRef dbGattServer = std::make_shared<DBGattServer>( /* services: */ @@ -383,7 +383,7 @@ class DBTServer01 : public DBTServerTest { parent.running_threads.count_down(); } - void disconnectDevice() { + void disconnectDeviceRandomly() { // sleep range: 100 - 1500 ms // sleep range: 100 - 1500 ms static const int sleep_min = 100; @@ -463,9 +463,9 @@ class DBTServer01 : public DBTServerTest { fprintf_td(stderr, "****** Server GATT::mtuChanged(match %d, served %zu, left %zu): %d -> %d, %s\n", match, parent.servedProtocolSessionsTotal.load(), parent.servingProtocolSessionsLeft.load(), match ? (int)usedMTU_old : 0, (int)mtu, device->toString().c_str()); - if( parent.do_disconnect ) { + if( parent.do_disconnect_randomly ) { parent.running_threads.count_up(); - std::thread disconnectThread(&MyGATTServerListener::disconnectDevice, this); + std::thread disconnectThread(&MyGATTServerListener::disconnectDeviceRandomly, this); disconnectThread.detach(); } } @@ -585,14 +585,14 @@ class DBTServer01 : public DBTServerTest { public: DBTServer01(const std::string& adapterName_, const jau::EUI48& useAdapter_, const BTMode btMode_, - const bool use_SC_, const BTSecurityLevel adapterSecurityLevel_, const bool do_disconnect_) + const bool use_SC_, const BTSecurityLevel adapterSecurityLevel_, const bool do_disconnect_randomly_=false) { this->adapterName = adapterName_; this->useAdapter = useAdapter_; this->btMode = btMode_; this->use_SC = use_SC_; this->adapterSecurityLevel = adapterSecurityLevel_; - this->do_disconnect = do_disconnect_; + this->do_disconnect_randomly = do_disconnect_randomly_; dbGattServer->addListener( gattServerListener ); } diff --git a/trial/direct_bt/test_provoke_client_server_i470.cpp b/trial/direct_bt/test_provoke_client_server_i470.cpp index 36b407b5..ad7ba08d 100644 --- a/trial/direct_bt/test_provoke_client_server_i470.cpp +++ b/trial/direct_bt/test_provoke_client_server_i470.cpp @@ -56,14 +56,21 @@ class TestDBTClientServer_i470 : public DBTClientServer1x { const BTSecurityLevel secLevelClient = BTSecurityLevel::ENC_ONLY; const ExpectedPairing serverExpPairing = ExpectedPairing::DONT_CARE; const ExpectedPairing clientExpPairing = ExpectedPairing::DONT_CARE; - const bool client_do_disconnect = true; - const bool server_do_disconnect = false; + const bool client_do_disconnect_random = true; + const bool server_do_disconnect_random = false; - std::shared_ptr<DBTServerTest> server = std::make_shared<DBTServer01>("S-"+suffix, EUI48::ALL_DEVICE, BTMode::DUAL, serverSC, secLevelServer, server_do_disconnect); - std::shared_ptr<DBTClientTest> client = std::make_shared<DBTClient01>("C-"+suffix, EUI48::ALL_DEVICE, BTMode::DUAL, client_do_disconnect); + std::shared_ptr<DBTServerTest> server = std::make_shared<DBTServer01>("S-"+suffix, EUI48::ALL_DEVICE, BTMode::DUAL, serverSC, secLevelServer, server_do_disconnect_random); + std::shared_ptr<DBTClientTest> client = std::make_shared<DBTClient01>("C-"+suffix, EUI48::ALL_DEVICE, BTMode::DUAL, client_do_disconnect_random); + + server->setProtocolSessionsLeft( protocolSessionCount ); + + client->setProtocolSessionsLeft( protocolSessionCount ); + client->setDisconnectDevice( true ); // default, auto-disconnect after work is done + client->setRemoveDevice( false ); // default, test side-effects + client->setDiscoveryPolicy( DiscoveryPolicy::PAUSE_CONNECTED_UNTIL_DISCONNECTED ); test8x_fullCycle(suffix, - protocolSessionCount, max_connections_per_session, expSuccess, + max_connections_per_session, expSuccess, server_client_order, server, secLevelServer, serverExpPairing, client, secLevelClient, clientExpPairing); @@ -84,14 +91,21 @@ class TestDBTClientServer_i470 : public DBTClientServer1x { const BTSecurityLevel secLevelClient = BTSecurityLevel::ENC_ONLY; const ExpectedPairing serverExpPairing = ExpectedPairing::DONT_CARE; const ExpectedPairing clientExpPairing = ExpectedPairing::DONT_CARE; - const bool client_do_disconnect = false; - const bool server_do_disconnect = true; + const bool client_do_disconnect_random = false; + const bool server_do_disconnect_random = true; + + std::shared_ptr<DBTServerTest> server = std::make_shared<DBTServer01>("S-"+suffix, EUI48::ALL_DEVICE, BTMode::DUAL, serverSC, secLevelServer, server_do_disconnect_random); + std::shared_ptr<DBTClientTest> client = std::make_shared<DBTClient01>("C-"+suffix, EUI48::ALL_DEVICE, BTMode::DUAL, client_do_disconnect_random); + + server->setProtocolSessionsLeft( protocolSessionCount ); - std::shared_ptr<DBTServerTest> server = std::make_shared<DBTServer01>("S-"+suffix, EUI48::ALL_DEVICE, BTMode::DUAL, serverSC, secLevelServer, server_do_disconnect); - std::shared_ptr<DBTClientTest> client = std::make_shared<DBTClient01>("C-"+suffix, EUI48::ALL_DEVICE, BTMode::DUAL, client_do_disconnect); + client->setProtocolSessionsLeft( protocolSessionCount ); + client->setDisconnectDevice( true ); // default, auto-disconnect after work is done + client->setRemoveDevice( false ); // default, test side-effects + client->setDiscoveryPolicy( DiscoveryPolicy::PAUSE_CONNECTED_UNTIL_DISCONNECTED ); test8x_fullCycle(suffix, - protocolSessionCount, max_connections_per_session, expSuccess, + max_connections_per_session, expSuccess, server_client_order, server, secLevelServer, serverExpPairing, client, secLevelClient, clientExpPairing); |