Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 1 | #include "helper.hpp" |
| 2 | #include "status.hpp" |
William A. Kennington III | f88bcf3 | 2021-10-14 02:15:10 -0700 | [diff] [blame] | 3 | #include "tool_errors.hpp" |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 4 | |
Jie Yang | 328f520 | 2021-03-16 00:52:07 -0700 | [diff] [blame] | 5 | #include <blobs-ipmid/blobs.hpp> |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 6 | #include <ipmiblob/test/blob_interface_mock.hpp> |
| 7 | |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 8 | #include <cstdint> |
| 9 | |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 10 | #include <gtest/gtest.h> |
| 11 | |
| 12 | namespace host_tool |
| 13 | { |
| 14 | using ::testing::Return; |
| 15 | using ::testing::TypedEq; |
| 16 | |
Vivekanand Veeracholan | c7fa2c2 | 2021-02-18 18:05:41 -0800 | [diff] [blame] | 17 | class HelperTest : public ::testing::Test |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 18 | { |
| 19 | protected: |
| 20 | ipmiblob::BlobInterfaceMock blobMock; |
| 21 | std::uint16_t session = 0xbeef; |
| 22 | }; |
| 23 | |
Vivekanand Veeracholan | c7fa2c2 | 2021-02-18 18:05:41 -0800 | [diff] [blame] | 24 | TEST_F(HelperTest, PollStatusReturnsAfterSuccess) |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 25 | { |
| 26 | ipmiblob::StatResponse verificationResponse = {}; |
| 27 | /* the other details of the response are ignored, and should be. */ |
| 28 | verificationResponse.metadata.push_back( |
| 29 | static_cast<std::uint8_t>(ipmi_flash::ActionStatus::success)); |
| 30 | |
| 31 | EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) |
| 32 | .WillOnce(Return(verificationResponse)); |
| 33 | |
William A. Kennington III | f88bcf3 | 2021-10-14 02:15:10 -0700 | [diff] [blame] | 34 | EXPECT_NO_THROW(pollStatus(session, &blobMock)); |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Vivekanand Veeracholan | c7fa2c2 | 2021-02-18 18:05:41 -0800 | [diff] [blame] | 37 | TEST_F(HelperTest, PollStatusReturnsAfterFailure) |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 38 | { |
| 39 | ipmiblob::StatResponse verificationResponse = {}; |
| 40 | /* the other details of the response are ignored, and should be. */ |
| 41 | verificationResponse.metadata.push_back( |
| 42 | static_cast<std::uint8_t>(ipmi_flash::ActionStatus::failed)); |
| 43 | |
| 44 | EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) |
| 45 | .WillOnce(Return(verificationResponse)); |
| 46 | |
William A. Kennington III | f88bcf3 | 2021-10-14 02:15:10 -0700 | [diff] [blame] | 47 | EXPECT_THROW(pollStatus(session, &blobMock), ToolException); |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Jie Yang | 328f520 | 2021-03-16 00:52:07 -0700 | [diff] [blame] | 50 | TEST_F(HelperTest, PollReadReadyReturnsAfterSuccess) |
| 51 | { |
| 52 | ipmiblob::StatResponse blobResponse = {}; |
| 53 | /* the other details of the response are ignored, and should be. */ |
Patrick Williams | 42a44c2 | 2024-08-16 15:21:32 -0400 | [diff] [blame^] | 54 | blobResponse.blob_state = |
| 55 | blobs::StateFlags::open_read | blobs::StateFlags::committed; |
Jie Yang | 328f520 | 2021-03-16 00:52:07 -0700 | [diff] [blame] | 56 | |
| 57 | EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) |
| 58 | .WillOnce(Return(blobResponse)); |
| 59 | |
William A. Kennington III | f88bcf3 | 2021-10-14 02:15:10 -0700 | [diff] [blame] | 60 | EXPECT_NO_THROW(pollReadReady(session, &blobMock)); |
Jie Yang | 328f520 | 2021-03-16 00:52:07 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | TEST_F(HelperTest, PollReadReadyReturnsAfterFailure) |
| 64 | { |
| 65 | ipmiblob::StatResponse blobResponse = {}; |
| 66 | /* the other details of the response are ignored, and should be. */ |
| 67 | blobResponse.blob_state = blobs::StateFlags::commit_error; |
| 68 | |
| 69 | EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) |
| 70 | .WillOnce(Return(blobResponse)); |
| 71 | |
William A. Kennington III | f88bcf3 | 2021-10-14 02:15:10 -0700 | [diff] [blame] | 72 | EXPECT_THROW(pollReadReady(session, &blobMock), ToolException); |
Jie Yang | 328f520 | 2021-03-16 00:52:07 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | TEST_F(HelperTest, PollReadReadyReturnsAfterRetrySuccess) |
| 76 | { |
| 77 | ipmiblob::StatResponse blobResponseRunning = {}; |
| 78 | /* the other details of the response are ignored, and should be. */ |
| 79 | blobResponseRunning.blob_state = blobs::StateFlags::committing; |
| 80 | |
| 81 | ipmiblob::StatResponse blobResponseReadReady = {}; |
| 82 | /* the other details of the response are ignored, and should be. */ |
| 83 | blobResponseReadReady.blob_state = blobs::StateFlags::open_read; |
| 84 | |
| 85 | EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) |
| 86 | .WillOnce(Return(blobResponseRunning)) |
| 87 | .WillOnce(Return(blobResponseReadReady)); |
| 88 | |
William A. Kennington III | f88bcf3 | 2021-10-14 02:15:10 -0700 | [diff] [blame] | 89 | EXPECT_NO_THROW(pollReadReady(session, &blobMock)); |
Jie Yang | 328f520 | 2021-03-16 00:52:07 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | TEST_F(HelperTest, PollReadReadyReturnsAfterRetryFailure) |
| 93 | { |
| 94 | ipmiblob::StatResponse blobResponseRunning = {}; |
| 95 | /* the other details of the response are ignored, and should be. */ |
| 96 | blobResponseRunning.blob_state = blobs::StateFlags::committing; |
| 97 | |
| 98 | ipmiblob::StatResponse blobResponseError = {}; |
| 99 | /* the other details of the response are ignored, and should be. */ |
| 100 | blobResponseError.blob_state = blobs::StateFlags::commit_error; |
| 101 | |
| 102 | EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) |
| 103 | .WillOnce(Return(blobResponseRunning)) |
| 104 | .WillOnce(Return(blobResponseError)); |
| 105 | |
William A. Kennington III | f88bcf3 | 2021-10-14 02:15:10 -0700 | [diff] [blame] | 106 | EXPECT_THROW(pollReadReady(session, &blobMock), ToolException); |
Jie Yang | 328f520 | 2021-03-16 00:52:07 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Vivekanand Veeracholan | c7fa2c2 | 2021-02-18 18:05:41 -0800 | [diff] [blame] | 109 | TEST_F(HelperTest, MemcpyAlignedOneByte) |
| 110 | { |
| 111 | const char source = 'a'; |
| 112 | char destination; |
| 113 | |
| 114 | EXPECT_EQ(&destination, |
| 115 | memcpyAligned(&destination, &source, sizeof(source))); |
| 116 | EXPECT_EQ(destination, source); |
| 117 | } |
| 118 | |
| 119 | TEST_F(HelperTest, MemcpyAlignedMultiByte) |
| 120 | { |
| 121 | const char source[14] = "abcdefghijklm"; |
| 122 | char destination[14] = "xxxxxxxxxxxxx"; |
| 123 | |
| 124 | EXPECT_EQ(&destination, |
| 125 | memcpyAligned(&destination, &source, sizeof(source))); |
| 126 | EXPECT_EQ(0, memcmp(&destination, &source, sizeof(source))); |
| 127 | } |
| 128 | |
Patrick Venture | 01123b2 | 2019-06-20 13:49:06 -0700 | [diff] [blame] | 129 | } // namespace host_tool |