summaryrefslogtreecommitdiff
path: root/boot_control_android_unittest.cc
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2019-11-05 16:34:32 -0800
committerYifan Hong <elsk@google.com>2019-11-13 03:12:37 +0000
commit3a1a5618390aeb56a2d7d4ca1cc61b97ea1515a2 (patch)
treeb54c69057b1b974fec3aae93e5ecea9b3ba7b9f4 /boot_control_android_unittest.cc
parent2b0f10a8c150e2094dbd1c5cdd81aed3af078474 (diff)
Proper split of BootControl and DynamicPartitionControl.
All dynamic/static partitions stuff are moved to DynamicPartitionControlAndroid. After this patch: (1) BootControl remains a simple shim over the boot control HAL. (BootControl still have two calls that is a delegate to DynamicPartitionControl, which will be cleaned up in follow up CLs.) (2) DynamicPartitionControlInterface API is minimized. All libdm and other Android specific details are hidden from the API surface now. Also move tests from boot_control_unittest to dynamic_partition_control_unittest because functionalities are moved. Test: update_engine_unittests Change-Id: I6ed902197569f9f0ef40e02703634e9078a4b060
Diffstat (limited to 'boot_control_android_unittest.cc')
-rw-r--r--boot_control_android_unittest.cc250
1 files changed, 0 insertions, 250 deletions
diff --git a/boot_control_android_unittest.cc b/boot_control_android_unittest.cc
deleted file mode 100644
index e44af157..00000000
--- a/boot_control_android_unittest.cc
+++ /dev/null
@@ -1,250 +0,0 @@
-//
-// Copyright (C) 2018 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.
-//
-
-#include "update_engine/boot_control_android.h"
-
-#include <set>
-#include <vector>
-
-#include <base/logging.h>
-#include <base/strings/string_util.h>
-#include <fs_mgr.h>
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-#include <libdm/dm.h>
-
-#include "update_engine/dynamic_partition_test_utils.h"
-#include "update_engine/mock_boot_control_hal.h"
-#include "update_engine/mock_dynamic_partition_control.h"
-
-using android::dm::DmDeviceState;
-using android::hardware::Void;
-using std::string;
-using testing::_;
-using testing::AnyNumber;
-using testing::Invoke;
-using testing::NiceMock;
-using testing::Not;
-using testing::Return;
-
-namespace chromeos_update_engine {
-
-class BootControlAndroidTest : public ::testing::Test {
- protected:
- void SetUp() override {
- // Fake init bootctl_
- bootctl_.module_ = new NiceMock<MockBootControlHal>();
- bootctl_.dynamic_control_ =
- std::make_unique<NiceMock<MockDynamicPartitionControl>>();
-
- ON_CALL(module(), getNumberSlots()).WillByDefault(Invoke([] {
- return kMaxNumSlots;
- }));
- ON_CALL(module(), getSuffix(_, _))
- .WillByDefault(Invoke([](auto slot, auto cb) {
- EXPECT_LE(slot, kMaxNumSlots);
- cb(slot < kMaxNumSlots ? kSlotSuffixes[slot] : "");
- return Void();
- }));
-
- ON_CALL(dynamicControl(), GetDynamicPartitionsFeatureFlag())
- .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH)));
- ON_CALL(dynamicControl(), GetVirtualAbFeatureFlag())
- .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::NONE)));
- ON_CALL(dynamicControl(), DeviceExists(_)).WillByDefault(Return(true));
- ON_CALL(dynamicControl(), GetDeviceDir(_))
- .WillByDefault(Invoke([](auto path) {
- *path = kFakeDevicePath;
- return true;
- }));
- ON_CALL(dynamicControl(), GetDmDevicePathByName(_, _))
- .WillByDefault(Invoke([](auto partition_name_suffix, auto device) {
- *device = GetDmDevice(partition_name_suffix);
- return true;
- }));
-
- ON_CALL(dynamicControl(), GetSuperPartitionName(_))
- .WillByDefault(Return(kFakeSuper));
- }
-
- std::string GetSuperDevice(uint32_t slot) {
- return GetDevice(dynamicControl().GetSuperPartitionName(slot));
- }
-
- // Return the mocked HAL module.
- NiceMock<MockBootControlHal>& module() {
- return static_cast<NiceMock<MockBootControlHal>&>(*bootctl_.module_);
- }
-
- // Return the mocked DynamicPartitionControlInterface.
- NiceMock<MockDynamicPartitionControl>& dynamicControl() {
- return static_cast<NiceMock<MockDynamicPartitionControl>&>(
- *bootctl_.dynamic_control_);
- }
-
- // Set the fake metadata to return when LoadMetadataBuilder is called on
- // |slot|.
- void SetMetadata(uint32_t slot, const PartitionSuffixSizes& sizes) {
- EXPECT_CALL(dynamicControl(),
- LoadMetadataBuilder(GetSuperDevice(slot), slot))
- .Times(AnyNumber())
- .WillRepeatedly(Invoke([sizes](auto, auto) {
- return NewFakeMetadata(PartitionSuffixSizesToManifest(sizes));
- }));
- }
-
- uint32_t source() { return slots_.source; }
-
- uint32_t target() { return slots_.target; }
-
- // Return partition names with suffix of source().
- string S(const string& name) { return name + kSlotSuffixes[source()]; }
-
- // Return partition names with suffix of target().
- string T(const string& name) { return name + kSlotSuffixes[target()]; }
-
- // Set source and target slots to use before testing.
- void SetSlots(const TestParam& slots) {
- slots_ = slots;
-
- ON_CALL(module(), getCurrentSlot()).WillByDefault(Invoke([this] {
- return source();
- }));
- }
-
- bool PreparePartitionsForUpdate(uint32_t slot,
- PartitionSizes partition_sizes,
- bool update_metadata = true) {
- auto m = PartitionSizesToManifest(partition_sizes);
- return bootctl_.PreparePartitionsForUpdate(slot, m, update_metadata);
- }
-
- BootControlAndroid bootctl_; // BootControlAndroid under test.
- TestParam slots_;
-};
-
-class BootControlAndroidTestP
- : public BootControlAndroidTest,
- public ::testing::WithParamInterface<TestParam> {
- public:
- void SetUp() override {
- BootControlAndroidTest::SetUp();
- SetSlots(GetParam());
- }
-};
-
-// Test applying retrofit update on a build with dynamic partitions enabled.
-TEST_P(BootControlAndroidTestP,
- ApplyRetrofitUpdateOnDynamicPartitionsEnabledBuild) {
- SetMetadata(source(),
- {{S("system"), 2_GiB},
- {S("vendor"), 1_GiB},
- {T("system"), 2_GiB},
- {T("vendor"), 1_GiB}});
-
- // Not calling through BootControlAndroidTest::PreparePartitionsForUpdate(),
- // since we don't want any default group in the PartitionMetadata.
- EXPECT_TRUE(bootctl_.PreparePartitionsForUpdate(target(), {}, true));
-
- // Should use dynamic source partitions.
- EXPECT_CALL(dynamicControl(), GetState(S("system")))
- .Times(1)
- .WillOnce(Return(DmDeviceState::ACTIVE));
- string system_device;
- EXPECT_TRUE(bootctl_.GetPartitionDevice("system", source(), &system_device));
- EXPECT_EQ(GetDmDevice(S("system")), system_device);
-
- // Should use static target partitions without querying dynamic control.
- EXPECT_CALL(dynamicControl(), GetState(T("system"))).Times(0);
- EXPECT_TRUE(bootctl_.GetPartitionDevice("system", target(), &system_device));
- EXPECT_EQ(GetDevice(T("system")), system_device);
-
- // Static partition "bar".
- EXPECT_CALL(dynamicControl(), GetState(S("bar"))).Times(0);
- std::string bar_device;
- EXPECT_TRUE(bootctl_.GetPartitionDevice("bar", source(), &bar_device));
- EXPECT_EQ(GetDevice(S("bar")), bar_device);
-
- EXPECT_CALL(dynamicControl(), GetState(T("bar"))).Times(0);
- EXPECT_TRUE(bootctl_.GetPartitionDevice("bar", target(), &bar_device));
- EXPECT_EQ(GetDevice(T("bar")), bar_device);
-}
-
-TEST_P(BootControlAndroidTestP, GetPartitionDeviceWhenResumingUpdate) {
- // Both of the two slots contain valid partition metadata, since this is
- // resuming an update.
- SetMetadata(source(),
- {{S("system"), 2_GiB},
- {S("vendor"), 1_GiB},
- {T("system"), 2_GiB},
- {T("vendor"), 1_GiB}});
- SetMetadata(target(),
- {{S("system"), 2_GiB},
- {S("vendor"), 1_GiB},
- {T("system"), 2_GiB},
- {T("vendor"), 1_GiB}});
-
- EXPECT_CALL(dynamicControl(), PreparePartitionsForUpdate(_, _, _, false))
- .WillOnce(Return(true));
-
- EXPECT_TRUE(PreparePartitionsForUpdate(
- target(), {{"system", 2_GiB}, {"vendor", 1_GiB}}, false));
-
- // Dynamic partition "system".
- EXPECT_CALL(dynamicControl(), GetState(S("system")))
- .Times(1)
- .WillOnce(Return(DmDeviceState::ACTIVE));
- string system_device;
- EXPECT_TRUE(bootctl_.GetPartitionDevice("system", source(), &system_device));
- EXPECT_EQ(GetDmDevice(S("system")), system_device);
-
- EXPECT_CALL(dynamicControl(), GetState(T("system")))
- .Times(AnyNumber())
- .WillOnce(Return(DmDeviceState::ACTIVE));
- EXPECT_CALL(dynamicControl(),
- MapPartitionOnDeviceMapper(
- GetSuperDevice(target()), T("system"), target(), _, _))
- .Times(AnyNumber())
- .WillRepeatedly(
- Invoke([](const auto&, const auto& name, auto, auto, auto* device) {
- *device = "/fake/remapped/" + name;
- return true;
- }));
- EXPECT_TRUE(bootctl_.GetPartitionDevice("system", target(), &system_device));
- EXPECT_EQ("/fake/remapped/" + T("system"), system_device);
-
- // Static partition "bar".
- EXPECT_CALL(dynamicControl(), GetState(S("bar"))).Times(0);
- std::string bar_device;
- EXPECT_TRUE(bootctl_.GetPartitionDevice("bar", source(), &bar_device));
- EXPECT_EQ(GetDevice(S("bar")), bar_device);
-
- EXPECT_CALL(dynamicControl(), GetState(T("bar"))).Times(0);
- EXPECT_TRUE(bootctl_.GetPartitionDevice("bar", target(), &bar_device));
- EXPECT_EQ(GetDevice(T("bar")), bar_device);
-}
-
-INSTANTIATE_TEST_CASE_P(BootControlAndroidTest,
- BootControlAndroidTestP,
- testing::Values(TestParam{0, 1}, TestParam{1, 0}));
-
-TEST_F(BootControlAndroidTest, ApplyingToCurrentSlot) {
- SetSlots({1, 1});
- EXPECT_FALSE(PreparePartitionsForUpdate(target(), {}))
- << "Should not be able to apply to current slot.";
-}
-
-} // namespace chromeos_update_engine