blob: de41dbb40ede6d2dc833a8d6959d600d770785bc [file] [log] [blame]
Matt Spinler97f7abc2019-11-06 09:40:23 -06001/**
2 * Copyright © 2019 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matt Spinler5b3a11d2019-10-08 14:13:31 -050016#include "extensions/openpower-pels/pce_identity.hpp"
17
18#include <gtest/gtest.h>
19
20using namespace openpower::pels;
21using namespace openpower::pels::src;
22
23TEST(PCEIdentityTest, TestConstructor)
24{
25 std::vector<uint8_t> data{
26 'P', 'E', 0x24, 0x00, // type, size, flags
27 'T', 'T', 'T', 'T', '-', 'M', 'M', 'M', // MTM
28 '1', '2', '3', '4', '5', '6', '7', // SN
29 '8', '9', 'A', 'B', 'C', 'P', 'C', 'E', // Name + null padded
30 'N', 'A', 'M', 'E', '1', '2', 0x00, 0x00, 0x00};
31
32 Stream stream{data};
33
34 PCEIdentity pce{stream};
35
36 EXPECT_EQ(pce.flattenedSize(), data.size());
37 EXPECT_EQ(pce.enclosureName(), "PCENAME12");
38 EXPECT_EQ(pce.mtms().machineTypeAndModel(), "TTTT-MMM");
39 EXPECT_EQ(pce.mtms().machineSerialNumber(), "123456789ABC");
40
41 // Flatten it
42 std::vector<uint8_t> newData;
43 Stream newStream{newData};
44 pce.flatten(newStream);
45
46 EXPECT_EQ(data, newData);
47}
48
49TEST(PCEIdentityTest, TestBadData)
50{
51 std::vector<uint8_t> data{
52 'P', 'E', 0x20, 0x00, 'T', 'T', 'T', 'T', '-',
53 };
54
55 Stream stream{data};
56 EXPECT_THROW(PCEIdentity pce{stream}, std::out_of_range);
57}