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