summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHansong Zhang2018-04-09 14:27:12 -0500
committerHansong Zhang2018-04-11 11:56:09 -0500
commit5b1813f077c6b819910b29c32e31073c9b4d6ddf (patch)
treeb5d3953d6b85740b7b35a11d71acb166b1caf941 /bluetooth/a2dp
parent6acac5a35678dea11f1ad76dbab9fb63d6ebd9c9 (diff)
downloadplatform-hardware-interfaces-5b1813f077c6b819910b29c32e31073c9b4d6ddf.tar.gz
platform-hardware-interfaces-5b1813f077c6b819910b29c32e31073c9b4d6ddf.tar.xz
platform-hardware-interfaces-5b1813f077c6b819910b29c32e31073c9b4d6ddf.zip
VTS for Bluetooth A2DP HAL
Initial VTS commit for the bluetooth.a2dp@1.0 HAL Test: VTS Bug: 74900514 Change-Id: I752abc4878ee6a974ce3a17ad852e941783da022
Diffstat (limited to 'bluetooth/a2dp')
-rw-r--r--bluetooth/a2dp/1.0/vts/functional/Android.bp26
-rw-r--r--bluetooth/a2dp/1.0/vts/functional/VtsHalBluetoothA2dpV1_0TargetTest.cpp126
2 files changed, 152 insertions, 0 deletions
diff --git a/bluetooth/a2dp/1.0/vts/functional/Android.bp b/bluetooth/a2dp/1.0/vts/functional/Android.bp
new file mode 100644
index 00000000..f1ffc459
--- /dev/null
+++ b/bluetooth/a2dp/1.0/vts/functional/Android.bp
@@ -0,0 +1,26 @@
1//
2// Copyright (C) 2018 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17cc_test {
18 name: "VtsHalBluetoothA2dpV1_0TargetTest",
19 defaults: ["VtsHalTargetTestDefaults"],
20 srcs: ["VtsHalBluetoothA2dpV1_0TargetTest.cpp"],
21 static_libs: [
22 "android.hardware.bluetooth@1.0",
23 "android.hardware.bluetooth.a2dp@1.0",
24 "libbluetooth-types",
25 ],
26}
diff --git a/bluetooth/a2dp/1.0/vts/functional/VtsHalBluetoothA2dpV1_0TargetTest.cpp b/bluetooth/a2dp/1.0/vts/functional/VtsHalBluetoothA2dpV1_0TargetTest.cpp
new file mode 100644
index 00000000..1a0342f3
--- /dev/null
+++ b/bluetooth/a2dp/1.0/vts/functional/VtsHalBluetoothA2dpV1_0TargetTest.cpp
@@ -0,0 +1,126 @@
1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "bluetooth_a2dp_hidl_hal_test"
18
19#include <android-base/logging.h>
20#include <android/hardware/bluetooth/a2dp/1.0/IBluetoothAudioHost.h>
21#include <android/hardware/bluetooth/a2dp/1.0/IBluetoothAudioOffload.h>
22#include <hardware/bluetooth.h>
23#include <utils/Log.h>
24
25#include <VtsHalHidlTargetCallbackBase.h>
26#include <VtsHalHidlTargetTestBase.h>
27#include <VtsHalHidlTargetTestEnvBase.h>
28
29using ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost;
30using ::android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload;
31using ::android::hardware::bluetooth::a2dp::V1_0::Status;
32using ::android::hardware::bluetooth::a2dp::V1_0::CodecType;
33using ::android::hardware::bluetooth::a2dp::V1_0::SampleRate;
34using ::android::hardware::bluetooth::a2dp::V1_0::BitsPerSample;
35using ::android::hardware::bluetooth::a2dp::V1_0::ChannelMode;
36using ::android::hardware::bluetooth::a2dp::V1_0::CodecConfiguration;
37using ::android::hardware::Return;
38using ::android::hardware::Void;
39using ::android::sp;
40
41// Test environment for Bluetooth HIDL A2DP HAL.
42class BluetoothA2dpHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
43 public:
44 // get the test environment singleton
45 static BluetoothA2dpHidlEnvironment* Instance() {
46 static BluetoothA2dpHidlEnvironment* instance = new BluetoothA2dpHidlEnvironment;
47 return instance;
48 }
49
50 virtual void registerTestServices() override { registerTestService<IBluetoothAudioOffload>(); }
51
52 private:
53 BluetoothA2dpHidlEnvironment() {}
54};
55
56// The main test class for Bluetooth A2DP HIDL HAL.
57class BluetoothA2dpHidlTest : public ::testing::VtsHalHidlTargetTestBase {
58 public:
59 virtual void SetUp() override {
60 // currently test passthrough mode only
61 audio_offload = ::testing::VtsHalHidlTargetTestBase::getService<IBluetoothAudioOffload>(
62 BluetoothA2dpHidlEnvironment::Instance()->getServiceName<IBluetoothAudioOffload>());
63 ASSERT_NE(audio_offload, nullptr);
64
65 audio_host = new BluetoothAudioHost(*this);
66 ASSERT_NE(audio_host, nullptr);
67
68 codec.codecType = CodecType::AAC;
69 codec.sampleRate = SampleRate::RATE_44100;
70 codec.bitsPerSample = BitsPerSample::BITS_16;
71 codec.channelMode = ChannelMode::STEREO;
72 codec.encodedAudioBitrate = 320000;
73 codec.peerMtu = 1000;
74 }
75
76 virtual void TearDown() override {}
77
78 // A simple test implementation of IBluetoothAudioHost.
79 class BluetoothAudioHost
80 : public ::testing::VtsHalHidlTargetCallbackBase<BluetoothA2dpHidlTest>,
81 public IBluetoothAudioHost {
82 BluetoothA2dpHidlTest& parent_;
83
84 public:
85 BluetoothAudioHost(BluetoothA2dpHidlTest& parent) : parent_(parent){};
86 virtual ~BluetoothAudioHost() = default;
87
88 Return<void> startStream() override {
89 parent_.audio_offload->streamStarted(Status::SUCCESS);
90 return Void();
91 };
92
93 Return<void> suspendStream() override {
94 parent_.audio_offload->streamSuspended(Status::SUCCESS);
95 return Void();
96 };
97
98 Return<void> stopStream() override { return Void(); };
99 };
100
101 // audio_host is for the Audio HAL to send stream start/suspend/stop commands to Bluetooth
102 sp<IBluetoothAudioHost> audio_host;
103 // audio_offload is for the Bluetooth HAL to report session started/ended and handled audio
104 // stream started/suspended
105 sp<IBluetoothAudioOffload> audio_offload;
106 // codec is the currently used codec
107 CodecConfiguration codec;
108};
109
110// Empty test: Initialize()/Close() are called in SetUp()/TearDown().
111TEST_F(BluetoothA2dpHidlTest, InitializeAndClose) {}
112
113// Test start and end session
114TEST_F(BluetoothA2dpHidlTest, StartAndEndSession) {
115 EXPECT_EQ(Status::SUCCESS, audio_offload->startSession(audio_host, codec));
116 audio_offload->endSession();
117}
118
119int main(int argc, char** argv) {
120 ::testing::AddGlobalTestEnvironment(BluetoothA2dpHidlEnvironment::Instance());
121 ::testing::InitGoogleTest(&argc, argv);
122 BluetoothA2dpHidlEnvironment::Instance()->init(&argc, argv);
123 int status = RUN_ALL_TESTS();
124 LOG(INFO) << "Test result = " << status;
125 return status;
126}