blob: 2d147e460662ed45e3095696ec70728ca2b84a3b [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 Ambur539cbb72019-12-16 11:31:13 -080030using ::android::hardware::soundtrigger::V2_3::AudioCapabilities;
Nicholas Ambur1e900192019-10-01 13:11:26 -070031using ::android::hardware::soundtrigger::V2_3::ISoundTriggerHw;
Nicholas Amburcb494632019-12-08 21:52:36 -080032using ::android::hardware::soundtrigger::V2_3::Properties;
Nicholas Ambur1e900192019-10-01 13:11:26 -070033
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 */
39class 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 */
57TEST_P(SoundTriggerHidlTest, ServiceIsInstantiated) {}
58
Nicholas Amburcb494632019-12-08 21:52:36 -080059/**
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 */
68TEST_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 Ambur539cbb72019-12-16 11:31:13 -080083 EXPECT_TRUE(halProperties.audioCapabilities <=
84 (AudioCapabilities::ECHO_CANCELLATION | AudioCapabilities::NOISE_SUPPRESSION));
Nicholas Amburcb494632019-12-08 21:52:36 -080085}
86
Nicholas Ambur1e900192019-10-01 13:11:26 -070087INSTANTIATE_TEST_SUITE_P(
88 PerInstance, SoundTriggerHidlTest,
89 testing::ValuesIn(android::hardware::getAllHalInstanceNames(ISoundTriggerHw::descriptor)),
90 android::hardware::PrintInstanceNameToString);