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