blob: 84570c586363f37a2728bcfb812e48cd81d9e0c8 [file] [log] [blame]
// Copyright 2024 Google LLC
//
// 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 "google3/host_commands.h"
#include "dbus_interface.hpp"
#include "payload_update_common.hpp"
#include <xyz/openbmc_project/Control/Hoth/server.hpp>
#include <optional>
#include <span>
#include <string>
#include <vector>
namespace google::hoth::tools
{
namespace fake_bus
{
constexpr char kActiveHalfVersion[] = "1.0.0.0";
constexpr char kNextHalfVersion[] = "2.0.0.0";
// The fake bus class constructor accepts a set of test option parameters to
// allow customization of test behaviors and expected results.
struct Options
{
bool resetRequired = false;
bool injectVersionFail = false;
bool injectInvalidAreaSize = false;
bool injectPayloadFail = false;
bool injectVerifyPayloadFail = false;
bool injectActivateFail = false;
bool injectDeactivateFail = false;
bool injectSpsPassthroughFail = false;
std::string newVersion = kNextHalfVersion;
};
} // namespace fake_bus
// Fake bus interface to stand in for the sdbus during unit tests
class FakeBus : public DBusInterface
{
public:
explicit FakeBus(const fake_bus::Options& opt) : options(opt)
{}
std::optional<std::string>
getPayloadVersion(const std::string& hothId,
payload_update::VersionType type) override;
bool sendPayloadAndVerify(const std::string& hothId,
const std::string& payloadFile) override;
bool sendStaticWPPayloadAndVerify(const std::string& hothId,
const std::string& payloadFile) override;
bool activatePayload(const std::string& hothId) override;
bool deactivatePayload(const std::string& hothId) override;
bool confirmPayload(const std::string& hothId) override;
bool eraseStagingArea(const std::string& hothId) override;
bool setTargetResetOption(const std::string& hothId,
ec_target_reset_option option) override;
bool setSpsPassthrough(const std::string& hothId,
bool enable) override;
std::optional<bool> getSpsPassthrough(const std::string& hothId) override;
bool expectConfirmPayload() override
{
return true;
}
private:
bool verifyPayload() const;
fake_bus::Options options;
bool resetHeld = false;
std::string activeHalfVersion = fake_bus::kActiveHalfVersion;
std::string nextHalfVersion = fake_bus::kNextHalfVersion;
};
} // namespace google::hoth::tools