Ytai Ben-Tsvi | a2cd51a | 2021-01-25 16:56:25 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2021 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.4/ISoundTriggerHwGlobalCallback.h> |
| 22 | #include <android/hardware/soundtrigger/2.4/ISoundTriggerHw.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::Status; |
| 30 | using ::android::hardware::soundtrigger::V2_4::ISoundTriggerHw; |
| 31 | using ::android::hardware::soundtrigger::V2_4::ISoundTriggerHwGlobalCallback; |
| 32 | |
| 33 | /** |
| 34 | * Test class holding the instance of the SoundTriggerHW service to test. |
| 35 | * The passed parameter is the registered name of the implementing service |
| 36 | * supplied by INSTANTIATE_TEST_SUITE_P() call. |
| 37 | */ |
| 38 | class SoundTriggerHidlTest : public testing::TestWithParam<std::string> { |
| 39 | public: |
| 40 | void SetUp() override { |
| 41 | mSoundtrigger = ISoundTriggerHw::getService(GetParam()); |
| 42 | |
| 43 | ASSERT_NE(mSoundtrigger, nullptr); |
| 44 | LOG(INFO) << "Test is remote " << mSoundtrigger->isRemote(); |
| 45 | } |
| 46 | |
| 47 | protected: |
| 48 | sp<ISoundTriggerHw> mSoundtrigger; |
| 49 | }; |
| 50 | |
| 51 | /** |
| 52 | * Empty test is in place to ensure service is initialized. |
| 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 | |
| 59 | class GlobalCallback : public ISoundTriggerHwGlobalCallback { |
| 60 | Return<void> onResourcesAvailable() override { |
| 61 | return Status::ok(); |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | /** |
| 66 | * Test ISoundTriggerHw::registerGlobalCallback method |
| 67 | * |
| 68 | * Verifies that: |
| 69 | * - the implementation implements the method |
| 70 | * - the method returns no error |
| 71 | */ |
| 72 | TEST_P(SoundTriggerHidlTest, RegisterGlobalCallback) { |
| 73 | Return<void> hidlReturn; |
| 74 | sp<ISoundTriggerHwGlobalCallback> callback = new GlobalCallback(); |
| 75 | hidlReturn = mSoundtrigger->registerGlobalCallback(callback); |
| 76 | EXPECT_TRUE(hidlReturn.isOk()); |
| 77 | } |
| 78 | |
| 79 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SoundTriggerHidlTest); |
| 80 | |
| 81 | INSTANTIATE_TEST_SUITE_P( |
| 82 | PerInstance, SoundTriggerHidlTest, |
| 83 | testing::ValuesIn(android::hardware::getAllHalInstanceNames(ISoundTriggerHw::descriptor)), |
| 84 | android::hardware::PrintInstanceNameToString); |