| // Copyright 2026 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 "google3/ec_commands.h" |
| #include "google3/host_commands.h" |
| |
| #include "ec_util_mock.hpp" |
| |
| #include <asset.hpp> |
| #include <sdbusplus/bus.hpp> |
| #include <sdbusplus/test/sdbus_mock.hpp> |
| #include <xyz/openbmc_project/Control/Hoth/error.hpp> |
| |
| #include <memory> |
| #include <string> |
| #include <tuple> |
| #include <vector> |
| |
| #include <gmock/gmock.h> |
| #include <gtest/gtest.h> |
| |
| using sdbusplus::error::xyz::openbmc_project::control::hoth::ResponseFailure; |
| |
| using ::testing::_; |
| using ::testing::IsNull; |
| using ::testing::Return; |
| using ::testing::StrEq; |
| using ::testing::Throw; |
| |
| namespace google |
| { |
| namespace hoth |
| { |
| namespace |
| { |
| |
| using internal::EcUtilMock; |
| |
| class AssetTest : public ::testing::Test |
| { |
| public: |
| static constexpr char kTestObjPath[] = "/test/obj/hoth"; |
| static constexpr char kTestBoardPath[] = "/test/board/system"; |
| |
| protected: |
| AssetTest() : bus(sdbusplus::get_mocked_new(&sdbus_mock)) |
| { |
| EXPECT_CALL(sdbus_mock, |
| sd_bus_emit_object_added(IsNull(), StrEq(kTestObjPath))) |
| .WillRepeatedly(Return(0)); |
| EXPECT_CALL(sdbus_mock, |
| sd_bus_emit_object_removed(IsNull(), StrEq(kTestObjPath))) |
| .WillRepeatedly(Return(0)); |
| EXPECT_CALL(sdbus_mock, sd_bus_add_object_vtable( |
| IsNull(), _, StrEq(kTestObjPath), _, _, _)) |
| .WillRepeatedly(Return(0)); |
| } |
| |
| sdbusplus::SdBusMock sdbus_mock; |
| sdbusplus::bus::bus bus; |
| EcUtilMock ecUtil; |
| std::unique_ptr<Asset> asset; |
| }; |
| |
| TEST_F(AssetTest, ChipInfoPopulatesPropertiesAndAssociation) |
| { |
| ec_response_chip_info chip_info = {}; |
| chip_info.hardware_category = CRYPTA_HW_CAT_HOTH_D2; |
| chip_info.hardware_identity = 0x123456789abcdef0; |
| |
| EXPECT_CALL(ecUtil, getHothChipInfo()).WillOnce(Return(chip_info)); |
| |
| EXPECT_NO_THROW({ |
| asset = |
| std::make_unique<Asset>(bus, kTestObjPath, kTestBoardPath, &ecUtil); |
| }); |
| |
| EXPECT_EQ(asset->manufacturer(), "Google"); |
| EXPECT_EQ(asset->model(), "Titan"); |
| EXPECT_EQ(asset->subModel(), "H1D2P"); |
| EXPECT_EQ(asset->partNumber(), "G660-00438-01"); |
| EXPECT_EQ(asset->serialNumber(), "4-0x123456789abcdef0"); |
| |
| std::vector<std::tuple<std::string, std::string, std::string>> |
| expectedAssocs = {{"chassis", "assembly", kTestBoardPath}}; |
| EXPECT_EQ(asset->associations(), expectedAssocs); |
| } |
| |
| TEST_F(AssetTest, ChipInfoExceptionPropagates) |
| { |
| EXPECT_CALL(ecUtil, getHothChipInfo()).WillOnce(Throw(ResponseFailure())); |
| |
| EXPECT_THROW( |
| { |
| asset = std::make_unique<Asset>(bus, kTestObjPath, kTestBoardPath, |
| &ecUtil); |
| }, |
| ResponseFailure); |
| } |
| |
| } // namespace |
| } // namespace hoth |
| } // namespace google |