blob: 13d70058e1a46925a954ce33c1dd32561956d264 [file] [log] [blame]
Ytai Ben-Tsvia2cd51a2021-01-25 16:56:25 -08001/*
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
27using ::android::sp;
28using ::android::hardware::Return;
29using ::android::hardware::Status;
30using ::android::hardware::soundtrigger::V2_4::ISoundTriggerHw;
31using ::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 */
38class SoundTriggerHidlTest : public testing::TestWithParam<std::string> {
39public:
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
47protected:
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 */
57TEST_P(SoundTriggerHidlTest, ServiceIsInstantiated) {}
58
59class 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 */
72TEST_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
79GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SoundTriggerHidlTest);
80
81INSTANTIATE_TEST_SUITE_P(
82 PerInstance, SoundTriggerHidlTest,
83 testing::ValuesIn(android::hardware::getAllHalInstanceNames(ISoundTriggerHw::descriptor)),
84 android::hardware::PrintInstanceNameToString);