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

Commit 5cd09cb2 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 5392835 from cb7f2dde to qt-release

Change-Id: Iee6e0753afd500f14a79e06220f32a945ad80fd2
parents 19b83992 cb7f2dde
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -295,6 +295,10 @@ const std::map<std::string, int32_t> kBootReasonMap = {
    {"kernel_panic,_sde_encoder_phys_cmd_handle_ppdone_timeout", 168},
    {"kernel_panic,_sde_encoder_phys_cmd_handle_ppdone_timeout", 168},
    {"recovery,quiescent", 169},
    {"recovery,quiescent", 169},
    {"reboot,quiescent", 170},
    {"reboot,quiescent", 170},
    {"reboot,rtc", 171},
    {"reboot,dm-verity_device_corrupted", 172},
    {"reboot,dm-verity_enforcing", 173},
    {"reboot,keys_clear", 174},
};
};


// Converts a string value representing the reason the system booted to an
// Converts a string value representing the reason the system booted to an
+23 −18
Original line number Original line Diff line number Diff line
@@ -55,6 +55,8 @@
#include "test_utils.h"
#include "test_utils.h"
#include "usb_transport_sniffer.h"
#include "usb_transport_sniffer.h"


using namespace std::literals::chrono_literals;

namespace fastboot {
namespace fastboot {


int FastBootTest::MatchFastboot(usb_ifc_info* info, const char* local_serial) {
int FastBootTest::MatchFastboot(usb_ifc_info* info, const char* local_serial) {
@@ -159,6 +161,26 @@ void FastBootTest::TearDownSerial() {
    }
    }
}
}


void FastBootTest::ReconnectFastbootDevice() {
    fb.reset();
    transport.reset();
    while (UsbStillAvailible())
        ;
    printf("WAITING FOR DEVICE\n");
    // Need to wait for device
    const auto matcher = [](usb_ifc_info* info) -> int { return MatchFastboot(info, nullptr); };
    while (!transport) {
        std::unique_ptr<UsbTransport> usb(usb_open(matcher, USB_TIMEOUT));
        if (usb) {
            transport = std::unique_ptr<UsbTransportSniffer>(
                    new UsbTransportSniffer(std::move(usb), serial_port));
        }
        std::this_thread::sleep_for(1s);
    }
    device_path = cb_scratch;
    fb = std::unique_ptr<FastBootDriver>(new FastBootDriver(transport.get(), {}, true));
}

void FastBootTest::SetLockState(bool unlock, bool assert_change) {
void FastBootTest::SetLockState(bool unlock, bool assert_change) {
    if (!fb) {
    if (!fb) {
        return;
        return;
@@ -197,25 +219,8 @@ void FastBootTest::SetLockState(bool unlock, bool assert_change) {
        std::string cmd = unlock ? "unlock" : "lock";
        std::string cmd = unlock ? "unlock" : "lock";
        ASSERT_EQ(fb->RawCommand("flashing " + cmd, &resp), SUCCESS)
        ASSERT_EQ(fb->RawCommand("flashing " + cmd, &resp), SUCCESS)
                << "Attempting to change locked state, but 'flashing" + cmd + "' command failed";
                << "Attempting to change locked state, but 'flashing" + cmd + "' command failed";
        fb.reset();
        transport.reset();
        printf("PLEASE RESPOND TO PROMPT FOR '%sing' BOOTLOADER ON DEVICE\n", cmd.c_str());
        printf("PLEASE RESPOND TO PROMPT FOR '%sing' BOOTLOADER ON DEVICE\n", cmd.c_str());
        while (UsbStillAvailible())
        ReconnectFastbootDevice();
            ;  // Wait for disconnect
        printf("WAITING FOR DEVICE");
        // Need to wait for device
        const auto matcher = [](usb_ifc_info* info) -> int { return MatchFastboot(info, nullptr); };
        while (!transport) {
            std::unique_ptr<UsbTransport> usb(usb_open(matcher, USB_TIMEOUT));
            if (usb) {
                transport = std::unique_ptr<UsbTransportSniffer>(
                        new UsbTransportSniffer(std::move(usb), serial_port));
            }
            std::this_thread::sleep_for(std::chrono::milliseconds(1000));
            putchar('.');
        }
        device_path = cb_scratch;
        fb = std::unique_ptr<FastBootDriver>(new FastBootDriver(transport.get(), {}, true));
        if (assert_change) {
        if (assert_change) {
            ASSERT_EQ(fb->GetVar("unlocked", &resp), SUCCESS) << "getvar:unlocked failed";
            ASSERT_EQ(fb->GetVar("unlocked", &resp), SUCCESS) << "getvar:unlocked failed";
            ASSERT_EQ(resp, unlock ? "yes" : "no")
            ASSERT_EQ(resp, unlock ? "yes" : "no")
+2 −0
Original line number Original line Diff line number Diff line
@@ -48,6 +48,7 @@ class FastBootTest : public testing::Test {
    static int MatchFastboot(usb_ifc_info* info, const char* local_serial = nullptr);
    static int MatchFastboot(usb_ifc_info* info, const char* local_serial = nullptr);
    bool UsbStillAvailible();
    bool UsbStillAvailible();
    bool UserSpaceFastboot();
    bool UserSpaceFastboot();
    void ReconnectFastbootDevice();


  protected:
  protected:
    RetCode DownloadCommand(uint32_t size, std::string* response = nullptr,
    RetCode DownloadCommand(uint32_t size, std::string* response = nullptr,
@@ -86,6 +87,7 @@ class Fuzz : public ModeTest<true> {
// differently
// differently
class BasicFunctionality : public ModeTest<true> {};
class BasicFunctionality : public ModeTest<true> {};
class Conformance : public ModeTest<true> {};
class Conformance : public ModeTest<true> {};
class LogicalPartitionCompliance : public ModeTest<true> {};
class UnlockPermissions : public ModeTest<true> {};
class UnlockPermissions : public ModeTest<true> {};
class LockPermissions : public ModeTest<false> {};
class LockPermissions : public ModeTest<false> {};


+87 −0
Original line number Original line Diff line number Diff line
@@ -177,6 +177,93 @@ TEST(USBFunctionality, USBConnect) {
    }
    }
}
}


// Test commands related to super partition
TEST_F(LogicalPartitionCompliance, SuperPartition) {
    ASSERT_TRUE(UserSpaceFastboot());
    std::string partition_type;
    // getvar partition-type:super must fail for retrofit devices because the
    // partition does not exist.
    if (fb->GetVar("partition-type:super", &partition_type) == SUCCESS) {
        std::string is_logical;
        EXPECT_EQ(fb->GetVar("is-logical:super", &is_logical), SUCCESS)
                << "getvar is-logical:super failed";
        EXPECT_EQ(is_logical, "no") << "super must not be a logical partition";
        std::string super_name;
        EXPECT_EQ(fb->GetVar("super-partition-name", &super_name), SUCCESS)
                << "'getvar super-partition-name' failed";
        EXPECT_EQ(super_name, "super") << "'getvar super-partition-name' must return 'super' for "
                                          "device with a super partition";
    }
}

// Test 'fastboot getvar is-logical'
TEST_F(LogicalPartitionCompliance, GetVarIsLogical) {
    ASSERT_TRUE(UserSpaceFastboot());
    std::string has_slot;
    EXPECT_EQ(fb->GetVar("has-slot:system", &has_slot), SUCCESS) << "getvar has-slot:system failed";
    std::string is_logical_cmd;
    if (has_slot == "yes") {
        std::string current_slot;
        EXPECT_EQ(fb->GetVar("current-slot", &current_slot), SUCCESS)
                << "getvar current-slot failed";
        is_logical_cmd = "is-logical:system_" + current_slot;
    } else {
        is_logical_cmd = "is-logical:system";
    }
    std::string is_logical;
    EXPECT_EQ(fb->GetVar(is_logical_cmd, &is_logical), SUCCESS) << "getvar is-logical failed";
    ASSERT_EQ(is_logical, "yes");
}

TEST_F(LogicalPartitionCompliance, FastbootRebootTest) {
    ASSERT_TRUE(UserSpaceFastboot());
    GTEST_LOG_(INFO) << "Rebooting to bootloader mode";
    // Test 'fastboot reboot bootloader' from fastbootd
    fb->RebootTo("bootloader");

    // Test fastboot reboot fastboot from bootloader
    ReconnectFastbootDevice();
    ASSERT_FALSE(UserSpaceFastboot());
    GTEST_LOG_(INFO) << "Rebooting back to fastbootd mode";
    fb->RebootTo("fastboot");

    ReconnectFastbootDevice();
    ASSERT_TRUE(UserSpaceFastboot());
}

// Testing creation/resize/delete of logical partitions
TEST_F(LogicalPartitionCompliance, CreateResizeDeleteLP) {
    ASSERT_TRUE(UserSpaceFastboot());
    GTEST_LOG_(INFO) << "Testing 'fastboot create-logical-partition' command";
    EXPECT_EQ(fb->CreatePartition("test_partition_a", "0"), SUCCESS)
            << "create-logical-partition failed";
    GTEST_LOG_(INFO) << "Testing 'fastboot resize-logical-partition' command";
    EXPECT_EQ(fb->ResizePartition("test_partition_a", "4096"), SUCCESS)
            << "resize-logical-partition failed";
    std::vector<char> buf(4096);

    GTEST_LOG_(INFO) << "Flashing a logical partition..";
    EXPECT_EQ(fb->FlashPartition("test_partition_a", buf), SUCCESS)
            << "flash logical -partition failed";
    GTEST_LOG_(INFO) << "Rebooting to bootloader mode";
    // Reboot to bootloader mode and attempt to flash the logical partitions
    fb->RebootTo("bootloader");

    ReconnectFastbootDevice();
    ASSERT_FALSE(UserSpaceFastboot());
    GTEST_LOG_(INFO) << "Attempt to flash a logical partition..";
    EXPECT_EQ(fb->FlashPartition("test_partition", buf), DEVICE_FAIL)
            << "flash logical partition must fail in bootloader";
    GTEST_LOG_(INFO) << "Rebooting back to fastbootd mode";
    fb->RebootTo("fastboot");

    ReconnectFastbootDevice();
    ASSERT_TRUE(UserSpaceFastboot());
    GTEST_LOG_(INFO) << "Testing 'fastboot delete-logical-partition' command";
    EXPECT_EQ(fb->DeletePartition("test_partition_a"), SUCCESS)
            << "delete logical-partition failed";
}

// Conformance tests
// Conformance tests
TEST_F(Conformance, GetVar) {
TEST_F(Conformance, GetVar) {
    std::string product;
    std::string product;
+12 −3
Original line number Original line Diff line number Diff line
@@ -176,6 +176,15 @@ int main(int argc, char* argv[]) {
        fstab_read = android::fs_mgr::ReadFstabFromFile(fstab_file, &fstab);
        fstab_read = android::fs_mgr::ReadFstabFromFile(fstab_file, &fstab);
    } else {
    } else {
        fstab_read = android::fs_mgr::ReadDefaultFstab(&fstab);
        fstab_read = android::fs_mgr::ReadDefaultFstab(&fstab);
        // Manufacture a / entry from /proc/mounts if missing.
        if (!GetEntryForMountPoint(&fstab, "/system") && !GetEntryForMountPoint(&fstab, "/")) {
            android::fs_mgr::Fstab mounts;
            if (android::fs_mgr::ReadFstabFromFile("/proc/mounts", &mounts)) {
                if (auto entry = GetEntryForMountPoint(&mounts, "/")) {
                    if (entry->fs_type != "rootfs") fstab.emplace_back(*entry);
                }
            }
        }
    }
    }
    if (!fstab_read || fstab.empty()) {
    if (!fstab_read || fstab.empty()) {
        PLOG(ERROR) << "Failed to read fstab";
        PLOG(ERROR) << "Failed to read fstab";
@@ -211,21 +220,21 @@ int main(int argc, char* argv[]) {
        // Do we know about the partition?
        // Do we know about the partition?
        auto it = std::find_if(fstab.begin(), fstab.end(), find_part);
        auto it = std::find_if(fstab.begin(), fstab.end(), find_part);
        if (it == fstab.end()) {
        if (it == fstab.end()) {
            LOG(ERROR) << "Unknown partition " << partition << ", skipping";
            LOG(ERROR) << "Unknown partition " << argv[optind] << ", skipping";
            retval = UNKNOWN_PARTITION;
            retval = UNKNOWN_PARTITION;
            continue;
            continue;
        }
        }
        // Is that one covered by an existing overlayfs?
        // Is that one covered by an existing overlayfs?
        auto wrap = is_wrapped(overlayfs_candidates, *it);
        auto wrap = is_wrapped(overlayfs_candidates, *it);
        if (wrap) {
        if (wrap) {
            LOG(INFO) << "partition " << partition << " covered by overlayfs for "
            LOG(INFO) << "partition " << argv[optind] << " covered by overlayfs for "
                      << wrap->mount_point << ", switching";
                      << wrap->mount_point << ", switching";
            partition = system_mount_point(*wrap);
            partition = system_mount_point(*wrap);
        }
        }
        // Is it a remountable partition?
        // Is it a remountable partition?
        it = std::find_if(all.begin(), all.end(), find_part);
        it = std::find_if(all.begin(), all.end(), find_part);
        if (it == all.end()) {
        if (it == all.end()) {
            LOG(ERROR) << "Invalid partition " << partition << ", skipping";
            LOG(ERROR) << "Invalid partition " << argv[optind] << ", skipping";
            retval = INVALID_PARTITION;
            retval = INVALID_PARTITION;
            continue;
            continue;
        }
        }
Loading