101123b2aSPatrick Venture #include "helper.hpp" 201123b2aSPatrick Venture #include "status.hpp" 301123b2aSPatrick Venture 401123b2aSPatrick Venture #include <ipmiblob/test/blob_interface_mock.hpp> 501123b2aSPatrick Venture 69b37b095SPatrick Venture #include <cstdint> 79b37b095SPatrick Venture 801123b2aSPatrick Venture #include <gtest/gtest.h> 901123b2aSPatrick Venture 1001123b2aSPatrick Venture namespace host_tool 1101123b2aSPatrick Venture { 1201123b2aSPatrick Venture using ::testing::Return; 1301123b2aSPatrick Venture using ::testing::TypedEq; 1401123b2aSPatrick Venture 15*c7fa2c28SVivekanand Veeracholan class HelperTest : public ::testing::Test 1601123b2aSPatrick Venture { 1701123b2aSPatrick Venture protected: 1801123b2aSPatrick Venture ipmiblob::BlobInterfaceMock blobMock; 1901123b2aSPatrick Venture std::uint16_t session = 0xbeef; 2001123b2aSPatrick Venture }; 2101123b2aSPatrick Venture 22*c7fa2c28SVivekanand Veeracholan TEST_F(HelperTest, PollStatusReturnsAfterSuccess) 2301123b2aSPatrick Venture { 2401123b2aSPatrick Venture ipmiblob::StatResponse verificationResponse = {}; 2501123b2aSPatrick Venture /* the other details of the response are ignored, and should be. */ 2601123b2aSPatrick Venture verificationResponse.metadata.push_back( 2701123b2aSPatrick Venture static_cast<std::uint8_t>(ipmi_flash::ActionStatus::success)); 2801123b2aSPatrick Venture 2901123b2aSPatrick Venture EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) 3001123b2aSPatrick Venture .WillOnce(Return(verificationResponse)); 3101123b2aSPatrick Venture 3201123b2aSPatrick Venture EXPECT_TRUE(pollStatus(session, &blobMock)); 3301123b2aSPatrick Venture } 3401123b2aSPatrick Venture 35*c7fa2c28SVivekanand Veeracholan TEST_F(HelperTest, PollStatusReturnsAfterFailure) 3601123b2aSPatrick Venture { 3701123b2aSPatrick Venture ipmiblob::StatResponse verificationResponse = {}; 3801123b2aSPatrick Venture /* the other details of the response are ignored, and should be. */ 3901123b2aSPatrick Venture verificationResponse.metadata.push_back( 4001123b2aSPatrick Venture static_cast<std::uint8_t>(ipmi_flash::ActionStatus::failed)); 4101123b2aSPatrick Venture 4201123b2aSPatrick Venture EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session))) 4301123b2aSPatrick Venture .WillOnce(Return(verificationResponse)); 4401123b2aSPatrick Venture 4501123b2aSPatrick Venture EXPECT_FALSE(pollStatus(session, &blobMock)); 4601123b2aSPatrick Venture } 4701123b2aSPatrick Venture 48*c7fa2c28SVivekanand Veeracholan TEST_F(HelperTest, MemcpyAlignedOneByte) 49*c7fa2c28SVivekanand Veeracholan { 50*c7fa2c28SVivekanand Veeracholan const char source = 'a'; 51*c7fa2c28SVivekanand Veeracholan char destination; 52*c7fa2c28SVivekanand Veeracholan 53*c7fa2c28SVivekanand Veeracholan EXPECT_EQ(&destination, 54*c7fa2c28SVivekanand Veeracholan memcpyAligned(&destination, &source, sizeof(source))); 55*c7fa2c28SVivekanand Veeracholan EXPECT_EQ(destination, source); 56*c7fa2c28SVivekanand Veeracholan } 57*c7fa2c28SVivekanand Veeracholan 58*c7fa2c28SVivekanand Veeracholan TEST_F(HelperTest, MemcpyAlignedMultiByte) 59*c7fa2c28SVivekanand Veeracholan { 60*c7fa2c28SVivekanand Veeracholan const char source[14] = "abcdefghijklm"; 61*c7fa2c28SVivekanand Veeracholan char destination[14] = "xxxxxxxxxxxxx"; 62*c7fa2c28SVivekanand Veeracholan 63*c7fa2c28SVivekanand Veeracholan EXPECT_EQ(&destination, 64*c7fa2c28SVivekanand Veeracholan memcpyAligned(&destination, &source, sizeof(source))); 65*c7fa2c28SVivekanand Veeracholan EXPECT_EQ(0, memcmp(&destination, &source, sizeof(source))); 66*c7fa2c28SVivekanand Veeracholan } 67*c7fa2c28SVivekanand Veeracholan 6801123b2aSPatrick Venture } // namespace host_tool 69