| Alexander Hansen | 40fb549 | 2025-10-28 17:56:12 +0100 | [diff] [blame^] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2019 IBM Corporation |
| 3 | |
| Matt Spinler | 5b3a11d | 2019-10-08 14:13:31 -0500 | [diff] [blame] | 4 | #include "extensions/openpower-pels/pce_identity.hpp" |
| 5 | |
| 6 | #include <gtest/gtest.h> |
| 7 | |
| 8 | using namespace openpower::pels; |
| 9 | using namespace openpower::pels::src; |
| 10 | |
| 11 | TEST(PCEIdentityTest, TestConstructor) |
| 12 | { |
| 13 | std::vector<uint8_t> data{ |
| 14 | 'P', 'E', 0x24, 0x00, // type, size, flags |
| 15 | 'T', 'T', 'T', 'T', '-', 'M', 'M', 'M', // MTM |
| 16 | '1', '2', '3', '4', '5', '6', '7', // SN |
| 17 | '8', '9', 'A', 'B', 'C', 'P', 'C', 'E', // Name + null padded |
| 18 | 'N', 'A', 'M', 'E', '1', '2', 0x00, 0x00, 0x00}; |
| 19 | |
| 20 | Stream stream{data}; |
| 21 | |
| 22 | PCEIdentity pce{stream}; |
| 23 | |
| 24 | EXPECT_EQ(pce.flattenedSize(), data.size()); |
| 25 | EXPECT_EQ(pce.enclosureName(), "PCENAME12"); |
| 26 | EXPECT_EQ(pce.mtms().machineTypeAndModel(), "TTTT-MMM"); |
| 27 | EXPECT_EQ(pce.mtms().machineSerialNumber(), "123456789ABC"); |
| 28 | |
| 29 | // Flatten it |
| 30 | std::vector<uint8_t> newData; |
| 31 | Stream newStream{newData}; |
| 32 | pce.flatten(newStream); |
| 33 | |
| 34 | EXPECT_EQ(data, newData); |
| 35 | } |
| 36 | |
| 37 | TEST(PCEIdentityTest, TestBadData) |
| 38 | { |
| 39 | std::vector<uint8_t> data{ |
| 40 | 'P', 'E', 0x20, 0x00, 'T', 'T', 'T', 'T', '-', |
| 41 | }; |
| 42 | |
| 43 | Stream stream{data}; |
| 44 | EXPECT_THROW(PCEIdentity pce{stream}, std::out_of_range); |
| 45 | } |