mike dooley | e952998 | 2018-10-17 08:06:10 +0200 | [diff] [blame] | 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 "SoundTriggerHidlHalTest" |
| 18 | #include <stdlib.h> |
| 19 | #include <time.h> |
| 20 | |
| 21 | #include <condition_variable> |
| 22 | #include <mutex> |
| 23 | |
| 24 | #include <android/log.h> |
| 25 | #include <cutils/native_handle.h> |
nelsonli | 4aa11b1 | 2019-11-12 14:47:12 +0800 | [diff] [blame] | 26 | #include <gtest/gtest.h> |
| 27 | #include <hidl/GtestPrinter.h> |
| 28 | #include <hidl/ServiceManagement.h> |
mike dooley | e952998 | 2018-10-17 08:06:10 +0200 | [diff] [blame] | 29 | #include <log/log.h> |
| 30 | |
| 31 | #include <android/hardware/audio/common/2.0/types.h> |
| 32 | #include <android/hardware/soundtrigger/2.0/ISoundTriggerHw.h> |
| 33 | #include <android/hardware/soundtrigger/2.2/ISoundTriggerHw.h> |
| 34 | |
mike dooley | e952998 | 2018-10-17 08:06:10 +0200 | [diff] [blame] | 35 | using ::android::sp; |
| 36 | using ::android::hardware::Return; |
| 37 | using ::android::hardware::soundtrigger::V2_0::ISoundTriggerHwCallback; |
| 38 | using ::android::hardware::soundtrigger::V2_0::SoundModelHandle; |
| 39 | using ::android::hardware::soundtrigger::V2_2::ISoundTriggerHw; |
| 40 | |
mike dooley | e952998 | 2018-10-17 08:06:10 +0200 | [diff] [blame] | 41 | // The main test class for Sound Trigger HIDL HAL. |
nelsonli | 4aa11b1 | 2019-11-12 14:47:12 +0800 | [diff] [blame] | 42 | class SoundTriggerHidlTest : public ::testing::TestWithParam<std::string> { |
mike dooley | e952998 | 2018-10-17 08:06:10 +0200 | [diff] [blame] | 43 | public: |
| 44 | void SetUp() override { |
nelsonli | 4aa11b1 | 2019-11-12 14:47:12 +0800 | [diff] [blame] | 45 | mSoundTriggerHal = ISoundTriggerHw::getService(GetParam()); |
mike dooley | e952998 | 2018-10-17 08:06:10 +0200 | [diff] [blame] | 46 | ASSERT_NE(nullptr, mSoundTriggerHal.get()); |
| 47 | } |
| 48 | |
| 49 | static void SetUpTestCase() { srand(1234); } |
| 50 | |
| 51 | void TearDown() override {} |
| 52 | |
| 53 | protected: |
| 54 | sp<ISoundTriggerHw> mSoundTriggerHal; |
| 55 | }; |
| 56 | |
| 57 | /** |
| 58 | * Test ISoundTriggerHw::getModelState() method |
| 59 | * |
| 60 | * Verifies that: |
mike dooley | 74a792e | 2018-11-07 15:51:56 +0100 | [diff] [blame] | 61 | * - the implementation returns -ENOSYS with invalid model handle |
mike dooley | e952998 | 2018-10-17 08:06:10 +0200 | [diff] [blame] | 62 | * |
| 63 | */ |
nelsonli | 4aa11b1 | 2019-11-12 14:47:12 +0800 | [diff] [blame] | 64 | TEST_P(SoundTriggerHidlTest, GetModelStateInvalidModel) { |
mike dooley | e952998 | 2018-10-17 08:06:10 +0200 | [diff] [blame] | 65 | SoundModelHandle handle = 0; |
mike dooley | 74a792e | 2018-11-07 15:51:56 +0100 | [diff] [blame] | 66 | Return<int32_t> hidlReturn = mSoundTriggerHal->getModelState(handle); |
mike dooley | e952998 | 2018-10-17 08:06:10 +0200 | [diff] [blame] | 67 | EXPECT_TRUE(hidlReturn.isOk()); |
mike dooley | 74a792e | 2018-11-07 15:51:56 +0100 | [diff] [blame] | 68 | EXPECT_EQ(-ENOSYS, hidlReturn); |
mike dooley | e952998 | 2018-10-17 08:06:10 +0200 | [diff] [blame] | 69 | } |
Dan Shi | ba4d532 | 2020-07-28 13:09:30 -0700 | [diff] [blame] | 70 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SoundTriggerHidlTest); |
nelsonli | 4aa11b1 | 2019-11-12 14:47:12 +0800 | [diff] [blame] | 71 | INSTANTIATE_TEST_SUITE_P( |
| 72 | PerInstance, SoundTriggerHidlTest, |
| 73 | testing::ValuesIn(android::hardware::getAllHalInstanceNames(ISoundTriggerHw::descriptor)), |
| 74 | android::hardware::PrintInstanceNameToString); |