Willy Tu | a2056e9 | 2021-10-10 13:36:16 -0700 | [diff] [blame^] | 1 | // Copyright 2021 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 15 | #include "commands.hpp" |
| 16 | #include "flash_size.hpp" |
| 17 | #include "handler_mock.hpp" |
| 18 | |
| 19 | #include <cstdint> |
| 20 | #include <cstring> |
| 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <gtest/gtest.h> |
| 25 | |
| 26 | #define MAX_IPMI_BUFFER 64 |
| 27 | |
| 28 | using ::testing::Return; |
| 29 | |
| 30 | namespace google |
| 31 | { |
| 32 | namespace ipmi |
| 33 | { |
| 34 | |
| 35 | TEST(FlashSizeCommandTest, InvalidCommandLength) |
| 36 | { |
| 37 | // GetFlashSizeRequest is one byte, let's send 0. |
| 38 | std::vector<std::uint8_t> request = {}; |
| 39 | size_t dataLen = request.size(); |
| 40 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 41 | |
| 42 | HandlerMock hMock; |
| 43 | EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID, |
| 44 | getFlashSize(request.data(), reply, &dataLen, &hMock)); |
| 45 | } |
| 46 | |
| 47 | TEST(FlashSizeCommandTest, ValidRequest) |
| 48 | { |
| 49 | std::vector<std::uint8_t> request = {SysOEMCommands::SysGetFlashSize}; |
| 50 | size_t dataLen = request.size(); |
| 51 | std::uint8_t reply[MAX_IPMI_BUFFER]; |
| 52 | uint32_t flashSize = 5422312; // 0x52BCE8 |
| 53 | |
| 54 | HandlerMock hMock; |
| 55 | EXPECT_CALL(hMock, getFlashSize()).WillOnce(Return(flashSize)); |
| 56 | EXPECT_EQ(IPMI_CC_OK, |
| 57 | getFlashSize(request.data(), reply, &dataLen, &hMock)); |
| 58 | EXPECT_EQ(dataLen, 5); |
| 59 | EXPECT_EQ(reply[4], 0); |
| 60 | EXPECT_EQ(reply[3], 0x52); |
| 61 | EXPECT_EQ(reply[2], 0xBC); |
| 62 | EXPECT_EQ(reply[1], 0xE8); |
| 63 | } |
| 64 | |
| 65 | } // namespace ipmi |
| 66 | } // namespace google |