xref: /openbmc/phosphor-ipmi-flash/bmc/firmware-handler/test/firmware_open_unittest.cpp (revision b487eb47e566df7679e740559582f6d25597feba)
184bff8beSJason Ling #include "create_action_map.hpp"
2ded66d0fSJason Ling #include "firmware_handler.hpp"
3ded66d0fSJason Ling #include "flags.hpp"
4ded66d0fSJason Ling #include "image_mock.hpp"
5ded66d0fSJason Ling #include "util.hpp"
6ded66d0fSJason Ling 
7ded66d0fSJason Ling #include <memory>
8ded66d0fSJason Ling #include <utility>
9ded66d0fSJason Ling #include <vector>
10ded66d0fSJason Ling 
11ded66d0fSJason Ling #include <gtest/gtest.h>
12ded66d0fSJason Ling 
13ded66d0fSJason Ling namespace ipmi_flash
14ded66d0fSJason Ling {
15ded66d0fSJason Ling namespace
16ded66d0fSJason Ling {
17ded66d0fSJason Ling 
18ded66d0fSJason Ling class FirmwareOpenFailTest : public ::testing::TestWithParam<std::uint16_t>
19ded66d0fSJason Ling {};
20ded66d0fSJason Ling 
TEST_P(FirmwareOpenFailTest,WithFlags)21ded66d0fSJason Ling TEST_P(FirmwareOpenFailTest, WithFlags)
22ded66d0fSJason Ling {
23ded66d0fSJason Ling     std::vector<DataHandlerPack> data;
24ded66d0fSJason Ling     data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr);
25ded66d0fSJason Ling     data.emplace_back(FirmwareFlags::UpdateFlags::p2a, nullptr);
26ded66d0fSJason Ling     data.emplace_back(FirmwareFlags::UpdateFlags::lpc, nullptr);
27ded66d0fSJason Ling 
28ded66d0fSJason Ling     std::vector<HandlerPack> blobs;
29ded66d0fSJason Ling     blobs.emplace_back(hashBlobId, std::make_unique<ImageHandlerMock>());
30ded66d0fSJason Ling     blobs.emplace_back("asdf", std::make_unique<ImageHandlerMock>());
31ded66d0fSJason Ling 
32ded66d0fSJason Ling     auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
33ded66d0fSJason Ling         std::move(blobs), std::move(data), CreateActionMap("asdf"));
34ded66d0fSJason Ling 
35ded66d0fSJason Ling     EXPECT_FALSE(handler->open(0, GetParam(), "asdf"));
36ded66d0fSJason Ling }
37ded66d0fSJason Ling 
38ded66d0fSJason Ling const std::vector<std::uint16_t> OpenFailParams{
39ded66d0fSJason Ling     /* These first 4 fail because they don't have the "write" flag */
40ded66d0fSJason Ling     0b000 << 8,
41ded66d0fSJason Ling     0b110 << 8,
42ded66d0fSJason Ling     0b101 << 8,
43ded66d0fSJason Ling     0b011 << 8,
44ded66d0fSJason Ling     /* Next 1 doesn't specify any transport */
45*b487eb47SWilly Tu     static_cast<std::uint16_t>(blobs::OpenFlags::write) | 0b000 << 8,
46ded66d0fSJason Ling     /* Next 3 specify 2 reserved transport bits at the same time. This isn't
47ded66d0fSJason Ling      * allowed because older code expects these first 3 bits to be mutually
48ded66d0fSJason Ling      * exclusive.
49ded66d0fSJason Ling      */
50*b487eb47SWilly Tu     static_cast<std::uint16_t>(blobs::OpenFlags::write) | 0b110 << 8,
51*b487eb47SWilly Tu     static_cast<std::uint16_t>(blobs::OpenFlags::write) | 0b101 << 8,
52*b487eb47SWilly Tu     static_cast<std::uint16_t>(blobs::OpenFlags::write) | 0b011 << 8,
53ded66d0fSJason Ling };
54ded66d0fSJason Ling 
55ded66d0fSJason Ling INSTANTIATE_TEST_CASE_P(WithFlags, FirmwareOpenFailTest,
56ded66d0fSJason Ling                         ::testing::ValuesIn(OpenFailParams));
57ded66d0fSJason Ling 
58ded66d0fSJason Ling } // namespace
59ded66d0fSJason Ling } // namespace ipmi_flash
60