Merge "Allow fuzzy_fastboot number to run for a specific device serial number" into qt-dev

This commit is contained in:
TreeHugger Robot 2019-04-15 20:57:18 +00:00 committed by Android (Google) Code Review
commit 1dd53f763b
3 changed files with 18 additions and 8 deletions

View file

@ -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<UsbTransport> 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<UsbTransport> 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 <bool UNLOCKED>
void ModeTest<UNLOCKED>::SetUp() {

View file

@ -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();

View file

@ -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++) {
@ -1738,10 +1738,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("<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) {