1 #include "extensions/openpower-pels/failing_mtms.hpp" 2 #include "mocks.hpp" 3 4 #include <gtest/gtest.h> 5 6 using namespace openpower::pels; 7 using ::testing::Return; 8 9 TEST(FailingMTMSTest, SizeTest) 10 { 11 EXPECT_EQ(FailingMTMS::flattenedSize(), 28); 12 } 13 14 TEST(FailingMTMSTest, ConstructorTest) 15 { 16 // Note: the TypeModel field is 8B, and the SN field is 12B 17 { 18 MockDataInterface dataIface; 19 20 EXPECT_CALL(dataIface, getMachineTypeModel()) 21 .WillOnce(Return("AAAA-BBB")); 22 23 EXPECT_CALL(dataIface, getMachineSerialNumber()) 24 .WillOnce(Return("123456789ABC")); 25 26 FailingMTMS fm{dataIface}; 27 28 // Check the section header 29 EXPECT_EQ(fm.header().id, 0x4D54); 30 EXPECT_EQ(fm.header().size, FailingMTMS::flattenedSize()); 31 EXPECT_EQ(fm.header().version, 0x01); 32 EXPECT_EQ(fm.header().subType, 0x00); 33 EXPECT_EQ(fm.header().componentID, 0x2000); 34 35 EXPECT_EQ(fm.getMachineTypeModel(), "AAAA-BBB"); 36 EXPECT_EQ(fm.getMachineSerialNumber(), "123456789ABC"); 37 } 38 39 // longer than the max - will truncate 40 { 41 MockDataInterface dataIface; 42 43 EXPECT_CALL(dataIface, getMachineTypeModel()) 44 .WillOnce(Return("AAAA-BBBTOOLONG")); 45 46 EXPECT_CALL(dataIface, getMachineSerialNumber()) 47 .WillOnce(Return("123456789ABCTOOLONG")); 48 49 FailingMTMS fm{dataIface}; 50 51 EXPECT_EQ(fm.getMachineTypeModel(), "AAAA-BBB"); 52 EXPECT_EQ(fm.getMachineSerialNumber(), "123456789ABC"); 53 } 54 55 // shorter than the max 56 { 57 MockDataInterface dataIface; 58 59 EXPECT_CALL(dataIface, getMachineTypeModel()).WillOnce(Return("A")); 60 61 EXPECT_CALL(dataIface, getMachineSerialNumber()).WillOnce(Return("1")); 62 63 FailingMTMS fm{dataIface}; 64 65 EXPECT_EQ(fm.getMachineTypeModel(), "A"); 66 EXPECT_EQ(fm.getMachineSerialNumber(), "1"); 67 } 68 } 69 70 TEST(FailingMTMSTest, StreamConstructorTest) 71 { 72 std::vector<uint8_t> data{0x4D, 0x54, 0x00, 0x1C, 0x01, 0x00, 0x20, 73 0x00, 'T', 'T', 'T', 'T', '-', 'M', 74 'M', 'M', '1', '2', '3', '4', '5', 75 '6', '7', '8', '9', 'A', 'B', 'C'}; 76 Stream stream{data}; 77 FailingMTMS fm{stream}; 78 79 EXPECT_EQ(fm.valid(), true); 80 81 EXPECT_EQ(fm.header().id, 0x4D54); 82 EXPECT_EQ(fm.header().size, FailingMTMS::flattenedSize()); 83 EXPECT_EQ(fm.header().version, 0x01); 84 EXPECT_EQ(fm.header().subType, 0x00); 85 EXPECT_EQ(fm.header().componentID, 0x2000); 86 87 EXPECT_EQ(fm.getMachineTypeModel(), "TTTT-MMM"); 88 EXPECT_EQ(fm.getMachineSerialNumber(), "123456789ABC"); 89 } 90 91 TEST(FailingMTMSTest, BadStreamConstructorTest) 92 { 93 // too short 94 std::vector<uint8_t> data{ 95 0x4D, 0x54, 0x00, 0x1C, 0x01, 0x00, 0x20, 0x00, 'T', 'T', 96 }; 97 Stream stream{data}; 98 FailingMTMS fm{stream}; 99 100 EXPECT_EQ(fm.valid(), false); 101 } 102 103 TEST(FailingMTMSTest, FlattenTest) 104 { 105 std::vector<uint8_t> data{0x4D, 0x54, 0x00, 0x1C, 0x01, 0x00, 0x20, 106 0x00, 'T', 'T', 'T', 'T', '-', 'M', 107 'M', 'M', '1', '2', '3', '4', '5', 108 '6', '7', '8', '9', 'A', 'B', 'C'}; 109 Stream stream{data}; 110 FailingMTMS fm{stream}; 111 112 // flatten and check results 113 std::vector<uint8_t> newData; 114 Stream newStream{newData}; 115 116 fm.flatten(newStream); 117 EXPECT_EQ(data, newData); 118 } 119