Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 1 | #include "pel_utils.hpp" |
| 2 | |
| 3 | #include "extensions/openpower-pels/private_header.hpp" |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 4 | #include "extensions/openpower-pels/user_header.hpp" |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 5 | |
| 6 | #include <fstream> |
| 7 | |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | namespace fs = std::filesystem; |
| 11 | using namespace openpower::pels; |
| 12 | |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 13 | std::filesystem::path CleanLogID::pelIDFile{}; |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 14 | std::filesystem::path CleanPELFiles::pelIDFile{}; |
| 15 | std::filesystem::path CleanPELFiles::repoPath{}; |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 16 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 17 | constexpr uint8_t simplePEL[] = { |
| 18 | // private header section header |
| 19 | 0x50, 0x48, // ID 'PH' |
| 20 | 0x00, 0x30, // Size |
| 21 | 0x01, 0x02, // version, subtype |
| 22 | 0x03, 0x04, // comp ID |
| 23 | |
| 24 | // private header |
| 25 | 0x20, 0x30, 0x05, 0x09, 0x11, 0x1E, 0x1, 0x63, // create timestamp |
| 26 | 0x20, 0x31, 0x06, 0x0F, 0x09, 0x22, 0x3A, 0x00, // commit timestamp |
| 27 | 0xAA, // creatorID |
| 28 | 0x00, // logtype |
| 29 | 0x00, // reserved |
| 30 | 0x02, // section count |
| 31 | 0x90, 0x91, 0x92, 0x93, // OpenBMC log ID |
| 32 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, // creator version |
| 33 | 0x50, 0x51, 0x52, 0x53, // plid |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 34 | 0x80, 0x81, 0x82, 0x83, // id |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 35 | |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 36 | // user header section header |
| 37 | 0x55, 0x48, // ID 'UH' |
| 38 | 0x00, 0x18, // Size |
| 39 | 0x01, 0x0A, // version, subtype |
| 40 | 0x0B, 0x0C, // comp ID |
| 41 | |
| 42 | // user header |
| 43 | 0x10, 0x04, // subsystem, scope |
| 44 | 0x20, 0x00, // severity, type |
| 45 | 0x00, 0x00, 0x00, 0x00, // reserved |
| 46 | 0x03, 0x04, // problem domain, vector |
| 47 | 0x80, 0xC0, // action flags |
| 48 | 0x00, 0x00, 0x00, 0x00 // reserved |
| 49 | |
| 50 | // Add more as the code supports more |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | std::unique_ptr<std::vector<uint8_t>> pelDataFactory(TestPelType type) |
| 54 | { |
| 55 | std::unique_ptr<std::vector<uint8_t>> data; |
| 56 | switch (type) |
| 57 | { |
| 58 | case TestPelType::pelSimple: |
| 59 | data = std::make_unique<std::vector<uint8_t>>( |
| 60 | simplePEL, simplePEL + sizeof(simplePEL)); |
| 61 | break; |
| 62 | case TestPelType::privateHeaderSimple: |
| 63 | data = std::make_unique<std::vector<uint8_t>>( |
| 64 | simplePEL, simplePEL + PrivateHeader::flattenedSize()); |
| 65 | break; |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 66 | case TestPelType::userHeaderSimple: |
| 67 | data = std::make_unique<std::vector<uint8_t>>( |
| 68 | simplePEL + PrivateHeader::flattenedSize(), |
| 69 | simplePEL + PrivateHeader::flattenedSize() + |
| 70 | UserHeader::flattenedSize()); |
| 71 | break; |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 72 | } |
| 73 | return data; |
| 74 | } |
| 75 | |
| 76 | std::unique_ptr<std::vector<uint8_t>> readPELFile(const fs::path& path) |
| 77 | { |
| 78 | std::ifstream file{path}; |
| 79 | |
| 80 | auto pel = std::make_unique<std::vector<uint8_t>>( |
| 81 | std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()); |
| 82 | return pel; |
| 83 | } |