Nicholas Ambur | 1e90019 | 2019-10-01 13:11:26 -0700 | [diff] [blame] | 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; |
Nicholas Ambur | cb49463 | 2019-12-08 21:52:36 -0800 | [diff] [blame] | 29 | using ::android::hardware::soundtrigger::V2_0::RecognitionMode; |
Nicholas Ambur | 539cbb7 | 2019-12-16 11:31:13 -0800 | [diff] [blame] | 30 | using ::android::hardware::soundtrigger::V2_3::AudioCapabilities; |
Nicholas Ambur | 1e90019 | 2019-10-01 13:11:26 -0700 | [diff] [blame] | 31 | using ::android::hardware::soundtrigger::V2_3::ISoundTriggerHw; |
Nicholas Ambur | cb49463 | 2019-12-08 21:52:36 -0800 | [diff] [blame] | 32 | using ::android::hardware::soundtrigger::V2_3::Properties; |
Nicholas Ambur | 1e90019 | 2019-10-01 13:11:26 -0700 | [diff] [blame] | 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: |
| 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 | */ |
| 57 | TEST_P(SoundTriggerHidlTest, ServiceIsInstantiated) {} |
| 58 | |
Nicholas Ambur | cb49463 | 2019-12-08 21:52:36 -0800 | [diff] [blame] | 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 | */ |
| 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)); |
Nicholas Ambur | 539cbb7 | 2019-12-16 11:31:13 -0800 | [diff] [blame] | 83 | EXPECT_TRUE(halProperties.audioCapabilities <= |
| 84 | (AudioCapabilities::ECHO_CANCELLATION | AudioCapabilities::NOISE_SUPPRESSION)); |
Nicholas Ambur | cb49463 | 2019-12-08 21:52:36 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Nicholas Ambur | 1e90019 | 2019-10-01 13:11:26 -0700 | [diff] [blame] | 87 | INSTANTIATE_TEST_SUITE_P( |
| 88 | PerInstance, SoundTriggerHidlTest, |
| 89 | testing::ValuesIn(android::hardware::getAllHalInstanceNames(ISoundTriggerHw::descriptor)), |
| 90 | android::hardware::PrintInstanceNameToString); |