summaryrefslogtreecommitdiffstats
path: root/test/openpower-pels/src_callout_test.cpp
blob: 3fd2a5c6b24686578044727a1071a1b3aa1c86c5 (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
 * 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/callout.hpp"
#include "pel_utils.hpp"

#include <gtest/gtest.h>

using namespace openpower::pels;
using namespace openpower::pels::src;

// Unflatten the callout section with all three substructures
TEST(CalloutTest, TestUnflattenAllSubstructures)
{
    // The base data.
    std::vector<uint8_t> data{
        0xFF, 0x2F, 'H', 8, // size, flags, priority, LC length
        'U',  '1',  '2', '-', 'P', '1', 0x00, 0x00 // LC
    };

    auto fruIdentity = srcDataFactory(TestSRCType::fruIdentityStructure);
    auto pceIdentity = srcDataFactory(TestSRCType::pceIdentityStructure);
    auto mrus = srcDataFactory(TestSRCType::mruStructure);

    // Add all 3 substructures
    data.insert(data.end(), fruIdentity.begin(), fruIdentity.end());
    data.insert(data.end(), pceIdentity.begin(), pceIdentity.end());
    data.insert(data.end(), mrus.begin(), mrus.end());

    // The final size
    data[0] = data.size();

    Stream stream{data};
    Callout callout{stream};

    EXPECT_EQ(callout.flattenedSize(), data.size());
    EXPECT_EQ(callout.priority(), 'H');
    EXPECT_EQ(callout.locationCode(), "U12-P1");

    // Spot check the 3 substructures
    EXPECT_TRUE(callout.fruIdentity());
    EXPECT_EQ(callout.fruIdentity()->getSN(), "123456789ABC");

    EXPECT_TRUE(callout.pceIdentity());
    EXPECT_EQ(callout.pceIdentity()->enclosureName(), "PCENAME12");

    EXPECT_TRUE(callout.mru());
    EXPECT_EQ(callout.mru()->mrus().size(), 4);
    EXPECT_EQ(callout.mru()->mrus().at(3).id, 0x04040404);

    // Now flatten
    std::vector<uint8_t> newData;
    Stream newStream{newData};

    callout.flatten(newStream);
    EXPECT_EQ(data, newData);
}

TEST(CalloutTest, TestUnflattenOneSubstructure)
{
    std::vector<uint8_t> data{
        0xFF, 0x28, 'H', 0x08, // size, flags, priority, LC length
        'U',  '1',  '2', '-',  'P', '1', 0x00, 0x00 // LC
    };

    auto fruIdentity = srcDataFactory(TestSRCType::fruIdentityStructure);

    data.insert(data.end(), fruIdentity.begin(), fruIdentity.end());

    // The final size
    data[0] = data.size();

    Stream stream{data};
    Callout callout{stream};

    EXPECT_EQ(callout.flattenedSize(), data.size());

    // Spot check the substructure
    EXPECT_TRUE(callout.fruIdentity());
    EXPECT_EQ(callout.fruIdentity()->getSN(), "123456789ABC");

    // Not present
    EXPECT_FALSE(callout.pceIdentity());
    EXPECT_FALSE(callout.mru());

    // Now flatten
    std::vector<uint8_t> newData;
    Stream newStream{newData};

    callout.flatten(newStream);
    EXPECT_EQ(data, newData);
}

TEST(CalloutTest, TestUnflattenTwoSubstructures)
{
    std::vector<uint8_t> data{
        0xFF, 0x2B, 'H', 0x08, // size, flags, priority, LC length
        'U',  '1',  '2', '-',  'P', '1', 0x00, 0x00 // LC
    };

    auto fruIdentity = srcDataFactory(TestSRCType::fruIdentityStructure);
    auto pceIdentity = srcDataFactory(TestSRCType::pceIdentityStructure);

    data.insert(data.end(), fruIdentity.begin(), fruIdentity.end());
    data.insert(data.end(), pceIdentity.begin(), pceIdentity.end());

    // The final size
    data[0] = data.size();

    Stream stream{data};
    Callout callout{stream};

    EXPECT_EQ(callout.flattenedSize(), data.size());

    // Spot check the 2 substructures
    EXPECT_TRUE(callout.fruIdentity());
    EXPECT_EQ(callout.fruIdentity()->getSN(), "123456789ABC");

    EXPECT_TRUE(callout.pceIdentity());
    EXPECT_EQ(callout.pceIdentity()->enclosureName(), "PCENAME12");

    // Not present
    EXPECT_FALSE(callout.mru());

    // Now flatten
    std::vector<uint8_t> newData;
    Stream newStream{newData};

    callout.flatten(newStream);
    EXPECT_EQ(data, newData);
}

TEST(CalloutTest, TestNoLocationCode)
{
    std::vector<uint8_t> data{
        0xFF, 0x2B, 'H', 0x00 // size, flags, priority, LC length
    };

    auto fruIdentity = srcDataFactory(TestSRCType::fruIdentityStructure);
    data.insert(data.end(), fruIdentity.begin(), fruIdentity.end());

    // The final size
    data[0] = data.size();

    Stream stream{data};
    Callout callout{stream};

    EXPECT_TRUE(callout.locationCode().empty());
}
OpenPOWER on IntegriCloud