Merge "Add a test for logical partitions."
This commit is contained in:
commit
b0f125d581
3 changed files with 57 additions and 18 deletions
|
|
@ -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")
|
||||||
|
|
|
||||||
|
|
@ -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> {};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,38 @@ TEST(USBFunctionality, USBConnect) {
|
||||||
delete transport;
|
delete transport;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 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) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue