| Matt Spinler | 97f7abc | 2019-11-06 09:40:23 -0600 | [diff] [blame] | 1 | /** | 
 | 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 Spinler | 6852d72 | 2019-09-30 15:35:53 -0500 | [diff] [blame] | 16 | #include "extensions/openpower-pels/ascii_string.hpp" | 
 | 17 | #include "extensions/openpower-pels/registry.hpp" | 
 | 18 |  | 
 | 19 | #include <gtest/gtest.h> | 
 | 20 |  | 
 | 21 | using namespace openpower::pels; | 
 | 22 |  | 
 | 23 | TEST(AsciiStringTest, AsciiStringTest) | 
 | 24 | { | 
 | 25 |     // Build the ASCII string from a message registry entry | 
 | 26 |     message::Entry entry; | 
 | 27 |     entry.src.type = 0xBD; | 
 | 28 |     entry.src.reasonCode = 0xABCD; | 
 | 29 |     entry.subsystem = 0x37; | 
 | 30 |  | 
 | 31 |     src::AsciiString as{entry}; | 
 | 32 |  | 
 | 33 |     auto data = as.get(); | 
 | 34 |  | 
 | 35 |     EXPECT_EQ(data, "BD37ABCD                        "); | 
 | 36 |  | 
 | 37 |     // Now flatten it | 
 | 38 |     std::vector<uint8_t> flattenedData; | 
 | 39 |     Stream stream{flattenedData}; | 
 | 40 |  | 
 | 41 |     as.flatten(stream); | 
 | 42 |  | 
 | 43 |     for (size_t i = 0; i < 32; i++) | 
 | 44 |     { | 
 | 45 |         EXPECT_EQ(data[i], flattenedData[i]); | 
 | 46 |     } | 
 | 47 | } | 
 | 48 |  | 
 | 49 | // A 0x11 power SRC doesn't have the subsystem in it | 
 | 50 | TEST(AsciiStringTest, PowerErrorTest) | 
 | 51 | { | 
 | 52 |     message::Entry entry; | 
 | 53 |     entry.src.type = 0x11; | 
 | 54 |     entry.src.reasonCode = 0xABCD; | 
 | 55 |     entry.subsystem = 0x37; | 
 | 56 |  | 
 | 57 |     src::AsciiString as{entry}; | 
 | 58 |     auto data = as.get(); | 
 | 59 |  | 
 | 60 |     EXPECT_EQ(data, "1100ABCD                        "); | 
 | 61 | } | 
 | 62 |  | 
 | 63 | TEST(AsciiStringTest, UnflattenTest) | 
 | 64 | { | 
 | 65 |     std::vector<uint8_t> rawData{'B', 'D', '5', '6', '1', '2', 'A', 'B'}; | 
 | 66 |  | 
 | 67 |     for (int i = 8; i < 32; i++) | 
 | 68 |     { | 
 | 69 |         rawData.push_back(' '); | 
 | 70 |     } | 
 | 71 |  | 
 | 72 |     Stream stream{rawData}; | 
 | 73 |     src::AsciiString as{stream}; | 
 | 74 |  | 
 | 75 |     auto data = as.get(); | 
 | 76 |  | 
 | 77 |     EXPECT_EQ(data, "BD5612AB                        "); | 
 | 78 | } | 
 | 79 |  | 
 | 80 | TEST(AsciiStringTest, UnderflowTest) | 
 | 81 | { | 
 | 82 |     std::vector<uint8_t> rawData{'B', 'D', '5', '6'}; | 
 | 83 |     Stream stream{rawData}; | 
 | 84 |  | 
 | 85 |     EXPECT_THROW(src::AsciiString as{stream}, std::out_of_range); | 
 | 86 | } | 
| Matt Spinler | 23970b0 | 2022-02-25 16:34:46 -0600 | [diff] [blame] | 87 |  | 
 | 88 | TEST(AsciiStringTest, MissingSubsystemTest) | 
 | 89 | { | 
 | 90 |     message::Entry entry; | 
 | 91 |     entry.src.type = 0xBD; | 
 | 92 |     entry.src.reasonCode = 0xABCD; | 
 | 93 |  | 
 | 94 |     src::AsciiString as{entry}; | 
 | 95 |     auto data = as.get(); | 
 | 96 |  | 
 | 97 |     // Default subsystem is 0x70 | 
 | 98 |     EXPECT_EQ(data, "BD70ABCD                        "); | 
 | 99 | } |