blob: 7c58ef3717c6be4fd836e7d9b17c8b2679ffacca [file] [log] [blame]
David Anderson04732142019-10-07 13:34:24 -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 "boot_hidl_hal_test"
18
19#include <vector>
20
21#include <android-base/logging.h>
22#include <android/hardware/boot/1.1/IBootControl.h>
23#include <android/hardware/boot/1.1/types.h>
24#include <gmock/gmock.h>
25#include <gtest/gtest.h>
26#include <hidl/GtestPrinter.h>
27#include <hidl/ServiceManagement.h>
28
29#include <unistd.h>
30
31using ::android::sp;
32using ::android::hardware::hidl_enum_range;
33using ::android::hardware::hidl_vec;
34using ::android::hardware::Return;
35using ::android::hardware::Void;
36using ::android::hardware::boot::V1_1::IBootControl;
37using ::android::hardware::boot::V1_1::MergeStatus;
38using ::testing::Contains;
39
40class BootHidlTest : public testing::TestWithParam<std::string> {
41 public:
42 virtual void SetUp() override {
43 boot = IBootControl::getService(GetParam());
44 ASSERT_NE(boot, nullptr);
45
46 LOG(INFO) << "Test is remote " << boot->isRemote();
47 }
48
49 sp<IBootControl> boot;
50};
51
52static std::vector<MergeStatus> ValidMergeStatusValues() {
53 std::vector<MergeStatus> values;
54 for (const auto value : hidl_enum_range<MergeStatus>()) {
55 if (value == MergeStatus::UNKNOWN) {
56 continue;
57 }
58 values.push_back(value);
59 }
60 return values;
61}
62
63/**
64 * Ensure merge status can be retrieved.
65 */
66TEST_P(BootHidlTest, GetSnapshotMergeStatus) {
67 auto values = ValidMergeStatusValues();
68 auto status = (MergeStatus)boot->getSnapshotMergeStatus();
69 EXPECT_THAT(values, Contains(status));
70}
71
72/**
73 * Ensure merge status can be set to arbitrary value.
74 */
75TEST_P(BootHidlTest, SetSnapshotMergeStatus) {
76 for (const auto value : ValidMergeStatusValues()) {
77 EXPECT_TRUE(boot->setSnapshotMergeStatus(value).withDefault(false));
78 auto status = boot->getSnapshotMergeStatus();
79 EXPECT_EQ(status, value);
80 }
81}
82
83INSTANTIATE_TEST_SUITE_P(
Haibo Huang83b4c1e2019-11-08 11:59:40 -080084 PerInstance, BootHidlTest,
David Anderson04732142019-10-07 13:34:24 -070085 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IBootControl::descriptor)),
86 android::hardware::PrintInstanceNameToString);