From b9051a3e6559b14759015d679c97d0e9e5fad9a4 Mon Sep 17 00:00:00 2001 From: Hridya Valsaraju Date: Wed, 10 Apr 2019 16:31:31 -0700 Subject: [PATCH] Allow fuzzy_fastboot number to run for a specific device serial number Test: ./fuzzy_fastboot --serial=826X003L --gtest_filter=*Logical* Bug: 117181762 Change-Id: I9dec510aa604b7994f25ce26edb87d7f6ec3e875 --- fastboot/fuzzy_fastboot/fixtures.cpp | 15 ++++++++++----- fastboot/fuzzy_fastboot/fixtures.h | 3 ++- fastboot/fuzzy_fastboot/main.cpp | 8 ++++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/fastboot/fuzzy_fastboot/fixtures.cpp b/fastboot/fuzzy_fastboot/fixtures.cpp index c23da01a2..bc13a8c4e 100644 --- a/fastboot/fuzzy_fastboot/fixtures.cpp +++ b/fastboot/fuzzy_fastboot/fixtures.cpp @@ -59,7 +59,7 @@ using namespace std::literals::chrono_literals; namespace fastboot { -int FastBootTest::MatchFastboot(usb_ifc_info* info, const char* local_serial) { +int FastBootTest::MatchFastboot(usb_ifc_info* info, const std::string& local_serial) { if (info->ifc_class != 0xff || info->ifc_subclass != 0x42 || info->ifc_protocol != 0x03) { return -1; } @@ -68,8 +68,8 @@ int FastBootTest::MatchFastboot(usb_ifc_info* info, const char* local_serial) { // require matching serial number or device path if requested // at the command line with the -s option. - if (local_serial && (strcmp(local_serial, info->serial_number) != 0 && - strcmp(local_serial, info->device_path) != 0)) + if (!local_serial.empty() && local_serial != info->serial_number && + local_serial != info->device_path) return -1; return 0; } @@ -113,7 +113,9 @@ void FastBootTest::SetUp() { ASSERT_TRUE(UsbStillAvailible()); // The device disconnected } - const auto matcher = [](usb_ifc_info* info) -> int { return MatchFastboot(info, nullptr); }; + const auto matcher = [](usb_ifc_info* info) -> int { + return MatchFastboot(info, device_serial); + }; for (int i = 0; i < MAX_USB_TRIES && !transport; i++) { std::unique_ptr usb(usb_open(matcher, USB_TIMEOUT)); if (usb) @@ -172,7 +174,9 @@ void FastBootTest::ReconnectFastbootDevice() { ; printf("WAITING FOR DEVICE\n"); // Need to wait for device - const auto matcher = [](usb_ifc_info* info) -> int { return MatchFastboot(info, nullptr); }; + const auto matcher = [](usb_ifc_info* info) -> int { + return MatchFastboot(info, device_serial); + }; while (!transport) { std::unique_ptr usb(usb_open(matcher, USB_TIMEOUT)); if (usb) { @@ -238,6 +242,7 @@ std::string FastBootTest::device_path = ""; std::string FastBootTest::cb_scratch = ""; std::string FastBootTest::initial_slot = ""; int FastBootTest::serial_port = 0; +std::string FastBootTest::device_serial = ""; template void ModeTest::SetUp() { diff --git a/fastboot/fuzzy_fastboot/fixtures.h b/fastboot/fuzzy_fastboot/fixtures.h index 7c8d54d27..c71c89766 100644 --- a/fastboot/fuzzy_fastboot/fixtures.h +++ b/fastboot/fuzzy_fastboot/fixtures.h @@ -43,9 +43,10 @@ constexpr char USB_PORT_GONE[] = class FastBootTest : public testing::Test { public: static int serial_port; + static std::string device_serial; static constexpr int MAX_USB_TRIES = 10; - static int MatchFastboot(usb_ifc_info* info, const char* local_serial = nullptr); + static int MatchFastboot(usb_ifc_info* info, const std::string& local_serial = ""); bool UsbStillAvailible(); bool UserSpaceFastboot(); void ReconnectFastbootDevice(); diff --git a/fastboot/fuzzy_fastboot/main.cpp b/fastboot/fuzzy_fastboot/main.cpp index 7ffc7d57c..82d5cc904 100644 --- a/fastboot/fuzzy_fastboot/main.cpp +++ b/fastboot/fuzzy_fastboot/main.cpp @@ -162,7 +162,7 @@ const auto not_allowed = [](char c) -> int { // Test that USB even works TEST(USBFunctionality, USBConnect) { const auto matcher = [](usb_ifc_info* info) -> int { - return FastBootTest::MatchFastboot(info, nullptr); + return FastBootTest::MatchFastboot(info, fastboot::FastBootTest::device_serial); }; Transport* transport = nullptr; for (int i = 0; i < FastBootTest::MAX_USB_TRIES && !transport; i++) { @@ -1728,10 +1728,14 @@ int main(int argc, char** argv) { fastboot::GenerateXmlTests(fastboot::config); } + if (args.find("serial") != args.end()) { + fastboot::FastBootTest::device_serial = args.at("serial"); + } + setbuf(stdout, NULL); // no buffering printf("\n"); const auto matcher = [](usb_ifc_info* info) -> int { - return fastboot::FastBootTest::MatchFastboot(info, nullptr); + return fastboot::FastBootTest::MatchFastboot(info, fastboot::FastBootTest::device_serial); }; Transport* transport = nullptr; while (!transport) {