diff options
-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 | ||||
-rw-r--r-- | trial/java/trial/org/direct_bt/DBTClient01.java | 35 | ||||
-rw-r--r-- | trial/java/trial/org/direct_bt/DBTClientServer1x.java | 38 | ||||
-rw-r--r-- | trial/java/trial/org/direct_bt/DBTClientTest.java | 4 | ||||
-rw-r--r-- | trial/java/trial/org/direct_bt/DBTServer01.java | 19 | ||||
-rw-r--r-- | trial/java/trial/org/direct_bt/TestDBTClientServer00.java | 2 | ||||
-rw-r--r-- | trial/java/trial/org/direct_bt/TestDBTProvokeClientServer_i470.java | 47 |
11 files changed, 145 insertions, 105 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); diff --git a/trial/java/trial/org/direct_bt/DBTClient01.java b/trial/java/trial/org/direct_bt/DBTClient01.java index c10d6450..473c5fa3 100644 --- a/trial/java/trial/org/direct_bt/DBTClient01.java +++ b/trial/java/trial/org/direct_bt/DBTClient01.java @@ -81,9 +81,9 @@ public class DBTClient01 implements DBTClientTest { private BTMode btMode = BTMode.DUAL; private BTAdapter clientAdapter = null; - private boolean KEEP_CONNECTED = false; + private boolean do_disconnect = true; - private boolean REMOVE_DEVICE = false; + private boolean do_remove_device = false; private DiscoveryPolicy discoveryPolicy = DiscoveryPolicy.PAUSE_CONNECTED_UNTIL_READY; // default value @@ -96,13 +96,16 @@ public class DBTClient01 implements DBTClientTest { private final AtomicInteger completedMeasurementsTotal = new AtomicInteger(0); private final AtomicInteger completedMeasurementsSuccess = new AtomicInteger(0); - private final boolean do_disconnect; + private final boolean do_disconnect_randomly; - public DBTClient01(final String adapterName, final EUI48 useAdapter, final BTMode btMode, final boolean do_disconnect) { + public DBTClient01(final String adapterName, final EUI48 useAdapter, final BTMode btMode, final boolean do_disconnect_randomly) { this.adapterName = adapterName; this.useAdapter = useAdapter; this.btMode = btMode; - this.do_disconnect = do_disconnect; + this.do_disconnect_randomly = do_disconnect_randomly; + } + public DBTClient01(final String adapterName, final EUI48 useAdapter, final BTMode btMode) { + this(adapterName, useAdapter, btMode, false /* do_disconnect_randomly */); } @Override @@ -141,12 +144,12 @@ public class DBTClient01 implements DBTClientTest { discoveryPolicy = v; } @Override - public void setKeepConnected(final boolean v) { - KEEP_CONNECTED = v; + public void setDisconnectDeviceed(final boolean v) { + do_disconnect = v; } @Override public void setRemoveDevice(final boolean v) { - REMOVE_DEVICE = v; + do_remove_device = v; } static void executeOffThread(final Runnable runobj, final String threadName, final boolean detach) { @@ -172,9 +175,9 @@ public class DBTClient01 implements DBTClientTest { final AdapterSettings newmask, final AdapterSettings changedmask, final long timestamp) { final boolean initialSetting = oldmask.isEmpty(); if( initialSetting ) { - PrintUtil.println(System.err, "****** Client SETTINGS: "+oldmask+" -> "+newmask+", initial "+changedmask); + PrintUtil.println(System.err, "****** Client SETTINGS_INITIAL: "+oldmask+" -> "+newmask+", changed "+changedmask); } else { - PrintUtil.println(System.err, "****** Client SETTINGS: "+oldmask+" -> "+newmask+", changed "+changedmask); + PrintUtil.println(System.err, "****** Client SETTINGS_CHANGED: "+oldmask+" -> "+newmask+", changed "+changedmask); } PrintUtil.println(System.err, "Client Status Adapter:"); PrintUtil.println(System.err, adapter.toString()); @@ -268,7 +271,7 @@ public class DBTClient01 implements DBTClientTest { } } - private void disconnectDevice(final BTDevice device) { + private void disconnectDeviceRandomly(final BTDevice device) { // sleep range: 100 - 1500 ms final int sleep_min = 100; final int sleep_max = 1500; @@ -296,8 +299,8 @@ public class DBTClient01 implements DBTClientTest { "DBT-Process1-"+device.getAddressAndType(), true /* detach */); // processReadyDevice(device); // AdapterStatusListener::deviceReady() explicitly allows prolonged and complex code execution! - if( do_disconnect ) { - executeOffThread( () -> { disconnectDevice(device); }, + if( do_disconnect_randomly ) { + executeOffThread( () -> { disconnectDeviceRandomly(device); }, "DBT-Disconnect-"+device.getAddressAndType(), true /* detach */); } } @@ -599,8 +602,8 @@ public class DBTClient01 implements DBTClientTest { PrintUtil.println(System.err, "****** Client Processing Ready Device: End-2: Success " + success + " on " + device.toString()); device.removeAllCharListener(); - if( !KEEP_CONNECTED ) { - if( REMOVE_DEVICE ) { + if( do_disconnect ) { + if( do_remove_device ) { device.remove(); } else { device.disconnect(); @@ -625,7 +628,7 @@ public class DBTClient01 implements DBTClientTest { private void removeDevice(final BTDevice device) { PrintUtil.println(System.err, "****** Client Remove Device: removing: "+device.getAddressAndType()); - if( REMOVE_DEVICE ) { + if( do_remove_device ) { device.remove(); } } diff --git a/trial/java/trial/org/direct_bt/DBTClientServer1x.java b/trial/java/trial/org/direct_bt/DBTClientServer1x.java index 48a89caf..3dfa48b2 100644 --- a/trial/java/trial/org/direct_bt/DBTClientServer1x.java +++ b/trial/java/trial/org/direct_bt/DBTClientServer1x.java @@ -30,6 +30,7 @@ import java.util.List; import org.direct_bt.BTMode; import org.direct_bt.BTSecurityLevel; +import org.direct_bt.AdapterSettings; import org.direct_bt.AdapterStatusListener; import org.direct_bt.BTAdapter; import org.direct_bt.BTDevice; @@ -41,6 +42,7 @@ import org.direct_bt.BTSecurityRegistry; import org.direct_bt.DiscoveryPolicy; import org.direct_bt.EIRDataTypeSet; import org.direct_bt.EInfoReport; +import org.direct_bt.HCIStatusCode; import org.direct_bt.PairingMode; import org.direct_bt.SMPKeyBin; import org.jau.io.PrintUtil; @@ -73,21 +75,30 @@ public abstract class DBTClientServer1x extends BaseDBTClientServer { final boolean serverSC, final BTSecurityLevel secLevelServer, final ExpectedPairing serverExpPairing, final BTSecurityLevel secLevelClient, final ExpectedPairing clientExpPairing) { - final DBTServer01 server = new DBTServer01("S-"+suffix, EUI48.ALL_DEVICE, BTMode.DUAL, serverSC, secLevelServer, false /* do_disconnect */); - final DBTClient01 client = new DBTClient01("C-"+suffix, EUI48.ALL_DEVICE, BTMode.DUAL, false /* do_disconnect */); + final DBTServer01 server = new DBTServer01("S-"+suffix, EUI48.ALL_DEVICE, BTMode.DUAL, serverSC, secLevelServer); + final DBTClient01 client = new DBTClient01("C-"+suffix, EUI48.ALL_DEVICE, BTMode.DUAL); + + server.setProtocolSessionsLeft( protocolSessionCount ); + + client.setProtocolSessionsLeft( protocolSessionCount ); + client.setDisconnectDeviceed( true ); // default, auto-disconnect after work is done + client.setRemoveDevice( false ); // default, test side-effects + client.setDiscoveryPolicy( DiscoveryPolicy.PAUSE_CONNECTED_UNTIL_DISCONNECTED ); + test8x_fullCycle(timeout_value, suffix, - protocolSessionCount, DBTConstants.max_connections_per_session, true /* expSuccess */, - server_client_order, - server, secLevelServer, serverExpPairing, - client, secLevelClient, clientExpPairing); + DBTConstants.max_connections_per_session, true /* expSuccess */, server_client_order, + server, + secLevelServer, serverExpPairing, client, + secLevelClient, clientExpPairing); } final void test8x_fullCycle(final long timeout_value, final String suffix, - final int protocolSessionCount, final int max_connections_per_session, final boolean expSuccess, - final boolean server_client_order, - final DBTServerTest server, final BTSecurityLevel secLevelServer, final ExpectedPairing serverExpPairing, - final DBTClientTest client, final BTSecurityLevel secLevelClient, final ExpectedPairing clientExpPairing) + final int max_connections_per_session, final boolean expSuccess, final boolean server_client_order, + final DBTServerTest server, + final BTSecurityLevel secLevelServer, final ExpectedPairing serverExpPairing, final DBTClientTest client, + final BTSecurityLevel secLevelClient, final ExpectedPairing clientExpPairing) { + final int protocolSessionCount = Math.min(server.getProtocolSessionsLeft(), client.getProtocolSessionsLeft()); final long t0 = Clock.currentTimeMillis(); BTManager manager = null; @@ -108,13 +119,6 @@ public abstract class DBTClientServer1x extends BaseDBTClientServer { Assert.assertTrue("Adapter count not >= 2 but "+adapters.size(), 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 ); - final DBTEndpoint.ChangedAdapterSetListener myChangedAdapterSetListener = DBTEndpoint.initChangedAdapterSetListener(manager, server_client_order ? Arrays.asList(server, client) : Arrays.asList(client, server)); diff --git a/trial/java/trial/org/direct_bt/DBTClientTest.java b/trial/java/trial/org/direct_bt/DBTClientTest.java index 8b5a33a0..d7171277 100644 --- a/trial/java/trial/org/direct_bt/DBTClientTest.java +++ b/trial/java/trial/org/direct_bt/DBTClientTest.java @@ -41,9 +41,9 @@ public interface DBTClientTest extends DBTEndpoint { /** * Set disconnect after processing. * - * Default is `false`. + * Default is `true`. */ - void setKeepConnected(final boolean v); + void setDisconnectDeviceed(final boolean v); /** * Set remove device when disconnecting. diff --git a/trial/java/trial/org/direct_bt/DBTServer01.java b/trial/java/trial/org/direct_bt/DBTServer01.java index 917c8142..b17c6465 100644 --- a/trial/java/trial/org/direct_bt/DBTServer01.java +++ b/trial/java/trial/org/direct_bt/DBTServer01.java @@ -89,18 +89,21 @@ public class DBTServer01 implements DBTServerTest { private final AtomicInteger servedProtocolSessionsSuccess = new AtomicInteger(0); private final AtomicInteger servingProtocolSessionsLeft = new AtomicInteger(1); - private final boolean do_disconnect; + private final boolean do_disconnect_randomly; - public DBTServer01(final String adapterName, final EUI48 useAdapter, final BTMode btMode, final boolean use_SC, final BTSecurityLevel adapterSecurityLevel, final boolean do_disconnect) { + public DBTServer01(final String adapterName, final EUI48 useAdapter, final BTMode btMode, final boolean use_SC, final BTSecurityLevel adapterSecurityLevel, final boolean do_disconnect_randomly) { 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 ); } + public DBTServer01(final String adapterName, final EUI48 useAdapter, final BTMode btMode, final boolean use_SC, final BTSecurityLevel adapterSecurityLevel) { + this(adapterName, useAdapter, btMode, use_SC, adapterSecurityLevel, false /* do_disconnect_randomly */); + } @Override public String getName() { return adapterName; } @@ -269,9 +272,9 @@ public class DBTServer01 implements DBTServerTest { final AdapterSettings newmask, final AdapterSettings changedmask, final long timestamp) { final boolean initialSetting = oldmask.isEmpty(); if( initialSetting ) { - PrintUtil.println(System.err, "****** Server SETTINGS: "+oldmask+" -> "+newmask+", initial "+changedmask); + PrintUtil.println(System.err, "****** Server SETTINGS_INITIAL: "+oldmask+" -> "+newmask+", changed "+changedmask); } else { - PrintUtil.println(System.err, "****** Server SETTINGS: "+oldmask+" -> "+newmask+", changed "+changedmask); + PrintUtil.println(System.err, "****** Server SETTINGS_CHANGED: "+oldmask+" -> "+newmask+", changed "+changedmask); } PrintUtil.println(System.err, "Server Status Adapter:"); PrintUtil.println(System.err, adapter.toString()); @@ -467,7 +470,7 @@ public class DBTServer01 implements DBTServerTest { } } - private void disconnectDevice() { + private void disconnectDeviceRandomly() { // sleep range: 100 - 1500 ms final int sleep_min = 100; final int sleep_max = 1500; @@ -534,8 +537,8 @@ public class DBTServer01 implements DBTServerTest { PrintUtil.fprintf_td(System.err, "****** Server GATT::mtuChanged(match %b, served %d, left %d): %d -> %d, %s\n", match, servedProtocolSessionsTotal.get(), servingProtocolSessionsLeft.get(), match ? usedMTU_old : 0, mtu, device.toString()); - if( do_disconnect ) { - executeOffThread( () -> { disconnectDevice(); }, "GattServer-DisconnectDevice", true /* detach */); + if( do_disconnect_randomly ) { + executeOffThread( () -> { disconnectDeviceRandomly(); }, "GattServer-DisconnectDevice", true /* detach */); } } diff --git a/trial/java/trial/org/direct_bt/TestDBTClientServer00.java b/trial/java/trial/org/direct_bt/TestDBTClientServer00.java index a945d038..8c8b3e9e 100644 --- a/trial/java/trial/org/direct_bt/TestDBTClientServer00.java +++ b/trial/java/trial/org/direct_bt/TestDBTClientServer00.java @@ -107,7 +107,7 @@ public class TestDBTClientServer00 extends BaseDBTClientServer { } final String serverName = "TestDBTCS00-S-T10"; - final DBTServer01 server = new DBTServer01(serverName, EUI48.ALL_DEVICE, BTMode.DUAL, true /* SC */, BTSecurityLevel.NONE, false /* do_disconnect */); + final DBTServer01 server = new DBTServer01(serverName, EUI48.ALL_DEVICE, BTMode.DUAL, true /* SC */, BTSecurityLevel.NONE); server.setProtocolSessionsLeft(1); final DBTEndpoint.ChangedAdapterSetListener myChangedAdapterSetListener = diff --git a/trial/java/trial/org/direct_bt/TestDBTProvokeClientServer_i470.java b/trial/java/trial/org/direct_bt/TestDBTProvokeClientServer_i470.java index b2e8e1c8..cd5e64c7 100644 --- a/trial/java/trial/org/direct_bt/TestDBTProvokeClientServer_i470.java +++ b/trial/java/trial/org/direct_bt/TestDBTProvokeClientServer_i470.java @@ -26,6 +26,7 @@ package trial.org.direct_bt; import org.direct_bt.BTMode; import org.direct_bt.BTSecurityLevel; +import org.direct_bt.DiscoveryPolicy; import org.jau.net.EUI48; import org.junit.FixMethodOrder; import org.junit.Test; @@ -55,17 +56,24 @@ public class TestDBTProvokeClientServer_i470 extends DBTClientServer1x { final boolean server_client_order = true; final ExpectedPairing serverExpPairing = ExpectedPairing.DONT_CARE; final ExpectedPairing clientExpPairing = ExpectedPairing.DONT_CARE; - final boolean client_do_disconnect = true; - final boolean server_do_disconnect = false; + final boolean client_do_disconnect_randomly = true; + final boolean server_do_disconnect_randomly = false; - final DBTServerTest server = new DBTServer01("S-"+suffix, EUI48.ALL_DEVICE, BTMode.DUAL, serverSC, BTSecurityLevel.ENC_ONLY, server_do_disconnect); - final DBTClientTest client = new DBTClient01("C-"+suffix, EUI48.ALL_DEVICE, BTMode.DUAL, client_do_disconnect); + final DBTServerTest server = new DBTServer01("S-"+suffix, EUI48.ALL_DEVICE, BTMode.DUAL, serverSC, BTSecurityLevel.ENC_ONLY, server_do_disconnect_randomly); + final DBTClientTest client = new DBTClient01("C-"+suffix, EUI48.ALL_DEVICE, BTMode.DUAL, client_do_disconnect_randomly); + + server.setProtocolSessionsLeft( protocolSessionCount ); + + client.setProtocolSessionsLeft( protocolSessionCount ); + client.setDisconnectDeviceed( true ); // default, auto-disconnect after work is done + client.setRemoveDevice( false ); // default, test side-effects + client.setDiscoveryPolicy( DiscoveryPolicy.PAUSE_CONNECTED_UNTIL_DISCONNECTED ); test8x_fullCycle(10000, suffix, - protocolSessionCount, max_connections_per_session, expSuccess, - server_client_order, - server, BTSecurityLevel.ENC_ONLY, serverExpPairing, - client, BTSecurityLevel.ENC_ONLY, clientExpPairing); + max_connections_per_session, expSuccess, server_client_order, + server, + BTSecurityLevel.ENC_ONLY, serverExpPairing, client, + BTSecurityLevel.ENC_ONLY, clientExpPairing); } @Test(timeout = 10000) @@ -79,17 +87,24 @@ public class TestDBTProvokeClientServer_i470 extends DBTClientServer1x { final boolean server_client_order = true; final ExpectedPairing serverExpPairing = ExpectedPairing.DONT_CARE; final ExpectedPairing clientExpPairing = ExpectedPairing.DONT_CARE; - final boolean client_do_disconnect = false; - final boolean server_do_disconnect = true; + final boolean client_do_disconnect_randomly = false; + final boolean server_do_disconnect_randomly = true; + + final DBTServerTest server = new DBTServer01("S-"+suffix, EUI48.ALL_DEVICE, BTMode.DUAL, serverSC, BTSecurityLevel.ENC_ONLY, server_do_disconnect_randomly); + final DBTClientTest client = new DBTClient01("C-"+suffix, EUI48.ALL_DEVICE, BTMode.DUAL, client_do_disconnect_randomly); + + server.setProtocolSessionsLeft( protocolSessionCount ); - final DBTServerTest server = new DBTServer01("S-"+suffix, EUI48.ALL_DEVICE, BTMode.DUAL, serverSC, BTSecurityLevel.ENC_ONLY, server_do_disconnect); - final DBTClientTest client = new DBTClient01("C-"+suffix, EUI48.ALL_DEVICE, BTMode.DUAL, client_do_disconnect); + client.setProtocolSessionsLeft( protocolSessionCount ); + client.setDisconnectDeviceed( true ); // default, auto-disconnect after work is done + client.setRemoveDevice( false ); // default, test side-effects + client.setDiscoveryPolicy( DiscoveryPolicy.PAUSE_CONNECTED_UNTIL_DISCONNECTED ); test8x_fullCycle(10000, suffix, - protocolSessionCount, max_connections_per_session, expSuccess, - server_client_order, - server, BTSecurityLevel.ENC_ONLY, serverExpPairing, - client, BTSecurityLevel.ENC_ONLY, clientExpPairing); + max_connections_per_session, expSuccess, server_client_order, + server, + BTSecurityLevel.ENC_ONLY, serverExpPairing, client, + BTSecurityLevel.ENC_ONLY, clientExpPairing); } public static void main(final String args[]) { |