1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/**
* Copyright © 2019 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "extensions/openpower-pels/fru_identity.hpp"
#include <gtest/gtest.h>
using namespace openpower::pels;
using namespace openpower::pels::src;
// Unflatten a FRUIdentity that is a HW FRU callout
TEST(FRUIdentityTest, TestHardwareFRU)
{
// Has PN, SN, CCIN
std::vector<uint8_t> data{'I', 'D', 0x1C, 0x1D, // type, size, flags
'1', '2', '3', '4', // PN
'5', '6', '7', 0x00, 'A', 'A', 'A', 'A', // CCIN
'1', '2', '3', '4', '5', '6', '7', '8', // SN
'9', 'A', 'B', 'C'};
Stream stream{data};
FRUIdentity fru{stream};
EXPECT_EQ(fru.failingComponentType(), FRUIdentity::hardwareFRU);
EXPECT_EQ(fru.flattenedSize(), data.size());
EXPECT_EQ(fru.getPN().value(), "1234567");
EXPECT_EQ(fru.getCCIN().value(), "AAAA");
EXPECT_EQ(fru.getSN().value(), "123456789ABC");
EXPECT_FALSE(fru.getMaintProc());
// Flatten
std::vector<uint8_t> newData;
Stream newStream{newData};
fru.flatten(newStream);
EXPECT_EQ(data, newData);
}
// Unflatten a FRUIdentity that is a Maintenance Procedure callout
TEST(FRUIdentityTest, TestMaintProcedure)
{
// Only contains the maintenance procedure
std::vector<uint8_t> data{
0x49, 0x44, 0x0C, 0x42, // type, size, flags
'1', '2', '3', '4', '5', '6', '7', 0x00 // Procedure
};
Stream stream{data};
FRUIdentity fru{stream};
EXPECT_EQ(fru.failingComponentType(), FRUIdentity::maintenanceProc);
EXPECT_EQ(fru.flattenedSize(), data.size());
EXPECT_EQ(fru.getMaintProc().value(), "1234567");
EXPECT_FALSE(fru.getPN());
EXPECT_FALSE(fru.getCCIN());
EXPECT_FALSE(fru.getSN());
// Flatten
std::vector<uint8_t> newData;
Stream newStream{newData};
fru.flatten(newStream);
EXPECT_EQ(data, newData);
}
// Try to unflatten garbage data
TEST(FRUIdentityTest, BadDataTest)
{
std::vector<uint8_t> data{0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF};
Stream stream{data};
EXPECT_THROW(FRUIdentity fru{stream}, std::out_of_range);
}
|