summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAjay Panicker <apanicke@google.com>2015-12-22 13:09:48 -0800
committerAjay Panicker <apanicke@google.com>2015-12-22 18:17:57 -0800
commit4bb7653894eeb12498f7c1b0f6fe54d37515eedf (patch)
tree19d3e6abb2a1b9db17f1eb06f964d456463d5242 /test
parentd0aa6cc53abaf122a2426c20691ccfa025ca7369 (diff)
downloadandroid_system_bt-4bb7653894eeb12498f7c1b0f6fe54d37515eedf.tar.gz
android_system_bt-4bb7653894eeb12498f7c1b0f6fe54d37515eedf.tar.bz2
android_system_bt-4bb7653894eeb12498f7c1b0f6fe54d37515eedf.zip
net_test_bluetooth: Improve set/get name logic
Without this CL semaphore_wait would instantly return due to the fact that enabling the adapter would cause the properties callback to post immediatly. Also prevented the test from returning a false positive if the original device name was the same as the test name. Change-Id: I987efcb9a5ef58209d37d2fc21f3c149fb3e556c
Diffstat (limited to 'test')
-rw-r--r--test/suite/adapter/adapter_unittest.cpp32
-rw-r--r--test/suite/adapter/bluetooth_test.cpp4
-rw-r--r--test/suite/adapter/bluetooth_test.h3
3 files changed, 24 insertions, 15 deletions
diff --git a/test/suite/adapter/adapter_unittest.cpp b/test/suite/adapter/adapter_unittest.cpp
index f39c2473c..14d4de9ec 100644
--- a/test/suite/adapter/adapter_unittest.cpp
+++ b/test/suite/adapter/adapter_unittest.cpp
@@ -62,13 +62,17 @@ TEST_F(BluetoothTest, AdapterRepeatedEnableDisable) {
}
TEST_F(BluetoothTest, AdapterSetGetName) {
- bt_property_t *name = property_new_name("BluetoothTestName");
+ bt_property_t *new_name = property_new_name("BluetoothTestName1");
EXPECT_EQ(bt_interface()->enable(), BT_STATUS_SUCCESS);
semaphore_wait(adapter_state_changed_callback_sem_);
EXPECT_EQ(GetState(), BT_STATE_ON)
<< "Test should be run with Adapter enabled";
+ // Enabling the interface will call the properties callback twice before
+ // ever reaching this point.
+ ClearSemaphore(adapter_properties_callback_sem_);
+
EXPECT_EQ(bt_interface()->get_adapter_property(BT_PROPERTY_BDNAME),
BT_STATUS_SUCCESS);
semaphore_wait(adapter_properties_callback_sem_);
@@ -76,36 +80,34 @@ TEST_F(BluetoothTest, AdapterSetGetName) {
<< "Expected at least one adapter property to change";
bt_property_t *old_name = GetProperty(BT_PROPERTY_BDNAME);
EXPECT_NE(old_name, nullptr);
- EXPECT_FALSE(property_equals(name, old_name))
- << "Current name of the device matches test name. "
- << "Please change the device name for this test.";
+ if (property_equals(old_name, new_name)) {
+ property_free(new_name);
+ new_name = property_new_name("BluetoothTestName2");
+ }
- EXPECT_EQ(bt_interface()->set_adapter_property(name), BT_STATUS_SUCCESS);
+ EXPECT_EQ(bt_interface()->set_adapter_property(new_name), BT_STATUS_SUCCESS);
semaphore_wait(adapter_properties_callback_sem_);
EXPECT_GT(GetPropertiesChangedCount(), 0)
<< "Expected at least one adapter property to change";
EXPECT_TRUE(GetProperty(BT_PROPERTY_BDNAME))
<< "The Bluetooth name property did not change.";
- EXPECT_TRUE(property_equals(GetProperty(BT_PROPERTY_BDNAME), name))
- << "Bluetooth name '"
+ EXPECT_TRUE(property_equals(GetProperty(BT_PROPERTY_BDNAME), new_name))
+ << "Bluetooth name "
<< property_as_name(GetProperty(BT_PROPERTY_BDNAME))->name
- << "' does not match test value " << name;
+ << " does not match test value " << property_as_name(new_name)->name;
+
EXPECT_EQ(bt_interface()->set_adapter_property(old_name), BT_STATUS_SUCCESS);
semaphore_wait(adapter_properties_callback_sem_);
- EXPECT_GT(GetPropertiesChangedCount(), 0)
- << "Expected at least one adapter property";
- EXPECT_TRUE(GetProperty(BT_PROPERTY_BDNAME))
- << "The Bluetooth name property did not change.";
EXPECT_TRUE(property_equals(GetProperty(BT_PROPERTY_BDNAME), old_name))
- << "Bluetooth name '"
+ << "Bluetooth name "
<< property_as_name(GetProperty(BT_PROPERTY_BDNAME))->name
- << "' does not match test value " << old_name;
+ << " does not match original name" << property_as_name(old_name)->name;
EXPECT_EQ(bt_interface()->disable(), BT_STATUS_SUCCESS);
semaphore_wait(adapter_state_changed_callback_sem_);
EXPECT_EQ(GetState(), BT_STATE_OFF) << "Adapter did not turn off.";
- property_free(name);
+ property_free(new_name);
}
TEST_F(BluetoothTest, AdapterStartDiscovery) {
diff --git a/test/suite/adapter/bluetooth_test.cpp b/test/suite/adapter/bluetooth_test.cpp
index 1046d75fd..91229db6e 100644
--- a/test/suite/adapter/bluetooth_test.cpp
+++ b/test/suite/adapter/bluetooth_test.cpp
@@ -66,6 +66,10 @@ void BluetoothTest::TearDown() {
ASSERT_FALSE(bt_hal_interface->IsInitialized());
}
+void BluetoothTest::ClearSemaphore(semaphore_t* sem) {
+ while (semaphore_try_wait(sem));
+}
+
const bt_interface_t* BluetoothTest::bt_interface() {
return bt_interface_;
}
diff --git a/test/suite/adapter/bluetooth_test.h b/test/suite/adapter/bluetooth_test.h
index 1b02c1360..4871d25ec 100644
--- a/test/suite/adapter/bluetooth_test.h
+++ b/test/suite/adapter/bluetooth_test.h
@@ -68,6 +68,9 @@ class BluetoothTest : public ::testing::Test,
// Get the current Bond State
bt_bond_state_t GetBondState();
+ // Reset a semaphores count to 0
+ void ClearSemaphore(semaphore_t* sem);
+
// SetUp initializes the Bluetooth interface and registers the callbacks
// before running every test
void SetUp() override;