BootControlAndroid unittests: fix tests
Tests are broken when fs_mgr_get_super_partition_name requires a
'slot' argument, and it defaults to zero.
Test: update_engine_unittests --gtest_filter=*BootControlAndroid*
Bug: 118506262
Change-Id: Ibd36e8d8e714e87525079b38e1ce78fc940c958b
diff --git a/boot_control_android_unittest.cc b/boot_control_android_unittest.cc
index 2375714..d706810 100644
--- a/boot_control_android_unittest.cc
+++ b/boot_control_android_unittest.cc
@@ -124,8 +124,10 @@
inline std::string GetDevice(const std::string& name) {
return kFakeDevicePath + name;
}
-inline std::string GetSuperDevice() {
- return GetDevice(fs_mgr_get_super_partition_name());
+
+// TODO(elsk): fs_mgr_get_super_partition_name should be mocked.
+inline std::string GetSuperDevice(uint32_t slot) {
+ return GetDevice(fs_mgr_get_super_partition_name(slot));
}
struct TestParam {
@@ -301,7 +303,7 @@
void SetMetadata(uint32_t slot, const PartitionMetadata& metadata) {
EXPECT_CALL(dynamicControl(),
- LoadMetadataBuilder(GetSuperDevice(), slot, _))
+ LoadMetadataBuilder(GetSuperDevice(slot), slot, _))
.Times(AnyNumber())
.WillRepeatedly(Invoke([metadata](auto, auto, auto) {
return NewFakeMetadata(metadata);
@@ -317,9 +319,10 @@
.WillByDefault(Return(false));
for (const auto& partition : partitions) {
- EXPECT_CALL(dynamicControl(),
- MapPartitionOnDeviceMapper(
- GetSuperDevice(), partition, target(), force_writable, _))
+ EXPECT_CALL(
+ dynamicControl(),
+ MapPartitionOnDeviceMapper(
+ GetSuperDevice(target()), partition, target(), force_writable, _))
.WillOnce(Invoke([this](auto, auto partition, auto, auto, auto path) {
auto it = mapped_devices_.find(partition);
if (it != mapped_devices_.end()) {
@@ -368,7 +371,7 @@
virtual void ExpectStoreMetadataMatch(
const Matcher<MetadataBuilder*>& matcher) {
EXPECT_CALL(dynamicControl(),
- StoreMetadata(GetSuperDevice(), matcher, target()))
+ StoreMetadata(GetSuperDevice(target()), matcher, target()))
.WillOnce(Return(true));
}
@@ -394,11 +397,12 @@
return source();
}));
// Should not store metadata to source slot.
- EXPECT_CALL(dynamicControl(), StoreMetadata(GetSuperDevice(), _, source()))
+ EXPECT_CALL(dynamicControl(),
+ StoreMetadata(GetSuperDevice(source()), _, source()))
.Times(0);
// Should not load metadata from target slot.
EXPECT_CALL(dynamicControl(),
- LoadMetadataBuilder(GetSuperDevice(), target(), _))
+ LoadMetadataBuilder(GetSuperDevice(target()), target(), _))
.Times(0);
}
@@ -517,7 +521,7 @@
// Test corrupt source metadata case.
TEST_P(BootControlAndroidTestP, CorruptedSourceMetadata) {
EXPECT_CALL(dynamicControl(),
- LoadMetadataBuilder(GetSuperDevice(), source(), _))
+ LoadMetadataBuilder(GetSuperDevice(source()), source(), _))
.WillOnce(Invoke([](auto, auto, auto) { return nullptr; }));
EXPECT_FALSE(InitPartitionMetadata(target(), {{"system", 1_GiB}}))
<< "Should not be able to continue with corrupt source metadata";