blob: 9aac01ae9b019545bca6aa1700615db5f871a21b [file] [log] [blame]
Patrick Venture01123b22019-06-20 13:49:06 -07001#include "helper.hpp"
2#include "status.hpp"
3
Patrick Venture01123b22019-06-20 13:49:06 -07004#include <ipmiblob/test/blob_interface_mock.hpp>
5
Patrick Venture9b37b092020-05-28 20:58:57 -07006#include <cstdint>
7
Patrick Venture01123b22019-06-20 13:49:06 -07008#include <gtest/gtest.h>
9
10namespace host_tool
11{
12using ::testing::Return;
13using ::testing::TypedEq;
14
Vivekanand Veeracholanc7fa2c22021-02-18 18:05:41 -080015class HelperTest : public ::testing::Test
Patrick Venture01123b22019-06-20 13:49:06 -070016{
17 protected:
18 ipmiblob::BlobInterfaceMock blobMock;
19 std::uint16_t session = 0xbeef;
20};
21
Vivekanand Veeracholanc7fa2c22021-02-18 18:05:41 -080022TEST_F(HelperTest, PollStatusReturnsAfterSuccess)
Patrick Venture01123b22019-06-20 13:49:06 -070023{
24 ipmiblob::StatResponse verificationResponse = {};
25 /* the other details of the response are ignored, and should be. */
26 verificationResponse.metadata.push_back(
27 static_cast<std::uint8_t>(ipmi_flash::ActionStatus::success));
28
29 EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session)))
30 .WillOnce(Return(verificationResponse));
31
32 EXPECT_TRUE(pollStatus(session, &blobMock));
33}
34
Vivekanand Veeracholanc7fa2c22021-02-18 18:05:41 -080035TEST_F(HelperTest, PollStatusReturnsAfterFailure)
Patrick Venture01123b22019-06-20 13:49:06 -070036{
37 ipmiblob::StatResponse verificationResponse = {};
38 /* the other details of the response are ignored, and should be. */
39 verificationResponse.metadata.push_back(
40 static_cast<std::uint8_t>(ipmi_flash::ActionStatus::failed));
41
42 EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session)))
43 .WillOnce(Return(verificationResponse));
44
45 EXPECT_FALSE(pollStatus(session, &blobMock));
46}
47
Vivekanand Veeracholanc7fa2c22021-02-18 18:05:41 -080048TEST_F(HelperTest, MemcpyAlignedOneByte)
49{
50 const char source = 'a';
51 char destination;
52
53 EXPECT_EQ(&destination,
54 memcpyAligned(&destination, &source, sizeof(source)));
55 EXPECT_EQ(destination, source);
56}
57
58TEST_F(HelperTest, MemcpyAlignedMultiByte)
59{
60 const char source[14] = "abcdefghijklm";
61 char destination[14] = "xxxxxxxxxxxxx";
62
63 EXPECT_EQ(&destination,
64 memcpyAligned(&destination, &source, sizeof(source)));
65 EXPECT_EQ(0, memcmp(&destination, &source, sizeof(source)));
66}
67
Patrick Venture01123b22019-06-20 13:49:06 -070068} // namespace host_tool