blob: 3cf46eda79993aeaf84b7dc74ce6f860fc0f441f [file] [log] [blame]
Patrick Venture6f17bd22018-08-07 13:24:17 -07001#include "flash-ipmi.hpp"
2
3#include <cstdio>
4#include <gtest/gtest.h>
Patrick Venture605f75f2018-08-07 16:27:05 -07005#include <sdbusplus/test/sdbus_mock.hpp>
Patrick Venture6f17bd22018-08-07 13:24:17 -07006#include <string>
7
8#define THIRTYTWO_MIB 33554432
9
10TEST(FlashIpmiHashStartTest, OutofSequenceFails)
11{
12 // Verify that the image must be started first. (can change).
13
14 std::string name = std::tmpnam(nullptr);
15 std::string name2 = std::tmpnam(nullptr);
16
Patrick Venture605f75f2018-08-07 16:27:05 -070017 sdbusplus::SdBusMock sdbus_mock;
18 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
19
20 FlashUpdate updater(std::move(bus_mock), name, "", name2);
Patrick Venture6f17bd22018-08-07 13:24:17 -070021 EXPECT_FALSE(updater.startHash(THIRTYTWO_MIB));
22
23 (void)std::remove(name.c_str());
24 (void)std::remove(name2.c_str());
25}
26
27TEST(FlashIpmiHashStartTest, VerifyHashFileCreated)
28{
29 // Verify that it's happy.
30
31 std::string name = std::tmpnam(nullptr);
32 std::string name2 = std::tmpnam(nullptr);
33
Patrick Venture605f75f2018-08-07 16:27:05 -070034 sdbusplus::SdBusMock sdbus_mock;
35 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
36
37 FlashUpdate updater(std::move(bus_mock), name, "", name2);
Patrick Venture6f17bd22018-08-07 13:24:17 -070038 EXPECT_TRUE(updater.start(THIRTYTWO_MIB));
39 EXPECT_TRUE(updater.startHash(THIRTYTWO_MIB));
40
41 (void)std::remove(name.c_str());
42 (void)std::remove(name2.c_str());
43}