Merge "Adding fastboot_driver interface + mock"
This commit is contained in:
commit
3ac1e55e1e
4 changed files with 124 additions and 19 deletions
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <string>
|
||||
#include "fastboot_driver.h"
|
||||
#include "fastboot_driver_interface.h"
|
||||
#include "filesystem.h"
|
||||
#include "super_flash_helper.h"
|
||||
#include "util.h"
|
||||
|
|
|
@ -40,21 +40,13 @@
|
|||
#include <sparse/sparse.h>
|
||||
|
||||
#include "constants.h"
|
||||
#include "fastboot_driver_interface.h"
|
||||
#include "transport.h"
|
||||
|
||||
class Transport;
|
||||
|
||||
namespace fastboot {
|
||||
|
||||
enum RetCode : int {
|
||||
SUCCESS = 0,
|
||||
BAD_ARG,
|
||||
IO_ERROR,
|
||||
BAD_DEV_RESP,
|
||||
DEVICE_FAIL,
|
||||
TIMEOUT,
|
||||
};
|
||||
|
||||
struct DriverCallbacks {
|
||||
std::function<void(const std::string&)> prolog = [](const std::string&) {};
|
||||
std::function<void(int)> epilog = [](int) {};
|
||||
|
@ -62,7 +54,7 @@ struct DriverCallbacks {
|
|||
std::function<void(const std::string&)> text = [](const std::string&) {};
|
||||
};
|
||||
|
||||
class FastBootDriver {
|
||||
class FastBootDriver : public IFastBootDriver {
|
||||
friend class FastBootTest;
|
||||
|
||||
public:
|
||||
|
@ -77,9 +69,10 @@ class FastBootDriver {
|
|||
RetCode Boot(std::string* response = nullptr, std::vector<std::string>* info = nullptr);
|
||||
RetCode Continue(std::string* response = nullptr, std::vector<std::string>* info = nullptr);
|
||||
RetCode CreatePartition(const std::string& partition, const std::string& size);
|
||||
RetCode DeletePartition(const std::string& partition);
|
||||
RetCode DeletePartition(const std::string& partition) override;
|
||||
RetCode Download(const std::string& name, android::base::borrowed_fd fd, size_t size,
|
||||
std::string* response = nullptr, std::vector<std::string>* info = nullptr);
|
||||
std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr) override;
|
||||
RetCode Download(android::base::borrowed_fd fd, size_t size, std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr);
|
||||
RetCode Download(const std::string& name, const std::vector<char>& buf,
|
||||
|
@ -92,16 +85,17 @@ class FastBootDriver {
|
|||
RetCode Download(sparse_file* s, bool use_crc = false, std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr);
|
||||
RetCode Erase(const std::string& partition, std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr);
|
||||
std::vector<std::string>* info = nullptr) override;
|
||||
RetCode Flash(const std::string& partition, std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr);
|
||||
RetCode GetVar(const std::string& key, std::string* val,
|
||||
std::vector<std::string>* info = nullptr);
|
||||
std::vector<std::string>* info = nullptr) override;
|
||||
RetCode GetVarAll(std::vector<std::string>* response);
|
||||
RetCode Reboot(std::string* response = nullptr, std::vector<std::string>* info = nullptr);
|
||||
RetCode Reboot(std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr) override;
|
||||
RetCode RebootTo(std::string target, std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr);
|
||||
RetCode ResizePartition(const std::string& partition, const std::string& size);
|
||||
std::vector<std::string>* info = nullptr) override;
|
||||
RetCode ResizePartition(const std::string& partition, const std::string& size) override;
|
||||
RetCode SetActive(const std::string& slot, std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr);
|
||||
RetCode Upload(const std::string& outfile, std::string* response = nullptr,
|
||||
|
@ -115,7 +109,7 @@ class FastBootDriver {
|
|||
/* HIGHER LEVEL COMMANDS -- Composed of the commands above */
|
||||
RetCode FlashPartition(const std::string& partition, const std::vector<char>& data);
|
||||
RetCode FlashPartition(const std::string& partition, android::base::borrowed_fd fd,
|
||||
uint32_t sz);
|
||||
uint32_t sz) override;
|
||||
RetCode FlashPartition(const std::string& partition, sparse_file* s, uint32_t sz,
|
||||
size_t current, size_t total);
|
||||
|
||||
|
@ -127,7 +121,7 @@ class FastBootDriver {
|
|||
void SetInfoCallback(std::function<void(const std::string&)> info);
|
||||
static const std::string RCString(RetCode rc);
|
||||
std::string Error();
|
||||
RetCode WaitForDisconnect();
|
||||
RetCode WaitForDisconnect() override;
|
||||
|
||||
// Note: set_transport will return the previous transport.
|
||||
Transport* set_transport(Transport* transport);
|
||||
|
|
59
fastboot/fastboot_driver_interface.h
Normal file
59
fastboot/fastboot_driver_interface.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
//
|
||||
// Copyright (C) 2023 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "android-base/unique_fd.h"
|
||||
|
||||
class Transport;
|
||||
|
||||
namespace fastboot {
|
||||
|
||||
enum RetCode : int {
|
||||
SUCCESS = 0,
|
||||
BAD_ARG,
|
||||
IO_ERROR,
|
||||
BAD_DEV_RESP,
|
||||
DEVICE_FAIL,
|
||||
TIMEOUT,
|
||||
};
|
||||
|
||||
class IFastBootDriver {
|
||||
public:
|
||||
RetCode virtual FlashPartition(const std::string& partition, android::base::borrowed_fd fd,
|
||||
uint32_t sz) = 0;
|
||||
RetCode virtual DeletePartition(const std::string& partition) = 0;
|
||||
RetCode virtual WaitForDisconnect() = 0;
|
||||
RetCode virtual Reboot(std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr) = 0;
|
||||
|
||||
RetCode virtual RebootTo(std::string target, std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr) = 0;
|
||||
RetCode virtual GetVar(const std::string& key, std::string* val,
|
||||
std::vector<std::string>* info = nullptr) = 0;
|
||||
RetCode virtual Download(const std::string& name, android::base::borrowed_fd fd, size_t size,
|
||||
std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr) = 0;
|
||||
RetCode virtual RawCommand(const std::string& cmd, const std::string& message,
|
||||
std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr, int* dsize = nullptr) = 0;
|
||||
RetCode virtual ResizePartition(const std::string& partition, const std::string& size) = 0;
|
||||
RetCode virtual Erase(const std::string& partition, std::string* response = nullptr,
|
||||
std::vector<std::string>* info = nullptr) = 0;
|
||||
virtual ~IFastBootDriver() = default;
|
||||
};
|
||||
} // namespace fastboot
|
51
fastboot/fastboot_driver_mock.h
Normal file
51
fastboot/fastboot_driver_mock.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// Copyright (C) 2023 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "fastboot_driver_interface.h"
|
||||
|
||||
namespace fastboot {
|
||||
|
||||
class MockFastbootDriver : public IFastBootDriver {
|
||||
public:
|
||||
MOCK_METHOD(RetCode, FlashPartition,
|
||||
(const std::string& partition, android::base::borrowed_fd fd, uint32_t sz),
|
||||
(override));
|
||||
MOCK_METHOD(RetCode, DeletePartition, (const std::string&), (override));
|
||||
MOCK_METHOD(RetCode, Reboot, (std::string*, std::vector<std::string>*), (override));
|
||||
MOCK_METHOD(RetCode, RebootTo, (std::string, std::string*, std::vector<std::string>*),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(RetCode, GetVar, (const std::string&, std::string*, std::vector<std::string>*),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(RetCode, Download,
|
||||
(const std::string&, android::base::borrowed_fd, size_t, std::string*,
|
||||
std::vector<std::string>*),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(RetCode, RawCommand,
|
||||
(const std::string&, const std::string&, std::string*, std::vector<std::string>*,
|
||||
int*),
|
||||
(override));
|
||||
MOCK_METHOD(RetCode, ResizePartition, (const std::string&, const std::string&), (override));
|
||||
MOCK_METHOD(RetCode, Erase, (const std::string&, std::string*, std::vector<std::string>*),
|
||||
(override));
|
||||
MOCK_METHOD(RetCode, WaitForDisconnect, (), (override));
|
||||
};
|
||||
|
||||
} // namespace fastboot
|
Loading…
Reference in a new issue