diff options
Diffstat (limited to 'aosp/dynamic_partition_control_android_unittest.cc')
-rw-r--r-- | aosp/dynamic_partition_control_android_unittest.cc | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/aosp/dynamic_partition_control_android_unittest.cc b/aosp/dynamic_partition_control_android_unittest.cc index 5d6463be..af5ae2c0 100644 --- a/aosp/dynamic_partition_control_android_unittest.cc +++ b/aosp/dynamic_partition_control_android_unittest.cc @@ -16,6 +16,7 @@ #include "update_engine/aosp/dynamic_partition_control_android.h" +#include <algorithm> #include <set> #include <vector> @@ -27,7 +28,7 @@ #include <libsnapshot/mock_snapshot.h> #include "update_engine/aosp/dynamic_partition_test_utils.h" -#include "update_engine/aosp/mock_dynamic_partition_control.h" +#include "update_engine/aosp/mock_dynamic_partition_control_android.h" #include "update_engine/common/mock_prefs.h" #include "update_engine/common/test_utils.h" @@ -38,6 +39,7 @@ using std::string; using testing::_; using testing::AnyNumber; using testing::AnyOf; +using testing::AtLeast; using testing::Invoke; using testing::NiceMock; using testing::Not; @@ -55,6 +57,8 @@ class DynamicPartitionControlAndroidTest : public ::testing::Test { .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH))); ON_CALL(dynamicControl(), GetVirtualAbFeatureFlag()) .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::NONE))); + ON_CALL(dynamicControl(), GetVirtualAbCompressionFeatureFlag()) + .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::NONE))); ON_CALL(dynamicControl(), GetDeviceDir(_)) .WillByDefault(Invoke([](auto path) { @@ -217,6 +221,8 @@ class DynamicPartitionControlAndroidTestP void SetUp() override { DynamicPartitionControlAndroidTest::SetUp(); SetSlots(GetParam()); + dynamicControl().SetSourceSlot(source()); + dynamicControl().SetTargetSlot(target()); } }; @@ -386,6 +392,84 @@ TEST_P(DynamicPartitionControlAndroidTestP, EXPECT_EQ(GetDevice(T("bar")), bar_device); } +TEST_P(DynamicPartitionControlAndroidTestP, GetMountableDevicePath) { + ON_CALL(dynamicControl(), GetDynamicPartitionsFeatureFlag()) + .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH))); + ON_CALL(dynamicControl(), GetVirtualAbFeatureFlag()) + .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH))); + ON_CALL(dynamicControl(), GetVirtualAbCompressionFeatureFlag()) + .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::NONE))); + ON_CALL(dynamicControl(), IsDynamicPartition(_)).WillByDefault(Return(true)); + + EXPECT_CALL(dynamicControl(), + DeviceExists(AnyOf(GetDevice(S("vendor")), + GetDevice(T("vendor")), + GetDevice(S("system")), + GetDevice(T("system"))))) + .WillRepeatedly(Return(true)); + EXPECT_CALL( + dynamicControl(), + GetState(AnyOf(S("vendor"), T("vendor"), S("system"), T("system")))) + .WillRepeatedly(Return(DmDeviceState::ACTIVE)); + + SetMetadata(source(), {{S("system"), 2_GiB}, {S("vendor"), 1_GiB}}); + SetMetadata(target(), {{T("system"), 2_GiB}, {T("vendor"), 1_GiB}}); + std::string device; + ASSERT_TRUE(dynamicControl().GetPartitionDevice( + "system", source(), source(), &device)); + ASSERT_EQ(GetDmDevice(S("system")), device); + + ASSERT_TRUE(dynamicControl().GetPartitionDevice( + "system", target(), source(), &device)); + ASSERT_EQ(GetDevice(T("system")), device); + + // If VABC is disabled, mountable device path should be same as device path. + auto device_info = + dynamicControl().GetPartitionDevice("system", target(), source()); + ASSERT_TRUE(device_info.has_value()); + ASSERT_EQ(device_info->mountable_device_path, device); +} + +TEST_P(DynamicPartitionControlAndroidTestP, GetMountableDevicePathVABC) { + ON_CALL(dynamicControl(), GetDynamicPartitionsFeatureFlag()) + .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH))); + ON_CALL(dynamicControl(), GetVirtualAbFeatureFlag()) + .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH))); + ON_CALL(dynamicControl(), GetVirtualAbCompressionFeatureFlag()) + .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH))); + EXPECT_CALL(dynamicControl(), IsDynamicPartition(_)) + .Times(AtLeast(1)) + .WillRepeatedly(Return(true)); + + EXPECT_CALL(dynamicControl(), + DeviceExists(AnyOf(GetDevice(S("vendor")), + GetDevice(T("vendor")), + GetDevice(S("system")), + GetDevice(T("system"))))) + .WillRepeatedly(Return(true)); + EXPECT_CALL( + dynamicControl(), + GetState(AnyOf(S("vendor"), T("vendor"), S("system"), T("system")))) + .WillRepeatedly(Return(DmDeviceState::ACTIVE)); + + SetMetadata(source(), {{S("system"), 2_GiB}, {S("vendor"), 1_GiB}}); + SetMetadata(target(), {{T("system"), 2_GiB}, {T("vendor"), 1_GiB}}); + + std::string device; + ASSERT_TRUE(dynamicControl().GetPartitionDevice( + "system", source(), source(), &device)); + ASSERT_EQ(GetDmDevice(S("system")), device); + + ASSERT_TRUE(dynamicControl().GetPartitionDevice( + "system", target(), source(), &device)); + ASSERT_EQ("", device); + + auto device_info = + dynamicControl().GetPartitionDevice("system", target(), source()); + ASSERT_TRUE(device_info.has_value()); + ASSERT_EQ(device_info->mountable_device_path, GetDevice(T("system"))); +} + TEST_P(DynamicPartitionControlAndroidTestP, GetPartitionDeviceWhenResumingUpdate) { // Static partition bar_{a,b} exists. |