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 | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 16 | #include "extensions/openpower-pels/src.hpp" |
| 17 | #include "pel_utils.hpp" |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
| 21 | using namespace openpower::pels; |
| 22 | |
| 23 | TEST(SRCTest, UnflattenFlattenTestNoCallouts) |
| 24 | { |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 25 | auto data = pelDataFactory(TestPELType::primarySRCSection); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 26 | |
| 27 | Stream stream{data}; |
| 28 | SRC src{stream}; |
| 29 | |
| 30 | EXPECT_TRUE(src.valid()); |
| 31 | |
| 32 | EXPECT_EQ(src.header().id, 0x5053); |
| 33 | EXPECT_EQ(src.header().size, 0x80); |
| 34 | EXPECT_EQ(src.header().version, 0x01); |
| 35 | EXPECT_EQ(src.header().subType, 0x01); |
| 36 | EXPECT_EQ(src.header().componentID, 0x0202); |
| 37 | |
| 38 | EXPECT_EQ(src.version(), 0x02); |
| 39 | EXPECT_EQ(src.flags(), 0x00); |
| 40 | EXPECT_EQ(src.hexWordCount(), 9); |
| 41 | EXPECT_EQ(src.size(), 0x48); |
| 42 | |
| 43 | const auto& hexwords = src.hexwordData(); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 44 | EXPECT_EQ(0x02020255, hexwords[0]); |
| 45 | EXPECT_EQ(0x03030310, hexwords[1]); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 46 | EXPECT_EQ(0x04040404, hexwords[2]); |
| 47 | EXPECT_EQ(0x05050505, hexwords[3]); |
| 48 | EXPECT_EQ(0x06060606, hexwords[4]); |
| 49 | EXPECT_EQ(0x07070707, hexwords[5]); |
| 50 | EXPECT_EQ(0x08080808, hexwords[6]); |
| 51 | EXPECT_EQ(0x09090909, hexwords[7]); |
| 52 | |
| 53 | EXPECT_EQ(src.asciiString(), "BD8D5678 "); |
| 54 | EXPECT_FALSE(src.callouts()); |
| 55 | |
| 56 | // Flatten |
| 57 | std::vector<uint8_t> newData; |
| 58 | Stream newStream{newData}; |
| 59 | |
| 60 | src.flatten(newStream); |
| 61 | EXPECT_EQ(data, newData); |
| 62 | } |
| 63 | |
| 64 | TEST(SRCTest, UnflattenFlattenTest2Callouts) |
| 65 | { |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 66 | auto data = pelDataFactory(TestPELType::primarySRCSection2Callouts); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 67 | |
| 68 | Stream stream{data}; |
| 69 | SRC src{stream}; |
| 70 | |
| 71 | EXPECT_TRUE(src.valid()); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 72 | EXPECT_EQ(src.flags(), 0x01); // Additional sections within the SRC. |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 73 | |
| 74 | // Spot check the SRC fields, but they're the same as above |
| 75 | EXPECT_EQ(src.asciiString(), "BD8D5678 "); |
| 76 | |
| 77 | // There should be 2 callouts |
| 78 | const auto& calloutsSection = src.callouts(); |
| 79 | ASSERT_TRUE(calloutsSection); |
| 80 | const auto& callouts = calloutsSection->callouts(); |
| 81 | EXPECT_EQ(callouts.size(), 2); |
| 82 | |
| 83 | // spot check that each callout has the right substructures |
| 84 | EXPECT_TRUE(callouts.front()->fruIdentity()); |
| 85 | EXPECT_FALSE(callouts.front()->pceIdentity()); |
| 86 | EXPECT_FALSE(callouts.front()->mru()); |
| 87 | |
| 88 | EXPECT_TRUE(callouts.back()->fruIdentity()); |
| 89 | EXPECT_TRUE(callouts.back()->pceIdentity()); |
| 90 | EXPECT_TRUE(callouts.back()->mru()); |
| 91 | |
| 92 | // Flatten |
| 93 | std::vector<uint8_t> newData; |
| 94 | Stream newStream{newData}; |
| 95 | |
| 96 | src.flatten(newStream); |
| 97 | EXPECT_EQ(data, newData); |
| 98 | } |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 99 | |
| 100 | // Create an SRC from the message registry |
| 101 | TEST(SRCTest, CreateTestNoCallouts) |
| 102 | { |
| 103 | message::Entry entry; |
| 104 | entry.src.type = 0xBD; |
| 105 | entry.src.reasonCode = 0xABCD; |
| 106 | entry.subsystem = 0x42; |
| 107 | entry.src.powerFault = true; |
| 108 | entry.src.hexwordADFields = {{5, "TEST1"}, // Not a user defined word |
| 109 | {6, "TEST1"}, |
| 110 | {7, "TEST2"}, |
| 111 | {8, "TEST3"}, |
| 112 | {9, "TEST4"}}; |
| 113 | |
| 114 | // Values for the SRC words pointed to above |
| 115 | std::vector<std::string> adData{"TEST1=0x12345678", "TEST2=12345678", |
| 116 | "TEST3=0XDEF", "TEST4=Z"}; |
| 117 | AdditionalData ad{adData}; |
| 118 | SRC src{entry, ad}; |
| 119 | |
| 120 | EXPECT_TRUE(src.valid()); |
| 121 | EXPECT_TRUE(src.isPowerFaultEvent()); |
| 122 | EXPECT_EQ(src.size(), baseSRCSize); |
| 123 | |
| 124 | const auto& hexwords = src.hexwordData(); |
| 125 | |
| 126 | // The spec always refers to SRC words 2 - 9, and as the hexwordData() |
| 127 | // array index starts at 0 use the math in the [] below to make it easier |
| 128 | // to tell what is being accessed. |
| 129 | EXPECT_EQ(hexwords[2 - 2] & 0xF0000000, 0); // Partition dump status |
| 130 | EXPECT_EQ(hexwords[2 - 2] & 0x00F00000, 0); // Partition boot type |
| 131 | EXPECT_EQ(hexwords[2 - 2] & 0x000000FF, 0x55); // SRC format |
| 132 | EXPECT_EQ(hexwords[3 - 2] & 0x000000FF, 0x10); // BMC position |
| 133 | |
| 134 | // Validate more fields here as the code starts filling them in. |
| 135 | |
| 136 | // Ensure hex word 5 wasn't allowed to be set to TEST1's contents |
| 137 | EXPECT_EQ(hexwords[5 - 2], 0); |
| 138 | |
| 139 | // The user defined hex word fields specifed in the additional data. |
| 140 | EXPECT_EQ(hexwords[6 - 2], 0x12345678); // TEST1 |
| 141 | EXPECT_EQ(hexwords[7 - 2], 12345678); // TEST2 |
| 142 | EXPECT_EQ(hexwords[8 - 2], 0xdef); // TEST3 |
| 143 | EXPECT_EQ(hexwords[9 - 2], 0); // TEST4, but can't convert a 'Z' |
| 144 | |
| 145 | EXPECT_EQ(src.asciiString(), "BD42ABCD "); |
| 146 | |
| 147 | // No callouts |
| 148 | EXPECT_FALSE(src.callouts()); |
| 149 | |
| 150 | // May as well spot check the flatten/unflatten |
| 151 | std::vector<uint8_t> data; |
| 152 | Stream stream{data}; |
| 153 | src.flatten(stream); |
| 154 | |
| 155 | stream.offset(0); |
| 156 | SRC newSRC{stream}; |
| 157 | |
| 158 | EXPECT_TRUE(newSRC.valid()); |
| 159 | EXPECT_EQ(newSRC.isPowerFaultEvent(), src.isPowerFaultEvent()); |
| 160 | EXPECT_EQ(newSRC.asciiString(), src.asciiString()); |
| 161 | EXPECT_FALSE(newSRC.callouts()); |
| 162 | } |