blob: e985b8062b1e97fce1549e931412febb29c2efe8 [file] [log] [blame]
Matt Spinlera906c942019-10-08 13:42:05 -05001#include "extensions/openpower-pels/fru_identity.hpp"
2
3#include <gtest/gtest.h>
4
5using namespace openpower::pels;
6using namespace openpower::pels::src;
7
8// Unflatten a FRUIdentity that is a HW FRU callout
9TEST(FRUIdentityTest, TestHardwareFRU)
10{
11 // Has PN, SN, CCIN
12 std::vector<uint8_t> data{'I', 'D', 0x1C, 0x1D, // type, size, flags
13 '1', '2', '3', '4', // PN
14 '5', '6', '7', 0x00, 'A', 'A', 'A', 'A', // CCIN
15 '1', '2', '3', '4', '5', '6', '7', '8', // SN
16 '9', 'A', 'B', 'C'};
17
18 Stream stream{data};
19
20 FRUIdentity fru{stream};
21
22 EXPECT_EQ(fru.failingComponentType(), FRUIdentity::hardwareFRU);
23 EXPECT_EQ(fru.flattenedSize(), data.size());
24
25 EXPECT_EQ(fru.getPN().value(), "1234567");
26 EXPECT_EQ(fru.getCCIN().value(), "AAAA");
27 EXPECT_EQ(fru.getSN().value(), "123456789ABC");
28 EXPECT_FALSE(fru.getMaintProc());
29
30 // Flatten
31 std::vector<uint8_t> newData;
32 Stream newStream{newData};
33 fru.flatten(newStream);
34 EXPECT_EQ(data, newData);
35}
36
37// Unflatten a FRUIdentity that is a Maintenance Procedure callout
38TEST(FRUIdentityTest, TestMaintProcedure)
39{
40 // Only contains the maintenance procedure
41 std::vector<uint8_t> data{
42 0x49, 0x44, 0x0C, 0x42, // type, size, flags
43 '1', '2', '3', '4', '5', '6', '7', 0x00 // Procedure
44 };
45
46 Stream stream{data};
47
48 FRUIdentity fru{stream};
49
50 EXPECT_EQ(fru.failingComponentType(), FRUIdentity::maintenanceProc);
51 EXPECT_EQ(fru.flattenedSize(), data.size());
52
53 EXPECT_EQ(fru.getMaintProc().value(), "1234567");
54 EXPECT_FALSE(fru.getPN());
55 EXPECT_FALSE(fru.getCCIN());
56 EXPECT_FALSE(fru.getSN());
57
58 // Flatten
59 std::vector<uint8_t> newData;
60 Stream newStream{newData};
61 fru.flatten(newStream);
62 EXPECT_EQ(data, newData);
63}
64
65// Try to unflatten garbage data
66TEST(FRUIdentityTest, BadDataTest)
67{
68 std::vector<uint8_t> data{0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
69 0xFF, 0xFF, 0xFF, 0xFF};
70
71 Stream stream{data};
72
73 EXPECT_THROW(FRUIdentity fru{stream}, std::out_of_range);
74}