Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3396e932 authored by Yifan Hong's avatar Yifan Hong
Browse files

libsnapshot: fix tests

- Add TestDeviceInfo(string, string) to avoid holding
the 'rebooted' TestDeviceInfo variable after ownership is
transferred

- OTA client calls BeginUpdate after unmapping partitions.

Test: run libsnapshot_test
Change-Id: Id37e34b421d728eb320c0e0906abef3b61897e7c
parent a1c1eb60
Loading
Loading
Loading
Loading
+8 −24
Original line number Diff line number Diff line
@@ -513,10 +513,7 @@ TEST_F(SnapshotTest, FirstStageMountAndMerge) {
    ASSERT_TRUE(sm->FinishedSnapshotWrites());
    ASSERT_TRUE(DestroyLogicalPartition("test_partition_b-base"));

    auto rebooted = new TestDeviceInfo(fake_super);
    rebooted->set_slot_suffix("_b");

    auto init = SnapshotManager::NewForFirstStageMount(rebooted);
    auto init = SnapshotManager::NewForFirstStageMount(new TestDeviceInfo(fake_super, "_b"));
    ASSERT_NE(init, nullptr);
    ASSERT_TRUE(init->NeedSnapshotsInFirstStageMount());
    ASSERT_TRUE(init->CreateLogicalAndSnapshotPartitions("super"));
@@ -559,10 +556,7 @@ TEST_F(SnapshotTest, FlashSuperDuringUpdate) {
    FormatFakeSuper();
    ASSERT_TRUE(CreatePartition("test_partition_b", kDeviceSize));

    auto rebooted = new TestDeviceInfo(fake_super);
    rebooted->set_slot_suffix("_b");

    auto init = SnapshotManager::NewForFirstStageMount(rebooted);
    auto init = SnapshotManager::NewForFirstStageMount(new TestDeviceInfo(fake_super, "_b"));
    ASSERT_NE(init, nullptr);
    ASSERT_TRUE(init->NeedSnapshotsInFirstStageMount());
    ASSERT_TRUE(init->CreateLogicalAndSnapshotPartitions("super"));
@@ -603,10 +597,7 @@ TEST_F(SnapshotTest, FlashSuperDuringMerge) {
    ASSERT_TRUE(sm->FinishedSnapshotWrites());
    ASSERT_TRUE(DestroyLogicalPartition("test_partition_b-base"));

    auto rebooted = new TestDeviceInfo(fake_super);
    rebooted->set_slot_suffix("_b");

    auto init = SnapshotManager::NewForFirstStageMount(rebooted);
    auto init = SnapshotManager::NewForFirstStageMount(new TestDeviceInfo(fake_super, "_b"));
    ASSERT_NE(init, nullptr);
    ASSERT_TRUE(init->NeedSnapshotsInFirstStageMount());
    ASSERT_TRUE(init->CreateLogicalAndSnapshotPartitions("super"));
@@ -761,9 +752,6 @@ class SnapshotUpdateTest : public SnapshotTest {
// Also test UnmapUpdateSnapshot unmaps everything.
// Also test first stage mount and merge after this.
TEST_F(SnapshotUpdateTest, FullUpdateFlow) {
    // OTA client calls BeginUpdate before doing anything.
    ASSERT_TRUE(sm->BeginUpdate());

    // OTA client blindly unmaps all partitions that are possibly mapped.
    for (const auto& name : {"sys_b", "vnd_b", "prd_b"}) {
        ASSERT_TRUE(sm->UnmapUpdateSnapshot(name));
@@ -774,6 +762,8 @@ TEST_F(SnapshotUpdateTest, FullUpdateFlow) {
    SetSize(vnd_, 4_MiB);
    SetSize(prd_, 4_MiB);

    // Execute the update.
    ASSERT_TRUE(sm->BeginUpdate());
    ASSERT_TRUE(sm->CreateUpdateSnapshots(manifest_));

    // Test that partitions prioritize using space in super.
@@ -812,9 +802,7 @@ TEST_F(SnapshotUpdateTest, FullUpdateFlow) {
    ASSERT_TRUE(UnmapAll());

    // After reboot, init does first stage mount.
    auto rebooted = new TestDeviceInfo(fake_super);
    rebooted->set_slot_suffix("_b");
    auto init = SnapshotManager::NewForFirstStageMount(rebooted);
    auto init = SnapshotManager::NewForFirstStageMount(new TestDeviceInfo(fake_super, "_b"));
    ASSERT_NE(init, nullptr);
    ASSERT_TRUE(init->NeedSnapshotsInFirstStageMount());
    ASSERT_TRUE(init->CreateLogicalAndSnapshotPartitions("super"));
@@ -965,9 +953,7 @@ TEST_F(SnapshotUpdateTest, TestRollback) {
    ASSERT_TRUE(UnmapAll());

    // After reboot, init does first stage mount.
    auto rebooted = new TestDeviceInfo(fake_super);
    rebooted->set_slot_suffix("_b");
    auto init = SnapshotManager::NewForFirstStageMount(rebooted);
    auto init = SnapshotManager::NewForFirstStageMount(new TestDeviceInfo(fake_super, "_b"));
    ASSERT_NE(init, nullptr);
    ASSERT_TRUE(init->NeedSnapshotsInFirstStageMount());
    ASSERT_TRUE(init->CreateLogicalAndSnapshotPartitions("super"));
@@ -979,9 +965,7 @@ TEST_F(SnapshotUpdateTest, TestRollback) {

    // Simulate shutting down the device again.
    ASSERT_TRUE(UnmapAll());
    rebooted = new TestDeviceInfo(fake_super);
    rebooted->set_slot_suffix("_a");
    init = SnapshotManager::NewForFirstStageMount(rebooted);
    init = SnapshotManager::NewForFirstStageMount(new TestDeviceInfo(fake_super, "_a"));
    ASSERT_NE(init, nullptr);
    ASSERT_FALSE(init->NeedSnapshotsInFirstStageMount());
    ASSERT_TRUE(init->CreateLogicalAndSnapshotPartitions("super"));
+4 −0
Original line number Diff line number Diff line
@@ -52,6 +52,10 @@ class TestDeviceInfo : public SnapshotManager::IDeviceInfo {
  public:
    TestDeviceInfo() {}
    explicit TestDeviceInfo(const std::string& fake_super) { set_fake_super(fake_super); }
    TestDeviceInfo(const std::string& fake_super, const std::string& slot_suffix)
        : TestDeviceInfo(fake_super) {
        set_slot_suffix(slot_suffix);
    }
    std::string GetGsidDir() const override { return "ota/test"s; }
    std::string GetMetadataDir() const override { return "/metadata/ota/test"s; }
    std::string GetSlotSuffix() const override { return slot_suffix_; }