1 /*
2 * Copyright (C) 2019 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 "SoundTriggerHidlHalTest"
18
19 #include <android-base/logging.h>
20 #include <android/hardware/audio/common/2.0/types.h>
21 #include <android/hardware/soundtrigger/2.3/ISoundTriggerHw.h>
22 #include <android/hardware/soundtrigger/2.3/types.h>
23 #include <gtest/gtest.h>
24 #include <hidl/GtestPrinter.h>
25 #include <hidl/ServiceManagement.h>
26
27 using ::android::sp;
28 using ::android::hardware::Return;
29 using ::android::hardware::soundtrigger::V2_0::RecognitionMode;
30 using ::android::hardware::soundtrigger::V2_3::AudioCapabilities;
31 using ::android::hardware::soundtrigger::V2_3::ISoundTriggerHw;
32 using ::android::hardware::soundtrigger::V2_3::Properties;
33
34 /**
35 * Test class holding the instance of the SoundTriggerHW service to test.
36 * The passed parameter is the registered name of the implementing service
37 * supplied by INSTANTIATE_TEST_SUITE_P() call.
38 */
39 class SoundTriggerHidlTest : public testing::TestWithParam<std::string> {
40 public:
SetUp()41 void SetUp() override {
42 soundtrigger = ISoundTriggerHw::getService(GetParam());
43
44 ASSERT_NE(soundtrigger, nullptr);
45 LOG(INFO) << "Test is remote " << soundtrigger->isRemote();
46 }
47
48 sp<ISoundTriggerHw> soundtrigger;
49 };
50
51 /**
52 * Empty test is in place to ensure service is initalized.
53 * Due to the nature of SoundTrigger HAL providing an interface for
54 * proprietary or vendor specific implementations, limited testing on
55 * individual APIs is possible.
56 */
TEST_P(SoundTriggerHidlTest,ServiceIsInstantiated)57 TEST_P(SoundTriggerHidlTest, ServiceIsInstantiated) {}
58
59 /**
60 * Test ISoundTriggerHw::getProperties_2_3 method
61 *
62 * Verifies that:
63 * - the implementation implements the method
64 * - the method returns no error
65 * - the implementation supports at least one sound model and one key phrase
66 * - the implementation supports at least VOICE_TRIGGER recognition mode
67 */
TEST_P(SoundTriggerHidlTest,GetProperties_2_3)68 TEST_P(SoundTriggerHidlTest, GetProperties_2_3) {
69 Properties halProperties;
70 Return<void> hidlReturn;
71 int ret = -ENODEV;
72
73 hidlReturn = soundtrigger->getProperties_2_3([&](int rc, auto res) {
74 ret = rc;
75 halProperties = res;
76 });
77
78 EXPECT_TRUE(hidlReturn.isOk());
79 EXPECT_EQ(0, ret);
80 EXPECT_GT(halProperties.base.maxSoundModels, 0u);
81 EXPECT_GT(halProperties.base.maxKeyPhrases, 0u);
82 EXPECT_NE(0u, (halProperties.base.recognitionModes & (uint32_t)RecognitionMode::VOICE_TRIGGER));
83 EXPECT_TRUE(halProperties.audioCapabilities <=
84 (AudioCapabilities::ECHO_CANCELLATION | AudioCapabilities::NOISE_SUPPRESSION));
85 }
86
87 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SoundTriggerHidlTest);
88 INSTANTIATE_TEST_SUITE_P(
89 PerInstance, SoundTriggerHidlTest,
90 testing::ValuesIn(android::hardware::getAllHalInstanceNames(ISoundTriggerHw::descriptor)),
91 android::hardware::PrintInstanceNameToString);
92