Benjamin Fair | a67e9e9 | 2019-11-15 14:47:42 -0800 | [diff] [blame] | 1 | #include "firmware_handler.hpp" |
| 2 | #include "flags.hpp" |
| 3 | #include "image_mock.hpp" |
| 4 | #include "triggerable_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> |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 19 | {}; |
Benjamin Fair | a67e9e9 | 2019-11-15 14:47:42 -0800 | [diff] [blame] | 20 | |
| 21 | TEST_P(FirmwareOpenFailTest, WithFlags) |
| 22 | { |
Patrick Venture | 4934daa | 2020-09-22 16:37:44 -0700 | [diff] [blame^] | 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); |
Benjamin Fair | a67e9e9 | 2019-11-15 14:47:42 -0800 | [diff] [blame] | 27 | |
| 28 | std::vector<HandlerPack> blobs; |
| 29 | blobs.push_back(std::move( |
| 30 | HandlerPack(hashBlobId, std::make_unique<ImageHandlerMock>()))); |
| 31 | blobs.push_back( |
| 32 | std::move(HandlerPack("asdf", std::make_unique<ImageHandlerMock>()))); |
| 33 | |
| 34 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 7b78343 | 2020-09-22 15:55:08 -0700 | [diff] [blame] | 35 | std::move(blobs), std::move(data), std::move(CreateActionMap("asdf"))); |
Benjamin Fair | a67e9e9 | 2019-11-15 14:47:42 -0800 | [diff] [blame] | 36 | |
| 37 | EXPECT_FALSE(handler->open(0, GetParam(), "asdf")); |
| 38 | } |
| 39 | |
| 40 | const std::vector<std::uint16_t> OpenFailParams{ |
| 41 | /* These first 4 fail because they don't have the "write" flag */ |
| 42 | 0b000 << 8, |
| 43 | 0b110 << 8, |
| 44 | 0b101 << 8, |
| 45 | 0b011 << 8, |
| 46 | /* Next 1 doesn't specify any transport */ |
| 47 | blobs::OpenFlags::write | 0b000 << 8, |
| 48 | /* Next 3 specify 2 reserved transport bits at the same time. This isn't |
| 49 | * allowed because older code expects these first 3 bits to be mutually |
| 50 | * exclusive. |
| 51 | */ |
| 52 | blobs::OpenFlags::write | 0b110 << 8, |
| 53 | blobs::OpenFlags::write | 0b101 << 8, |
| 54 | blobs::OpenFlags::write | 0b011 << 8, |
| 55 | }; |
| 56 | |
| 57 | INSTANTIATE_TEST_CASE_P(WithFlags, FirmwareOpenFailTest, |
| 58 | ::testing::ValuesIn(OpenFailParams)); |
| 59 | |
| 60 | } // namespace |
| 61 | } // namespace ipmi_flash |