summaryrefslogtreecommitdiff
path: root/soundtrigger/2.4/vts/functional/VtsHalSoundtriggerV2_4TargetTest.cpp
blob: 13d70058e1a46925a954ce33c1dd32561956d264 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "SoundTriggerHidlHalTest"

#include <android-base/logging.h>
#include <android/hardware/audio/common/2.0/types.h>
#include <android/hardware/soundtrigger/2.4/ISoundTriggerHwGlobalCallback.h>
#include <android/hardware/soundtrigger/2.4/ISoundTriggerHw.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>

using ::android::sp;
using ::android::hardware::Return;
using ::android::hardware::Status;
using ::android::hardware::soundtrigger::V2_4::ISoundTriggerHw;
using ::android::hardware::soundtrigger::V2_4::ISoundTriggerHwGlobalCallback;

/**
 * Test class holding the instance of the SoundTriggerHW service to test.
 * The passed parameter is the registered name of the implementing service
 * supplied by INSTANTIATE_TEST_SUITE_P() call.
 */
class SoundTriggerHidlTest : public testing::TestWithParam<std::string> {
public:
    void SetUp() override {
        mSoundtrigger = ISoundTriggerHw::getService(GetParam());

        ASSERT_NE(mSoundtrigger, nullptr);
        LOG(INFO) << "Test is remote " << mSoundtrigger->isRemote();
    }

protected:
    sp<ISoundTriggerHw> mSoundtrigger;
};

/**
 * Empty test is in place to ensure service is initialized.
 * Due to the nature of SoundTrigger HAL providing an interface for
 * proprietary or vendor specific implementations, limited testing on
 * individual APIs is possible.
 */
TEST_P(SoundTriggerHidlTest, ServiceIsInstantiated) {}

class GlobalCallback : public ISoundTriggerHwGlobalCallback {
    Return<void> onResourcesAvailable() override {
        return Status::ok();
    }
};

/**
 * Test ISoundTriggerHw::registerGlobalCallback method
 *
 * Verifies that:
 * - the implementation implements the method
 * - the method returns no error
 */
TEST_P(SoundTriggerHidlTest, RegisterGlobalCallback) {
    Return<void> hidlReturn;
    sp<ISoundTriggerHwGlobalCallback> callback = new GlobalCallback();
    hidlReturn = mSoundtrigger->registerGlobalCallback(callback);
    EXPECT_TRUE(hidlReturn.isOk());
}

GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SoundTriggerHidlTest);

INSTANTIATE_TEST_SUITE_P(
        PerInstance, SoundTriggerHidlTest,
        testing::ValuesIn(android::hardware::getAllHalInstanceNames(ISoundTriggerHw::descriptor)),
        android::hardware::PrintInstanceNameToString);