platform_hardware_interfaces/ir/1.0/vts/functional/VtsHalIrV1_0TargetTest.cpp
Zhuoyao Zhang 146b8f8093 Convert ir hal test to use VtsHalHidlTargetTestEnvBase
Bug: 64203181
Test: make vts
      vts-tradefed run vts -m VtsHalIrV1_0Target

Change-Id: If3f7fcd04ce6d1e2a499a62807e186f36a771748
2018-02-10 19:35:49 -08:00

102 lines
3.1 KiB
C++

/*
* Copyright (C) 2016 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 "ir_hidl_hal_test"
#include <android-base/logging.h>
#include <android/hardware/ir/1.0/IConsumerIr.h>
#include <android/hardware/ir/1.0/types.h>
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
#include <algorithm>
using ::android::hardware::ir::V1_0::IConsumerIr;
using ::android::hardware::ir::V1_0::ConsumerIrFreqRange;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::sp;
// Test environment for Ir
class ConsumerIrHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
public:
// get the test environment singleton
static ConsumerIrHidlEnvironment* Instance() {
static ConsumerIrHidlEnvironment* instance = new ConsumerIrHidlEnvironment;
return instance;
}
virtual void registerTestServices() override { registerTestService<IConsumerIr>(); }
private:
ConsumerIrHidlEnvironment() {}
};
// The main test class for IR HIDL HAL.
class ConsumerIrHidlTest : public ::testing::VtsHalHidlTargetTestBase {
public:
virtual void SetUp() override {
ir = ::testing::VtsHalHidlTargetTestBase::getService<IConsumerIr>(
ConsumerIrHidlEnvironment::Instance()->getServiceName<IConsumerIr>());
ASSERT_NE(ir, nullptr);
}
virtual void TearDown() override {}
sp<IConsumerIr> ir;
};
// Test transmit() for the min and max frequency of every available range
TEST_F(ConsumerIrHidlTest, TransmitTest) {
bool success;
hidl_vec<ConsumerIrFreqRange> ranges;
auto cb = [&](bool s, hidl_vec<ConsumerIrFreqRange> v) {
ranges = v;
success = s;
};
Return<void> ret = ir->getCarrierFreqs(cb);
ASSERT_TRUE(ret.isOk());
ASSERT_TRUE(success);
if (ranges.size() > 0) {
uint32_t len = 16;
hidl_vec<int32_t> vec;
vec.resize(len);
std::fill(vec.begin(), vec.end(), 1000);
for (auto range = ranges.begin(); range != ranges.end(); range++) {
EXPECT_TRUE(ir->transmit(range->min, vec));
EXPECT_TRUE(ir->transmit(range->max, vec));
}
}
}
// Test transmit() when called with invalid frequencies
TEST_F(ConsumerIrHidlTest, BadFreqTest) {
uint32_t len = 16;
hidl_vec<int32_t> vec;
vec.resize(len);
std::fill(vec.begin(), vec.end(), 1);
EXPECT_FALSE(ir->transmit(-1, vec));
}
int main(int argc, char **argv) {
::testing::AddGlobalTestEnvironment(ConsumerIrHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv);
ConsumerIrHidlEnvironment::Instance()->init(&argc, argv);
int status = RUN_ALL_TESTS();
LOG(INFO) << "Test result = " << status;
return status;
}