blob: d8c1d24ba2a04e65d3bbad15b5d9d4f4f402cb65 [file] [log] [blame]
Patrick Venture6f17bd22018-08-07 13:24:17 -07001#include "flash-ipmi.hpp"
2
3#include <cstdio>
Patrick Venture605f75f2018-08-07 16:27:05 -07004#include <sdbusplus/test/sdbus_mock.hpp>
Patrick Venture6f17bd22018-08-07 13:24:17 -07005#include <string>
6
Patrick Venture1aedab22018-09-10 14:41:45 -07007#include <gtest/gtest.h>
8
Patrick Venture6f17bd22018-08-07 13:24:17 -07009#define THIRTYTWO_MIB 33554432
10
11TEST(FlashIpmiHashStartTest, OutofSequenceFails)
12{
13 // Verify that the image must be started first. (can change).
14
15 std::string name = std::tmpnam(nullptr);
16 std::string name2 = std::tmpnam(nullptr);
17
Patrick Venture605f75f2018-08-07 16:27:05 -070018 sdbusplus::SdBusMock sdbus_mock;
19 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
20
21 FlashUpdate updater(std::move(bus_mock), name, "", name2);
Patrick Venture6f17bd22018-08-07 13:24:17 -070022 EXPECT_FALSE(updater.startHash(THIRTYTWO_MIB));
23
24 (void)std::remove(name.c_str());
25 (void)std::remove(name2.c_str());
26}
27
28TEST(FlashIpmiHashStartTest, VerifyHashFileCreated)
29{
30 // Verify that it's happy.
31
32 std::string name = std::tmpnam(nullptr);
33 std::string name2 = std::tmpnam(nullptr);
34
Patrick Venture605f75f2018-08-07 16:27:05 -070035 sdbusplus::SdBusMock sdbus_mock;
36 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
37
38 FlashUpdate updater(std::move(bus_mock), name, "", name2);
Patrick Venture6f17bd22018-08-07 13:24:17 -070039 EXPECT_TRUE(updater.start(THIRTYTWO_MIB));
40 EXPECT_TRUE(updater.startHash(THIRTYTWO_MIB));
41
42 (void)std::remove(name.c_str());
43 (void)std::remove(name2.c_str());
44}