Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea5c4aa4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Allow fuzzy_fastboot test devices over internet" into android10-tests-dev

parents db5c1bc4 b0a06daa
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -297,3 +297,7 @@ int ClientUsbTransport::Close() {
    CloseFunctionFs(handle_.get());
    return 0;
}

int ClientUsbTransport::Reset() {
    return 0;
}
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ class ClientUsbTransport : public Transport {
    ssize_t Read(void* data, size_t len) override;
    ssize_t Write(const void* data, size_t len) override;
    int Close() override;
    int Reset() override;

  private:
    std::unique_ptr<usb_handle> handle_;
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ cc_test_host {
  srcs: [
    "main.cpp",
    "extensions.cpp",
    "usb_transport_sniffer.cpp",
    "transport_sniffer.cpp",
    "fixtures.cpp",
    "test_utils.cpp",
  ],
+51 −12
Original line number Diff line number Diff line
@@ -48,12 +48,13 @@
#include <gtest/gtest.h>

#include "fastboot_driver.h"
#include "tcp.h"
#include "usb.h"

#include "extensions.h"
#include "fixtures.h"
#include "test_utils.h"
#include "usb_transport_sniffer.h"
#include "transport_sniffer.h"

using namespace std::literals::chrono_literals;

@@ -74,7 +75,14 @@ int FastBootTest::MatchFastboot(usb_ifc_info* info, const std::string& local_ser
    return 0;
}

bool FastBootTest::IsFastbootOverTcp() {
    // serial contains ":" is treated as host ip and port number
    return (device_serial.find(":") != std::string::npos);
}

bool FastBootTest::UsbStillAvailible() {
    if (IsFastbootOverTcp()) return true;

    // For some reason someone decided to prefix the path with "usb:"
    std::string prefix("usb:");
    if (std::equal(prefix.begin(), prefix.end(), device_path.begin())) {
@@ -113,16 +121,20 @@ void FastBootTest::SetUp() {
        ASSERT_TRUE(UsbStillAvailible());  // The device disconnected
    }

    if (IsFastbootOverTcp()) {
        ConnectTcpFastbootDevice();
    } else {
        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)
            transport = std::unique_ptr<UsbTransportSniffer>(
                    new UsbTransportSniffer(std::move(usb), serial_port));
                transport = std::unique_ptr<TransportSniffer>(
                        new TransportSniffer(std::move(usb), serial_port));
            std::this_thread::sleep_for(std::chrono::milliseconds(10));
        }
    }

    ASSERT_TRUE(transport);  // no nullptr

@@ -154,6 +166,8 @@ void FastBootTest::TearDown() {

// TODO, this should eventually be piped to a file instead of stdout
void FastBootTest::TearDownSerial() {
    if (IsFastbootOverTcp()) return;

    if (!transport) return;
    // One last read from serial
    transport->ProcessSerial();
@@ -167,9 +181,34 @@ void FastBootTest::TearDownSerial() {
    }
}

void FastBootTest::ConnectTcpFastbootDevice() {
    std::size_t found = device_serial.find(":");
    if (found != std::string::npos) {
        for (int i = 0; i < MAX_TCP_TRIES && !transport; i++) {
            std::string error;
            std::unique_ptr<Transport> tcp(
                    tcp::Connect(device_serial.substr(0, found), tcp::kDefaultPort, &error)
                            .release());
            if (tcp)
                transport =
                        std::unique_ptr<TransportSniffer>(new TransportSniffer(std::move(tcp), 0));
            if (transport != nullptr) break;
            std::this_thread::sleep_for(std::chrono::milliseconds(10));
        }
    }
}

void FastBootTest::ReconnectFastbootDevice() {
    fb.reset();
    transport.reset();

    if (IsFastbootOverTcp()) {
        ConnectTcpFastbootDevice();
        device_path = cb_scratch;
        fb = std::unique_ptr<FastBootDriver>(new FastBootDriver(transport.get(), {}, true));
        return;
    }

    while (UsbStillAvailible())
        ;
    printf("WAITING FOR DEVICE\n");
@@ -180,8 +219,8 @@ void FastBootTest::ReconnectFastbootDevice() {
    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));
            transport = std::unique_ptr<TransportSniffer>(
                    new TransportSniffer(std::move(usb), serial_port));
        }
        std::this_thread::sleep_for(1s);
    }
+5 −2
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@
#include "fastboot_driver.h"

#include "extensions.h"
#include "usb_transport_sniffer.h"
#include "transport_sniffer.h"

namespace fastboot {

@@ -45,11 +45,14 @@ class FastBootTest : public testing::Test {
    static int serial_port;
    static std::string device_serial;
    static constexpr int MAX_USB_TRIES = 10;
    static constexpr int MAX_TCP_TRIES = 6000;

    static int MatchFastboot(usb_ifc_info* info, const std::string& local_serial = "");
    static bool IsFastbootOverTcp();
    bool UsbStillAvailible();
    bool UserSpaceFastboot();
    void ReconnectFastbootDevice();
    void ConnectTcpFastbootDevice();

  protected:
    RetCode DownloadCommand(uint32_t size, std::string* response = nullptr,
@@ -64,7 +67,7 @@ class FastBootTest : public testing::Test {
    void TearDownSerial();
    void SetLockState(bool unlock, bool assert_change = true);

    std::unique_ptr<UsbTransportSniffer> transport;
    std::unique_ptr<TransportSniffer> transport;
    std::unique_ptr<FastBootDriver> fb;

  private:
Loading