/* * Copyright (C) 2018 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #pragma once #include #include "fastboot_driver.h" #include "extensions.h" #include "transport_sniffer.h" namespace fastboot { const int USB_TIMEOUT = 30000; constexpr char USB_PORT_GONE[] = "The USB port has disappeared, this is usually due to the bootloader crashing"; class FastBootTest : public testing::Test { public: 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, std::vector* info = nullptr); RetCode SendBuffer(const std::vector& buf); RetCode HandleResponse(std::string* response = nullptr, std::vector* info = nullptr, int* dsize = nullptr); void SetUp() override; void TearDown() override; void TearDownSerial(); void SetLockState(bool unlock, bool assert_change = true); std::unique_ptr transport; std::unique_ptr fb; private: // This is an annoying hack static std::string cb_scratch; static std::string device_path; static std::string initial_slot; }; template class ModeTest : public FastBootTest { protected: void SetUp() override; }; class Fuzz : public ModeTest { protected: void TearDown() override; }; // These derived classes without overrides serve no purpose other than to allow gtest to name them // differently class BasicFunctionality : public ModeTest {}; class Conformance : public ModeTest {}; class LogicalPartitionCompliance : public ModeTest {}; class UnlockPermissions : public ModeTest {}; class LockPermissions : public ModeTest {}; // Magic C++ double inheritance class ExtensionsGetVarConformance : public ModeTest, public ::testing::WithParamInterface< std::pair> {}; class ExtensionsOemConformance : public ModeTest, public ::testing::WithParamInterface< std::tuple> {}; class ExtensionsPackedValid : public ModeTest, public ::testing::WithParamInterface< std::pair> {}; class ExtensionsPackedInvalid : public ModeTest, public ::testing::WithParamInterface< std::pair> {}; template class ExtensionsPartition : public FastBootTest, public ::testing::WithParamInterface< std::pair> { protected: void SetUp() override; int64_t part_size; int64_t max_flash; int64_t max_dl; std::vector real_parts; // includes the slots }; class AnyPartition : public ExtensionsPartition {}; class WriteablePartition : public ExtensionsPartition {}; class WriteHashablePartition : public ExtensionsPartition {}; class WriteHashNonParsedPartition : public ExtensionsPartition {}; class FuzzWriteablePartition : public ExtensionsPartition {}; class FuzzWriteableParsedPartition : public ExtensionsPartition {}; class FuzzAnyPartitionLocked : public ExtensionsPartition {}; class UserdataPartition : public ExtensionsPartition {}; class SparseTestPartition : public ExtensionsPartition {}; } // end namespace fastboot