blob: ed38368d8cd74e3f4632f6536a3a336eebb60d78 [file] [log] [blame]
Nicholas Ambur1e900192019-10-01 13:11:26 -07001/*
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
27using ::android::sp;
28using ::android::hardware::Return;
Nicholas Amburcb494632019-12-08 21:52:36 -080029using ::android::hardware::soundtrigger::V2_0::RecognitionMode;
Nicholas Ambur1e900192019-10-01 13:11:26 -070030using ::android::hardware::soundtrigger::V2_3::ISoundTriggerHw;
Nicholas Amburcb494632019-12-08 21:52:36 -080031using ::android::hardware::soundtrigger::V2_3::Properties;
Nicholas Ambur1e900192019-10-01 13:11:26 -070032
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> {
39 public:
40 void SetUp() override {
41 soundtrigger = ISoundTriggerHw::getService(GetParam());
42
43 ASSERT_NE(soundtrigger, nullptr);
44 LOG(INFO) << "Test is remote " << soundtrigger->isRemote();
45 }
46
47 sp<ISoundTriggerHw> soundtrigger;
48};
49
50/**
51 * Empty test is in place to ensure service is initalized.
52 * Due to the nature of SoundTrigger HAL providing an interface for
53 * proprietary or vendor specific implementations, limited testing on
54 * individual APIs is possible.
55 */
56TEST_P(SoundTriggerHidlTest, ServiceIsInstantiated) {}
57
Nicholas Amburcb494632019-12-08 21:52:36 -080058/**
59 * Test ISoundTriggerHw::getProperties_2_3 method
60 *
61 * Verifies that:
62 * - the implementation implements the method
63 * - the method returns no error
64 * - the implementation supports at least one sound model and one key phrase
65 * - the implementation supports at least VOICE_TRIGGER recognition mode
66 */
67TEST_P(SoundTriggerHidlTest, GetProperties_2_3) {
68 Properties halProperties;
69 Return<void> hidlReturn;
70 int ret = -ENODEV;
71
72 hidlReturn = soundtrigger->getProperties_2_3([&](int rc, auto res) {
73 ret = rc;
74 halProperties = res;
75 });
76
77 EXPECT_TRUE(hidlReturn.isOk());
78 EXPECT_EQ(0, ret);
79 EXPECT_GT(halProperties.base.maxSoundModels, 0u);
80 EXPECT_GT(halProperties.base.maxKeyPhrases, 0u);
81 EXPECT_NE(0u, (halProperties.base.recognitionModes & (uint32_t)RecognitionMode::VOICE_TRIGGER));
82}
83
Nicholas Ambur1e900192019-10-01 13:11:26 -070084INSTANTIATE_TEST_SUITE_P(
85 PerInstance, SoundTriggerHidlTest,
86 testing::ValuesIn(android::hardware::getAllHalInstanceNames(ISoundTriggerHw::descriptor)),
87 android::hardware::PrintInstanceNameToString);