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