blob: 05f136ef6128756b5e9c908d23de5b06ae5476d4 [file] [log] [blame]
David Anderson04732142019-10-07 13:34:24 -07001/*
Sivananthinikumarib2018882022-06-13 18:10:25 +05302
David Anderson04732142019-10-07 13:34:24 -07003 * Copyright (C) 2019 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#define LOG_TAG "boot_hidl_hal_test"
19
20#include <vector>
21
22#include <android-base/logging.h>
Sivananthinikumarib2018882022-06-13 18:10:25 +053023#include <android-base/properties.h>
David Anderson04732142019-10-07 13:34:24 -070024#include <android/hardware/boot/1.1/IBootControl.h>
25#include <android/hardware/boot/1.1/types.h>
26#include <gmock/gmock.h>
27#include <gtest/gtest.h>
28#include <hidl/GtestPrinter.h>
29#include <hidl/ServiceManagement.h>
30
31#include <unistd.h>
32
33using ::android::sp;
34using ::android::hardware::hidl_enum_range;
35using ::android::hardware::hidl_vec;
36using ::android::hardware::Return;
37using ::android::hardware::Void;
38using ::android::hardware::boot::V1_1::IBootControl;
39using ::android::hardware::boot::V1_1::MergeStatus;
40using ::testing::Contains;
41
Sivananthinikumarib2018882022-06-13 18:10:25 +053042bool IsVirtualAbEnabled();
43
44#define SKIP_IF_NON_VIRTUAL_AB() \
45 do { \
46 if (!IsVirtualAbEnabled()) GTEST_SKIP() << "Test for Virtual A/B devices only"; \
47 } while (0)
48
49bool IsVirtualAbEnabled() {
50 return android::base::GetBoolProperty("ro.virtual_ab.enabled", false);
51}
52
David Anderson04732142019-10-07 13:34:24 -070053class BootHidlTest : public testing::TestWithParam<std::string> {
54 public:
55 virtual void SetUp() override {
Sivananthinikumarib2018882022-06-13 18:10:25 +053056 SKIP_IF_NON_VIRTUAL_AB();
David Anderson04732142019-10-07 13:34:24 -070057 boot = IBootControl::getService(GetParam());
58 ASSERT_NE(boot, nullptr);
59
60 LOG(INFO) << "Test is remote " << boot->isRemote();
61 }
62
63 sp<IBootControl> boot;
64};
65
66static std::vector<MergeStatus> ValidMergeStatusValues() {
67 std::vector<MergeStatus> values;
68 for (const auto value : hidl_enum_range<MergeStatus>()) {
69 if (value == MergeStatus::UNKNOWN) {
70 continue;
71 }
72 values.push_back(value);
73 }
74 return values;
75}
76
77/**
78 * Ensure merge status can be retrieved.
79 */
80TEST_P(BootHidlTest, GetSnapshotMergeStatus) {
81 auto values = ValidMergeStatusValues();
82 auto status = (MergeStatus)boot->getSnapshotMergeStatus();
83 EXPECT_THAT(values, Contains(status));
84}
85
86/**
87 * Ensure merge status can be set to arbitrary value.
88 */
89TEST_P(BootHidlTest, SetSnapshotMergeStatus) {
90 for (const auto value : ValidMergeStatusValues()) {
91 EXPECT_TRUE(boot->setSnapshotMergeStatus(value).withDefault(false));
92 auto status = boot->getSnapshotMergeStatus();
David Andersonf0fbfdd2020-04-28 17:44:32 -070093 if (value == MergeStatus::SNAPSHOTTED) {
94 EXPECT_TRUE(status == MergeStatus::SNAPSHOTTED || status == MergeStatus::NONE);
95 } else {
96 EXPECT_EQ(status, value);
97 }
David Anderson04732142019-10-07 13:34:24 -070098 }
99}
100
Dan Shiba4d5322020-07-28 13:09:30 -0700101GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BootHidlTest);
David Anderson04732142019-10-07 13:34:24 -0700102INSTANTIATE_TEST_SUITE_P(
Haibo Huang83b4c1e2019-11-08 11:59:40 -0800103 PerInstance, BootHidlTest,
David Anderson04732142019-10-07 13:34:24 -0700104 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IBootControl::descriptor)),
105 android::hardware::PrintInstanceNameToString);