Patrick Venture | 6f17bd2 | 2018-08-07 13:24:17 -0700 | [diff] [blame] | 1 | #include "flash-ipmi.hpp" |
| 2 | |
| 3 | #include <cstdio> |
| 4 | #include <gtest/gtest.h> |
Patrick Venture | 605f75f | 2018-08-07 16:27:05 -0700 | [diff] [blame] | 5 | #include <sdbusplus/test/sdbus_mock.hpp> |
Patrick Venture | 6f17bd2 | 2018-08-07 13:24:17 -0700 | [diff] [blame] | 6 | #include <string> |
| 7 | |
| 8 | #define THIRTYTWO_MIB 33554432 |
| 9 | |
| 10 | TEST(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 Venture | 605f75f | 2018-08-07 16:27:05 -0700 | [diff] [blame] | 17 | 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 Venture | 6f17bd2 | 2018-08-07 13:24:17 -0700 | [diff] [blame] | 21 | EXPECT_FALSE(updater.startHash(THIRTYTWO_MIB)); |
| 22 | |
| 23 | (void)std::remove(name.c_str()); |
| 24 | (void)std::remove(name2.c_str()); |
| 25 | } |
| 26 | |
| 27 | TEST(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 Venture | 605f75f | 2018-08-07 16:27:05 -0700 | [diff] [blame] | 34 | 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 Venture | 6f17bd2 | 2018-08-07 13:24:17 -0700 | [diff] [blame] | 38 | 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 | } |