blob: a473c3779b4f246ceec2f0118f795437c22a7219 [file] [log] [blame]
mike dooleye9529982018-10-17 08:06:10 +02001/*
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>
26#include <log/log.h>
27
28#include <android/hardware/audio/common/2.0/types.h>
29#include <android/hardware/soundtrigger/2.0/ISoundTriggerHw.h>
30#include <android/hardware/soundtrigger/2.2/ISoundTriggerHw.h>
31
32#include <VtsHalHidlTargetTestBase.h>
33#include <VtsHalHidlTargetTestEnvBase.h>
34
35using ::android::sp;
36using ::android::hardware::Return;
37using ::android::hardware::soundtrigger::V2_0::ISoundTriggerHwCallback;
38using ::android::hardware::soundtrigger::V2_0::SoundModelHandle;
39using ::android::hardware::soundtrigger::V2_2::ISoundTriggerHw;
40
41// Test environment for SoundTrigger HIDL HAL.
42class SoundTriggerHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
43 public:
44 // get the test environment singleton
45 static SoundTriggerHidlEnvironment* Instance() {
46 static SoundTriggerHidlEnvironment* instance = new SoundTriggerHidlEnvironment;
47 return instance;
48 }
49
50 void registerTestServices() override { registerTestService<ISoundTriggerHw>(); }
51
52 private:
53 SoundTriggerHidlEnvironment() {}
54};
55
56// The main test class for Sound Trigger HIDL HAL.
57class SoundTriggerHidlTest : public ::testing::VtsHalHidlTargetTestBase {
58 public:
59 void SetUp() override {
60 mSoundTriggerHal = ::testing::VtsHalHidlTargetTestBase::getService<ISoundTriggerHw>(
61 SoundTriggerHidlEnvironment::Instance()->getServiceName<ISoundTriggerHw>());
62 ASSERT_NE(nullptr, mSoundTriggerHal.get());
63 }
64
65 static void SetUpTestCase() { srand(1234); }
66
67 void TearDown() override {}
68
69 protected:
70 sp<ISoundTriggerHw> mSoundTriggerHal;
71};
72
73/**
74 * Test ISoundTriggerHw::getModelState() method
75 *
76 * Verifies that:
77 * - the implementation returns -EINVAL with invalid model handle
78 *
79 */
80TEST_F(SoundTriggerHidlTest, GetModelStateInvalidModel) {
81 int ret = android::OK;
82 ::android::hardware::soundtrigger::V2_0::ISoundTriggerHwCallback::RecognitionEvent event;
83 SoundModelHandle handle = 0;
84 Return<void> hidlReturn =
85 mSoundTriggerHal->getModelState(handle, [&](int32_t retval, auto res) {
86 ret = retval;
87 event = res;
88 });
89
90 EXPECT_TRUE(hidlReturn.isOk());
91 EXPECT_EQ(-ENOSYS, ret);
92}
93
94int main(int argc, char** argv) {
95 ::testing::AddGlobalTestEnvironment(SoundTriggerHidlEnvironment::Instance());
96 ::testing::InitGoogleTest(&argc, argv);
97 SoundTriggerHidlEnvironment::Instance()->init(&argc, argv);
98 int status = RUN_ALL_TESTS();
99 ALOGI("Test result = %d", status);
100 return status;
101}