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