libsnapshot_test: skip global setup on non-VAB devices.
On non-VAB devices, fake super image creation may fail because it may not support f2fs file pinning. Also changes global setup to a testing::Environment object because it is the recommended way in gtest's guide. SnapshotTestEnvironement::TearDown is automatically executed before RUN_ALL_TEST returns. Test: vts_libsnapshot_test Test: make IsVirtualAbEnabled() return false, then all tests are skipped. Bug: 162557082 Change-Id: I1382f9a4ddec146fa2d8cfb21ac66ca22a2e110f
This commit is contained in:
parent
ca0a46aefa
commit
a7c00a0943
5 changed files with 98 additions and 56 deletions
|
|
@ -180,5 +180,22 @@ class LowSpaceUserdata {
|
||||||
uint64_t bsize_ = 0;
|
uint64_t bsize_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool IsVirtualAbEnabled();
|
||||||
|
|
||||||
|
#define SKIP_IF_NON_VIRTUAL_AB() \
|
||||||
|
do { \
|
||||||
|
if (!IsVirtualAbEnabled()) GTEST_SKIP() << "Test for Virtual A/B devices only"; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define RETURN_IF_NON_VIRTUAL_AB_MSG(msg) \
|
||||||
|
do { \
|
||||||
|
if (!IsVirtualAbEnabled()) { \
|
||||||
|
std::cerr << (msg); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define RETURN_IF_NON_VIRTUAL_AB() RETURN_IF_NON_VIRTUAL_AB_MSG("")
|
||||||
|
|
||||||
} // namespace snapshot
|
} // namespace snapshot
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,14 @@ namespace snapshot {
|
||||||
|
|
||||||
class PartitionCowCreatorTest : public ::testing::Test {
|
class PartitionCowCreatorTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
void SetUp() override { SnapshotTestPropertyFetcher::SetUp(); }
|
void SetUp() override {
|
||||||
void TearDown() override { SnapshotTestPropertyFetcher::TearDown(); }
|
SKIP_IF_NON_VIRTUAL_AB();
|
||||||
|
SnapshotTestPropertyFetcher::SetUp();
|
||||||
|
}
|
||||||
|
void TearDown() override {
|
||||||
|
RETURN_IF_NON_VIRTUAL_AB();
|
||||||
|
SnapshotTestPropertyFetcher::TearDown();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(PartitionCowCreatorTest, IntersectSelf) {
|
TEST_F(PartitionCowCreatorTest, IntersectSelf) {
|
||||||
|
|
@ -223,6 +229,8 @@ TEST_F(PartitionCowCreatorTest, Zero) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(DmSnapshotInternals, CowSizeCalculator) {
|
TEST(DmSnapshotInternals, CowSizeCalculator) {
|
||||||
|
SKIP_IF_NON_VIRTUAL_AB();
|
||||||
|
|
||||||
DmSnapCowSizeCalculator cc(512, 8);
|
DmSnapCowSizeCalculator cc(512, 8);
|
||||||
unsigned long int b;
|
unsigned long int b;
|
||||||
|
|
||||||
|
|
@ -286,7 +294,9 @@ struct OptimizeOperationTestParam {
|
||||||
std::optional<InstallOperation> expected_output;
|
std::optional<InstallOperation> expected_output;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OptimizeOperationTest : public ::testing::TestWithParam<OptimizeOperationTestParam> {};
|
class OptimizeOperationTest : public ::testing::TestWithParam<OptimizeOperationTestParam> {
|
||||||
|
void SetUp() override { SKIP_IF_NON_VIRTUAL_AB(); }
|
||||||
|
};
|
||||||
TEST_P(OptimizeOperationTest, Test) {
|
TEST_P(OptimizeOperationTest, Test) {
|
||||||
InstallOperation actual_output;
|
InstallOperation actual_output;
|
||||||
EXPECT_EQ(GetParam().expected_output.has_value(),
|
EXPECT_EQ(GetParam().expected_output.has_value(),
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,11 @@ namespace snapshot {
|
||||||
|
|
||||||
class SnapshotMetadataUpdaterTest : public ::testing::TestWithParam<uint32_t> {
|
class SnapshotMetadataUpdaterTest : public ::testing::TestWithParam<uint32_t> {
|
||||||
public:
|
public:
|
||||||
SnapshotMetadataUpdaterTest() {
|
SnapshotMetadataUpdaterTest() = default;
|
||||||
is_virtual_ab_ = android::base::GetBoolProperty("ro.virtual_ab.enabled", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
|
SKIP_IF_NON_VIRTUAL_AB();
|
||||||
|
|
||||||
target_slot_ = GetParam();
|
target_slot_ = GetParam();
|
||||||
target_suffix_ = SlotSuffixForSlotNumber(target_slot_);
|
target_suffix_ = SlotSuffixForSlotNumber(target_slot_);
|
||||||
SnapshotTestPropertyFetcher::SetUp(SlotSuffixForSlotNumber(1 - target_slot_));
|
SnapshotTestPropertyFetcher::SetUp(SlotSuffixForSlotNumber(1 - target_slot_));
|
||||||
|
|
@ -68,7 +68,11 @@ class SnapshotMetadataUpdaterTest : public ::testing::TestWithParam<uint32_t> {
|
||||||
ASSERT_TRUE(FillFakeMetadata(builder_.get(), manifest_, target_suffix_));
|
ASSERT_TRUE(FillFakeMetadata(builder_.get(), manifest_, target_suffix_));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TearDown() override { SnapshotTestPropertyFetcher::TearDown(); }
|
void TearDown() override {
|
||||||
|
RETURN_IF_NON_VIRTUAL_AB();
|
||||||
|
|
||||||
|
SnapshotTestPropertyFetcher::TearDown();
|
||||||
|
}
|
||||||
|
|
||||||
// Append suffix to name.
|
// Append suffix to name.
|
||||||
std::string T(std::string_view name) { return std::string(name) + target_suffix_; }
|
std::string T(std::string_view name) { return std::string(name) + target_suffix_; }
|
||||||
|
|
@ -127,7 +131,6 @@ class SnapshotMetadataUpdaterTest : public ::testing::TestWithParam<uint32_t> {
|
||||||
<< ".";
|
<< ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_virtual_ab_;
|
|
||||||
std::unique_ptr<MetadataBuilder> builder_;
|
std::unique_ptr<MetadataBuilder> builder_;
|
||||||
uint32_t target_slot_;
|
uint32_t target_slot_;
|
||||||
std::string target_suffix_;
|
std::string target_suffix_;
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,7 @@ void MountMetadata();
|
||||||
|
|
||||||
class SnapshotTest : public ::testing::Test {
|
class SnapshotTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
SnapshotTest() : dm_(DeviceMapper::Instance()) {
|
SnapshotTest() : dm_(DeviceMapper::Instance()) {}
|
||||||
is_virtual_ab_ = android::base::GetBoolProperty("ro.virtual_ab.enabled", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is exposed for main.
|
// This is exposed for main.
|
||||||
void Cleanup() {
|
void Cleanup() {
|
||||||
|
|
@ -95,7 +93,7 @@ class SnapshotTest : public ::testing::Test {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
if (!is_virtual_ab_) GTEST_SKIP() << "Test for Virtual A/B devices only";
|
SKIP_IF_NON_VIRTUAL_AB();
|
||||||
|
|
||||||
SnapshotTestPropertyFetcher::SetUp();
|
SnapshotTestPropertyFetcher::SetUp();
|
||||||
InitializeState();
|
InitializeState();
|
||||||
|
|
@ -106,7 +104,7 @@ class SnapshotTest : public ::testing::Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TearDown() override {
|
void TearDown() override {
|
||||||
if (!is_virtual_ab_) return;
|
RETURN_IF_NON_VIRTUAL_AB();
|
||||||
|
|
||||||
lock_ = nullptr;
|
lock_ = nullptr;
|
||||||
|
|
||||||
|
|
@ -341,7 +339,6 @@ class SnapshotTest : public ::testing::Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr std::chrono::milliseconds snapshot_timeout_ = 5s;
|
static constexpr std::chrono::milliseconds snapshot_timeout_ = 5s;
|
||||||
bool is_virtual_ab_;
|
|
||||||
DeviceMapper& dm_;
|
DeviceMapper& dm_;
|
||||||
std::unique_ptr<SnapshotManager::LockedFile> lock_;
|
std::unique_ptr<SnapshotManager::LockedFile> lock_;
|
||||||
android::fiemap::IImageManager* image_manager_ = nullptr;
|
android::fiemap::IImageManager* image_manager_ = nullptr;
|
||||||
|
|
@ -722,11 +719,13 @@ class LockTestConsumer {
|
||||||
class LockTest : public ::testing::Test {
|
class LockTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
void SetUp() {
|
void SetUp() {
|
||||||
|
SKIP_IF_NON_VIRTUAL_AB();
|
||||||
first_consumer.StartHandleRequestsInBackground();
|
first_consumer.StartHandleRequestsInBackground();
|
||||||
second_consumer.StartHandleRequestsInBackground();
|
second_consumer.StartHandleRequestsInBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
|
RETURN_IF_NON_VIRTUAL_AB();
|
||||||
EXPECT_TRUE(first_consumer.MakeRequest(Request::EXIT));
|
EXPECT_TRUE(first_consumer.MakeRequest(Request::EXIT));
|
||||||
EXPECT_TRUE(second_consumer.MakeRequest(Request::EXIT));
|
EXPECT_TRUE(second_consumer.MakeRequest(Request::EXIT));
|
||||||
}
|
}
|
||||||
|
|
@ -770,7 +769,7 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
class SnapshotUpdateTest : public SnapshotTest {
|
class SnapshotUpdateTest : public SnapshotTest {
|
||||||
public:
|
public:
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
if (!is_virtual_ab_) GTEST_SKIP() << "Test for Virtual A/B devices only";
|
SKIP_IF_NON_VIRTUAL_AB();
|
||||||
|
|
||||||
SnapshotTest::SetUp();
|
SnapshotTest::SetUp();
|
||||||
Cleanup();
|
Cleanup();
|
||||||
|
|
@ -832,7 +831,7 @@ class SnapshotUpdateTest : public SnapshotTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void TearDown() override {
|
void TearDown() override {
|
||||||
if (!is_virtual_ab_) return;
|
RETURN_IF_NON_VIRTUAL_AB();
|
||||||
|
|
||||||
Cleanup();
|
Cleanup();
|
||||||
SnapshotTest::TearDown();
|
SnapshotTest::TearDown();
|
||||||
|
|
@ -1365,13 +1364,17 @@ TEST_F(SnapshotUpdateTest, MergeCannotRemoveCow) {
|
||||||
ASSERT_EQ(UpdateState::MergeCompleted, init->ProcessUpdateState());
|
ASSERT_EQ(UpdateState::MergeCompleted, init->ProcessUpdateState());
|
||||||
}
|
}
|
||||||
|
|
||||||
class MetadataMountedTest : public SnapshotUpdateTest {
|
class MetadataMountedTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
|
// This is so main() can instantiate this to invoke Cleanup.
|
||||||
|
virtual void TestBody() override {}
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
|
SKIP_IF_NON_VIRTUAL_AB();
|
||||||
metadata_dir_ = test_device->GetMetadataDir();
|
metadata_dir_ = test_device->GetMetadataDir();
|
||||||
ASSERT_TRUE(ReadDefaultFstab(&fstab_));
|
ASSERT_TRUE(ReadDefaultFstab(&fstab_));
|
||||||
}
|
}
|
||||||
void TearDown() override {
|
void TearDown() override {
|
||||||
|
RETURN_IF_NON_VIRTUAL_AB();
|
||||||
SetUp();
|
SetUp();
|
||||||
// Remount /metadata
|
// Remount /metadata
|
||||||
test_device->set_recovery(false);
|
test_device->set_recovery(false);
|
||||||
|
|
@ -1702,8 +1705,6 @@ class FlashAfterUpdateTest : public SnapshotUpdateTest,
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_P(FlashAfterUpdateTest, FlashSlotAfterUpdate) {
|
TEST_P(FlashAfterUpdateTest, FlashSlotAfterUpdate) {
|
||||||
if (!is_virtual_ab_) GTEST_SKIP() << "Test for Virtual A/B devices only";
|
|
||||||
|
|
||||||
// OTA client blindly unmaps all partitions that are possibly mapped.
|
// OTA client blindly unmaps all partitions that are possibly mapped.
|
||||||
for (const auto& name : {"sys_b", "vnd_b", "prd_b"}) {
|
for (const auto& name : {"sys_b", "vnd_b", "prd_b"}) {
|
||||||
ASSERT_TRUE(sm->UnmapUpdateSnapshot(name));
|
ASSERT_TRUE(sm->UnmapUpdateSnapshot(name));
|
||||||
|
|
@ -1803,14 +1804,13 @@ INSTANTIATE_TEST_SUITE_P(Snapshot, FlashAfterUpdateTest, Combine(Values(0, 1), B
|
||||||
class ImageManagerTest : public SnapshotTest, public WithParamInterface<uint64_t> {
|
class ImageManagerTest : public SnapshotTest, public WithParamInterface<uint64_t> {
|
||||||
protected:
|
protected:
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
if (!is_virtual_ab_) GTEST_SKIP() << "Test for Virtual A/B devices only";
|
SKIP_IF_NON_VIRTUAL_AB();
|
||||||
|
|
||||||
SnapshotTest::SetUp();
|
SnapshotTest::SetUp();
|
||||||
userdata_ = std::make_unique<LowSpaceUserdata>();
|
userdata_ = std::make_unique<LowSpaceUserdata>();
|
||||||
ASSERT_TRUE(userdata_->Init(GetParam()));
|
ASSERT_TRUE(userdata_->Init(GetParam()));
|
||||||
}
|
}
|
||||||
void TearDown() override {
|
void TearDown() override {
|
||||||
if (!is_virtual_ab_) return;
|
RETURN_IF_NON_VIRTUAL_AB();
|
||||||
return; // BUG(149738928)
|
return; // BUG(149738928)
|
||||||
|
|
||||||
EXPECT_TRUE(!image_manager_->BackingImageExists(kImageName) ||
|
EXPECT_TRUE(!image_manager_->BackingImageExists(kImageName) ||
|
||||||
|
|
@ -1852,11 +1852,6 @@ std::vector<uint64_t> ImageManagerTestParams() {
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(ImageManagerTest, ImageManagerTest, ValuesIn(ImageManagerTestParams()));
|
INSTANTIATE_TEST_SUITE_P(ImageManagerTest, ImageManagerTest, ValuesIn(ImageManagerTestParams()));
|
||||||
|
|
||||||
} // namespace snapshot
|
|
||||||
} // namespace android
|
|
||||||
|
|
||||||
using namespace android::snapshot;
|
|
||||||
|
|
||||||
bool Mkdir(const std::string& path) {
|
bool Mkdir(const std::string& path) {
|
||||||
if (mkdir(path.c_str(), 0700) && errno != EEXIST) {
|
if (mkdir(path.c_str(), 0700) && errno != EEXIST) {
|
||||||
std::cerr << "Could not mkdir " << path << ": " << strerror(errno) << std::endl;
|
std::cerr << "Could not mkdir " << path << ": " << strerror(errno) << std::endl;
|
||||||
|
|
@ -1865,8 +1860,21 @@ bool Mkdir(const std::string& path) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
class SnapshotTestEnvironment : public ::testing::Environment {
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
public:
|
||||||
|
~SnapshotTestEnvironment() override {}
|
||||||
|
void SetUp() override;
|
||||||
|
void TearDown() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<IImageManager> super_images_;
|
||||||
|
};
|
||||||
|
|
||||||
|
void SnapshotTestEnvironment::SetUp() {
|
||||||
|
// b/163082876: GTEST_SKIP in Environment will make atest report incorrect results. Until
|
||||||
|
// that is fixed, don't call GTEST_SKIP here, but instead call GTEST_SKIP in individual test
|
||||||
|
// suites.
|
||||||
|
RETURN_IF_NON_VIRTUAL_AB_MSG("Virtual A/B is not enabled, skipping global setup.\n");
|
||||||
|
|
||||||
std::vector<std::string> paths = {
|
std::vector<std::string> paths = {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
@ -1879,18 +1887,13 @@ int main(int argc, char** argv) {
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
for (const auto& path : paths) {
|
for (const auto& path : paths) {
|
||||||
if (!Mkdir(path)) {
|
ASSERT_TRUE(Mkdir(path));
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create this once, otherwise, gsid will start/stop between each test.
|
// Create this once, otherwise, gsid will start/stop between each test.
|
||||||
test_device = new TestDeviceInfo();
|
test_device = new TestDeviceInfo();
|
||||||
sm = SnapshotManager::New(test_device);
|
sm = SnapshotManager::New(test_device);
|
||||||
if (!sm) {
|
ASSERT_NE(nullptr, sm) << "Could not create snapshot manager";
|
||||||
std::cerr << "Could not create snapshot manager\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up previous run.
|
// Clean up previous run.
|
||||||
MetadataMountedTest().TearDown();
|
MetadataMountedTest().TearDown();
|
||||||
|
|
@ -1898,31 +1901,35 @@ int main(int argc, char** argv) {
|
||||||
SnapshotTest().Cleanup();
|
SnapshotTest().Cleanup();
|
||||||
|
|
||||||
// Use a separate image manager for our fake super partition.
|
// Use a separate image manager for our fake super partition.
|
||||||
auto super_images = IImageManager::Open("ota/test/super", 10s);
|
super_images_ = IImageManager::Open("ota/test/super", 10s);
|
||||||
if (!super_images) {
|
ASSERT_NE(nullptr, super_images_) << "Could not create image manager";
|
||||||
std::cerr << "Could not create image manager\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up any old copy.
|
// Clean up any old copy.
|
||||||
DeleteBackingImage(super_images.get(), "fake-super");
|
DeleteBackingImage(super_images_.get(), "fake-super");
|
||||||
|
|
||||||
// Create and map the fake super partition.
|
// Create and map the fake super partition.
|
||||||
static constexpr int kImageFlags =
|
static constexpr int kImageFlags =
|
||||||
IImageManager::CREATE_IMAGE_DEFAULT | IImageManager::CREATE_IMAGE_ZERO_FILL;
|
IImageManager::CREATE_IMAGE_DEFAULT | IImageManager::CREATE_IMAGE_ZERO_FILL;
|
||||||
if (!super_images->CreateBackingImage("fake-super", kSuperSize, kImageFlags)) {
|
ASSERT_TRUE(super_images_->CreateBackingImage("fake-super", kSuperSize, kImageFlags))
|
||||||
std::cerr << "Could not create fake super partition\n";
|
<< "Could not create fake super partition";
|
||||||
return 1;
|
|
||||||
}
|
ASSERT_TRUE(super_images_->MapImageDevice("fake-super", 10s, &fake_super))
|
||||||
if (!super_images->MapImageDevice("fake-super", 10s, &fake_super)) {
|
<< "Could not map fake super partition";
|
||||||
std::cerr << "Could not map fake super partition\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
test_device->set_fake_super(fake_super);
|
test_device->set_fake_super(fake_super);
|
||||||
|
}
|
||||||
auto result = RUN_ALL_TESTS();
|
|
||||||
|
void SnapshotTestEnvironment::TearDown() {
|
||||||
DeleteBackingImage(super_images.get(), "fake-super");
|
RETURN_IF_NON_VIRTUAL_AB();
|
||||||
|
if (super_images_ != nullptr) {
|
||||||
return result;
|
DeleteBackingImage(super_images_.get(), "fake-super");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace snapshot
|
||||||
|
} // namespace android
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
::testing::AddGlobalTestEnvironment(new ::android::snapshot::SnapshotTestEnvironment());
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
|
#include <android-base/properties.h>
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
#include <android-base/unique_fd.h>
|
#include <android-base/unique_fd.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
@ -241,5 +242,9 @@ uint64_t LowSpaceUserdata::bsize() const {
|
||||||
return bsize_;
|
return bsize_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsVirtualAbEnabled() {
|
||||||
|
return android::base::GetBoolProperty("ro.virtual_ab.enabled", false);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace snapshot
|
} // namespace snapshot
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue