blob: 7ecabab2fdf7e6ca1f2f1a3d2a674f0403de469b [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.
#include "firmware_mtd_updater.hpp"
#include "mtd_mock.hpp"
#include "sys_mock.hpp"
#include <xyz/openbmc_project/Control/Hoth/error.hpp>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
using sdbusplus::error::xyz::openbmc_project::control::hoth::FirmwareFailure;
using google::hoth::internal::FirmwareMtdUpdater;
using google::hoth::internal::MtdMock;
using google::hoth::internal::SysMock;
using ::testing::_;
using ::testing::Return;
class FirmwareMtdUpdaterTest : public ::testing::Test
{
protected:
// Mtd mock object
MtdMock mtd;
// Sys mock object
SysMock sys;
};
TEST_F(FirmwareMtdUpdaterTest, noMtd)
{
FirmwareMtdUpdater updater(nullptr, nullptr);
EXPECT_THROW(updater.update({}), FirmwareFailure);
}
TEST_F(FirmwareMtdUpdaterTest, Success)
{
EXPECT_CALL(mtd, findPartition(_)).Times(1).WillRepeatedly(Return(""));
EXPECT_CALL(mtd, flashCopy(_, _, _)).Times(1);
FirmwareMtdUpdater updater(&mtd, &sys);
EXPECT_NO_THROW(updater.update({}));
}
TEST_F(FirmwareMtdUpdaterTest, noSpiWrite)
{
FirmwareMtdUpdater updater(&mtd, &sys);
EXPECT_THROW(updater.spiWrite(0, {}), FirmwareFailure);
}