Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 1 | #include "commands.hpp" |
| 2 | #include "flash_size.hpp" |
| 3 | #include "handler_mock.hpp" |
| 4 | |
| 5 | #include <cstdint> |
| 6 | #include <cstring> |
| 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include <gtest/gtest.h> |
| 11 | |
| 12 | #define MAX_IPMI_BUFFER 64 |
| 13 | |
| 14 | using ::testing::Return; |
| 15 | |
| 16 | namespace google |
| 17 | { |
| 18 | namespace ipmi |
| 19 | { |
| 20 | |
| 21 | TEST(FlashSizeCommandTest, InvalidCommandLength) |
| 22 | { |
| 23 | // GetFlashSizeRequest is one byte, let's send 0. |
| 24 | std::vector<std::uint8_t> request = {}; |
| 25 | size_t dataLen = request.size(); |
| 26 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 27 | |
| 28 | HandlerMock hMock; |
| 29 | EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID, |
| 30 | getFlashSize(request.data(), reply, &dataLen, &hMock)); |
| 31 | } |
| 32 | |
| 33 | TEST(FlashSizeCommandTest, ValidRequest) |
| 34 | { |
| 35 | std::vector<std::uint8_t> request = {SysOEMCommands::SysGetFlashSize}; |
| 36 | size_t dataLen = request.size(); |
| 37 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 38 | uint32_t flashSize = 5422312; // 0x52BCE8 |
| 39 | |
| 40 | HandlerMock hMock; |
| 41 | EXPECT_CALL(hMock, getFlashSize()).WillOnce(Return(flashSize)); |
| 42 | EXPECT_EQ(IPMI_CC_OK, |
| 43 | getFlashSize(request.data(), reply, &dataLen, &hMock)); |
| 44 | EXPECT_EQ(dataLen, 5); |
| 45 | EXPECT_EQ(reply[4], 0); |
| 46 | EXPECT_EQ(reply[3], 0x52); |
| 47 | EXPECT_EQ(reply[2], 0xBC); |
| 48 | EXPECT_EQ(reply[1], 0xE8); |
| 49 | } |
| 50 | |
| 51 | } // namespace ipmi |
| 52 | } // namespace google |