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