From 6727d5840b94d94a3ca9b9dca41a37cc3a5efe49 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 25 Apr 2023 16:46:21 -0700 Subject: [PATCH] libsnapshot: Fix test failures on certain configurations. Due to how CF is built and tested, VABC is enabled even when not supported by the kernel. To work around this add some logic in libsnapshot and the test harness to recognize this situation and silently flip off the VABC flag. This also fixes the -force_mode option to vts_libsnapshot_test, so that it will skip tests that aren't supported by the device. Bug: 264279496 Test: vts_libsnapshot_test on android12-gsi with 11-5.4 kernel Change-Id: I9279d8d400cac5cd504a7ae91f254aae57fa856d --- fs_mgr/libsnapshot/snapshot.cpp | 3 ++- fs_mgr/libsnapshot/snapshot_test.cpp | 34 ++++++++++++++++------------ fs_mgr/libsnapshot/utility.cpp | 7 ++++++ fs_mgr/libsnapshot/utility.h | 1 + 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp index 0e36da151..2773be79b 100644 --- a/fs_mgr/libsnapshot/snapshot.cpp +++ b/fs_mgr/libsnapshot/snapshot.cpp @@ -2784,7 +2784,8 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife << " writer.GetCowVersion(): " << writer.GetCowVersion(); bool use_compression = IsCompressionEnabled() && dap_metadata.vabc_enabled() && - !device_->IsRecovery() && cow_format_support; + !device_->IsRecovery() && cow_format_support && + KernelSupportsCompressedSnapshots(); std::string compression_algorithm; if (use_compression) { diff --git a/fs_mgr/libsnapshot/snapshot_test.cpp b/fs_mgr/libsnapshot/snapshot_test.cpp index 60186434a..57a28546f 100644 --- a/fs_mgr/libsnapshot/snapshot_test.cpp +++ b/fs_mgr/libsnapshot/snapshot_test.cpp @@ -125,6 +125,10 @@ class SnapshotTest : public ::testing::Test { sm->set_use_first_stage_snapuserd(false); } + bool DeviceSupportsCompression() { + return IsCompressionEnabled() && KernelSupportsCompressedSnapshots(); + } + void CleanupTestArtifacts() { // Normally cancelling inside a merge is not allowed. Since these // are tests, we don't care, destroy everything that might exist. @@ -327,7 +331,7 @@ class SnapshotTest : public ::testing::Test { DeltaArchiveManifest manifest; auto dynamic_partition_metadata = manifest.mutable_dynamic_partition_metadata(); - dynamic_partition_metadata->set_vabc_enabled(IsCompressionEnabled()); + dynamic_partition_metadata->set_vabc_enabled(DeviceSupportsCompression()); dynamic_partition_metadata->set_cow_version(android::snapshot::kCowVersionMajor); auto group = dynamic_partition_metadata->add_groups(); @@ -366,7 +370,7 @@ class SnapshotTest : public ::testing::Test { if (!res) { return res; } - } else if (!IsCompressionEnabled()) { + } else if (!DeviceSupportsCompression()) { std::string ignore; if (!MapUpdateSnapshot("test_partition_b", &ignore)) { return AssertionFailure() << "Failed to map test_partition_b"; @@ -425,7 +429,7 @@ TEST_F(SnapshotTest, CreateSnapshot) { ASSERT_TRUE(AcquireLock()); PartitionCowCreator cow_creator; - cow_creator.compression_enabled = IsCompressionEnabled(); + cow_creator.compression_enabled = DeviceSupportsCompression(); if (cow_creator.compression_enabled) { cow_creator.compression_algorithm = "gz"; } else { @@ -466,7 +470,7 @@ TEST_F(SnapshotTest, MapSnapshot) { ASSERT_TRUE(AcquireLock()); PartitionCowCreator cow_creator; - cow_creator.compression_enabled = IsCompressionEnabled(); + cow_creator.compression_enabled = DeviceSupportsCompression(); static const uint64_t kDeviceSize = 1024 * 1024; SnapshotStatus status; @@ -585,7 +589,7 @@ TEST_F(SnapshotTest, FirstStageMountAndMerge) { SnapshotStatus status; ASSERT_TRUE(init->ReadSnapshotStatus(lock_.get(), "test_partition_b", &status)); ASSERT_EQ(status.state(), SnapshotState::CREATED); - if (IsCompressionEnabled()) { + if (DeviceSupportsCompression()) { ASSERT_EQ(status.compression_algorithm(), "gz"); } else { ASSERT_EQ(status.compression_algorithm(), "none"); @@ -855,7 +859,7 @@ class SnapshotUpdateTest : public SnapshotTest { opener_ = std::make_unique(fake_super); auto dynamic_partition_metadata = manifest_.mutable_dynamic_partition_metadata(); - dynamic_partition_metadata->set_vabc_enabled(IsCompressionEnabled()); + dynamic_partition_metadata->set_vabc_enabled(DeviceSupportsCompression()); dynamic_partition_metadata->set_cow_version(android::snapshot::kCowVersionMajor); // Create a fake update package metadata. @@ -975,7 +979,7 @@ class SnapshotUpdateTest : public SnapshotTest { } AssertionResult MapOneUpdateSnapshot(const std::string& name) { - if (IsCompressionEnabled()) { + if (DeviceSupportsCompression()) { std::unique_ptr writer; return MapUpdateSnapshot(name, &writer); } else { @@ -985,7 +989,7 @@ class SnapshotUpdateTest : public SnapshotTest { } AssertionResult WriteSnapshotAndHash(const std::string& name) { - if (IsCompressionEnabled()) { + if (DeviceSupportsCompression()) { std::unique_ptr writer; auto res = MapUpdateSnapshot(name, &writer); if (!res) { @@ -1158,7 +1162,7 @@ TEST_F(SnapshotUpdateTest, FullUpdateFlow) { // Initiate the merge and wait for it to be completed. ASSERT_TRUE(init->InitiateMerge()); - ASSERT_EQ(init->IsSnapuserdRequired(), IsCompressionEnabled()); + ASSERT_EQ(init->IsSnapuserdRequired(), DeviceSupportsCompression()); { // We should have started in SECOND_PHASE since nothing shrinks. ASSERT_TRUE(AcquireLock()); @@ -1187,7 +1191,7 @@ TEST_F(SnapshotUpdateTest, FullUpdateFlow) { // Test that shrinking and growing partitions at the same time is handled // correctly in VABC. TEST_F(SnapshotUpdateTest, SpaceSwapUpdate) { - if (!IsCompressionEnabled()) { + if (!DeviceSupportsCompression()) { // b/179111359 GTEST_SKIP() << "Skipping Virtual A/B Compression test"; } @@ -1255,7 +1259,7 @@ TEST_F(SnapshotUpdateTest, SpaceSwapUpdate) { // Initiate the merge and wait for it to be completed. ASSERT_TRUE(init->InitiateMerge()); - ASSERT_EQ(init->IsSnapuserdRequired(), IsCompressionEnabled()); + ASSERT_EQ(init->IsSnapuserdRequired(), DeviceSupportsCompression()); { // Check that the merge phase is FIRST_PHASE until at least one call // to ProcessUpdateState() occurs. @@ -1879,8 +1883,8 @@ TEST_F(SnapshotUpdateTest, DataWipeWithStaleSnapshots) { ASSERT_TRUE(AcquireLock()); PartitionCowCreator cow_creator = { - .compression_enabled = IsCompressionEnabled(), - .compression_algorithm = IsCompressionEnabled() ? "gz" : "none", + .compression_enabled = DeviceSupportsCompression(), + .compression_algorithm = DeviceSupportsCompression() ? "gz" : "none", }; SnapshotStatus status; status.set_name("sys_a"); @@ -1974,7 +1978,7 @@ TEST_F(SnapshotUpdateTest, Hashtree) { // Test for overflow bit after update TEST_F(SnapshotUpdateTest, Overflow) { - if (IsCompressionEnabled()) { + if (DeviceSupportsCompression()) { GTEST_SKIP() << "No overflow bit set for userspace COWs"; } @@ -2040,7 +2044,7 @@ class AutoKill final { }; TEST_F(SnapshotUpdateTest, DaemonTransition) { - if (!IsCompressionEnabled()) { + if (!DeviceSupportsCompression()) { GTEST_SKIP() << "Skipping Virtual A/B Compression test"; } diff --git a/fs_mgr/libsnapshot/utility.cpp b/fs_mgr/libsnapshot/utility.cpp index 4a2af1c10..e46bffbde 100644 --- a/fs_mgr/libsnapshot/utility.cpp +++ b/fs_mgr/libsnapshot/utility.cpp @@ -25,7 +25,9 @@ #include #include #include +#include +using android::dm::DeviceMapper; using android::dm::kSectorSize; using android::fiemap::FiemapStatus; using android::fs_mgr::EnsurePathMounted; @@ -195,5 +197,10 @@ std::string GetOtherPartitionName(const std::string& name) { return name.substr(0, name.size() - suffix.size()) + other_suffix; } +bool KernelSupportsCompressedSnapshots() { + auto& dm = DeviceMapper::Instance(); + return dm.GetTargetByName("user", nullptr); +} + } // namespace snapshot } // namespace android diff --git a/fs_mgr/libsnapshot/utility.h b/fs_mgr/libsnapshot/utility.h index 671de9dbc..b0e565cfe 100644 --- a/fs_mgr/libsnapshot/utility.h +++ b/fs_mgr/libsnapshot/utility.h @@ -129,6 +129,7 @@ std::ostream& operator<<(std::ostream& os, const Now&); void AppendExtent(google::protobuf::RepeatedPtrField* extents, uint64_t start_block, uint64_t num_blocks); +bool KernelSupportsCompressedSnapshots(); bool IsCompressionEnabled(); // Swap the suffix of a partition name.