From 0daa164e59d2206d975a7a01e11c3b46cc87ae5e Mon Sep 17 00:00:00 2001 From: Myles Watson Date: Thu, 26 Jan 2023 15:58:28 -0800 Subject: [PATCH] VtsHalBluetooth: Add test for double init Bug: 266221125 Test: atest VtsHalBluetoothTargetTest Change-Id: Ic9c0abd27171e210367c2224f8a97991f4088285 --- .../hardware/bluetooth/IBluetoothHci.aidl | 3 ++ .../bluetooth/IBluetoothHciCallbacks.aidl | 2 + .../aidl/vts/VtsHalBluetoothTargetTest.cpp | 42 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/bluetooth/aidl/android/hardware/bluetooth/IBluetoothHci.aidl b/bluetooth/aidl/android/hardware/bluetooth/IBluetoothHci.aidl index db12986b50..ff1f7358d0 100644 --- a/bluetooth/aidl/android/hardware/bluetooth/IBluetoothHci.aidl +++ b/bluetooth/aidl/android/hardware/bluetooth/IBluetoothHci.aidl @@ -35,6 +35,9 @@ interface IBluetoothHci { /** * Initialize the Bluetooth interface and set the callbacks. + * Only one client can initialize the interface at a time. When a + * call to initialize fails, the Status parameter of the callback + * will indicate the reason for the failure. */ void initialize(in IBluetoothHciCallbacks callback); diff --git a/bluetooth/aidl/android/hardware/bluetooth/IBluetoothHciCallbacks.aidl b/bluetooth/aidl/android/hardware/bluetooth/IBluetoothHciCallbacks.aidl index 000333e2ca..0148c6fc4e 100644 --- a/bluetooth/aidl/android/hardware/bluetooth/IBluetoothHciCallbacks.aidl +++ b/bluetooth/aidl/android/hardware/bluetooth/IBluetoothHciCallbacks.aidl @@ -39,6 +39,8 @@ interface IBluetoothHciCallbacks { /** * Invoked when the Bluetooth controller initialization has been * completed. + * @param status contains a return code indicating success, or the + * reason the initialization failed. */ void initializationComplete(in Status status); diff --git a/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp b/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp index 7b9e211d5b..3704c3dcda 100644 --- a/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp +++ b/bluetooth/aidl/vts/VtsHalBluetoothTargetTest.cpp @@ -867,6 +867,48 @@ TEST_P(BluetoothAidlTest, SetLeEventMask) { wait_for_command_complete_event(set_event_mask); } +// Call initialize twice, second one should fail. +TEST_P(BluetoothAidlTest, CallInitializeTwice) { + class SecondCb + : public aidl::android::hardware::bluetooth::BnBluetoothHciCallbacks { + public: + ndk::ScopedAStatus initializationComplete(Status status) { + EXPECT_EQ(status, Status::ALREADY_INITIALIZED); + init_promise.set_value(); + return ScopedAStatus::ok(); + }; + + ndk::ScopedAStatus hciEventReceived(const std::vector& /*event*/) { + ADD_FAILURE(); + return ScopedAStatus::ok(); + }; + + ndk::ScopedAStatus aclDataReceived(const std::vector& /*data*/) { + ADD_FAILURE(); + return ScopedAStatus::ok(); + }; + + ndk::ScopedAStatus scoDataReceived(const std::vector& /*data*/) { + ADD_FAILURE(); + return ScopedAStatus::ok(); + }; + + ndk::ScopedAStatus isoDataReceived(const std::vector& /*data*/) { + ADD_FAILURE(); + return ScopedAStatus::ok(); + }; + std::promise init_promise; + }; + + std::shared_ptr second_cb = ndk::SharedRefBase::make(); + ASSERT_NE(second_cb, nullptr); + + auto future = second_cb->init_promise.get_future(); + ASSERT_TRUE(hci->initialize(second_cb).isOk()); + auto status = future.wait_for(std::chrono::seconds(1)); + ASSERT_EQ(status, std::future_status::ready); +} + GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BluetoothAidlTest); INSTANTIATE_TEST_SUITE_P(PerInstance, BluetoothAidlTest, testing::ValuesIn(android::getAidlHalInstanceNames(