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
diff --git a/fastboot/fuzzy_fastboot/fixtures.cpp b/fastboot/fuzzy_fastboot/fixtures.cpp
index c23da01..bc13a8c 100644
--- a/fastboot/fuzzy_fastboot/fixtures.cpp
+++ b/fastboot/fuzzy_fastboot/fixtures.cpp
@@ -59,7 +59,7 @@
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 @@
// 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 @@
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<UsbTransport> usb(usb_open(matcher, USB_TIMEOUT));
if (usb)
@@ -172,7 +174,9 @@
;
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<UsbTransport> usb(usb_open(matcher, USB_TIMEOUT));
if (usb) {
@@ -238,6 +242,7 @@
std::string FastBootTest::cb_scratch = "";
std::string FastBootTest::initial_slot = "";
int FastBootTest::serial_port = 0;
+std::string FastBootTest::device_serial = "";
template <bool UNLOCKED>
void ModeTest<UNLOCKED>::SetUp() {
diff --git a/fastboot/fuzzy_fastboot/fixtures.h b/fastboot/fuzzy_fastboot/fixtures.h
index 7c8d54d..c71c897 100644
--- a/fastboot/fuzzy_fastboot/fixtures.h
+++ b/fastboot/fuzzy_fastboot/fixtures.h
@@ -43,9 +43,10 @@
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 7ffc7d5..82d5cc9 100644
--- a/fastboot/fuzzy_fastboot/main.cpp
+++ b/fastboot/fuzzy_fastboot/main.cpp
@@ -162,7 +162,7 @@
// 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 @@
fastboot::GenerateXmlTests(fastboot::config);
}
+ if (args.find("serial") != args.end()) {
+ fastboot::FastBootTest::device_serial = args.at("serial");
+ }
+
setbuf(stdout, NULL); // no buffering
printf("<Waiting for Device>\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) {