Add a test for logical partitions.

Test: ./fuzzy_fastboot --gtest_filter=LogicalPartitionCompliance*
Bug: 117220134

Change-Id: Ib68f98ec5c8c402f9a80139134a0118ab65f8cd3
This commit is contained in:
Hridya Valsaraju 2019-03-16 21:25:01 -07:00
parent aaee497db2
commit 68e639ecf6
3 changed files with 57 additions and 18 deletions

View file

@ -55,6 +55,8 @@
#include "test_utils.h"
#include "usb_transport_sniffer.h"
using namespace std::literals::chrono_literals;
namespace fastboot {
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) {
if (!fb) {
return;
@ -197,25 +219,8 @@ void FastBootTest::SetLockState(bool unlock, bool assert_change) {
std::string cmd = unlock ? "unlock" : "lock";
ASSERT_EQ(fb->RawCommand("flashing " + cmd, &resp), SUCCESS)
<< "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());
while (UsbStillAvailible())
; // 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));
ReconnectFastbootDevice();
if (assert_change) {
ASSERT_EQ(fb->GetVar("unlocked", &resp), SUCCESS) << "getvar:unlocked failed";
ASSERT_EQ(resp, unlock ? "yes" : "no")

View file

@ -48,6 +48,7 @@ class FastBootTest : public testing::Test {
static int MatchFastboot(usb_ifc_info* info, const char* local_serial = nullptr);
bool UsbStillAvailible();
bool UserSpaceFastboot();
void ReconnectFastbootDevice();
protected:
RetCode DownloadCommand(uint32_t size, std::string* response = nullptr,
@ -86,6 +87,7 @@ class Fuzz : public ModeTest<true> {
// differently
class BasicFunctionality : public ModeTest<true> {};
class Conformance : public ModeTest<true> {};
class LogicalPartitionCompliance : public ModeTest<true> {};
class UnlockPermissions : public ModeTest<true> {};
class LockPermissions : public ModeTest<false> {};

View file

@ -176,6 +176,38 @@ TEST(USBFunctionality, USBConnect) {
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
TEST_F(Conformance, GetVar) {