blob: b6714eb9cde72093cbdadb508750c9fee2741469 [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
13constexpr uint8_t simplePEL[] = {
14 // private header section header
15 0x50, 0x48, // ID 'PH'
16 0x00, 0x30, // Size
17 0x01, 0x02, // version, subtype
18 0x03, 0x04, // comp ID
19
20 // private header
21 0x20, 0x30, 0x05, 0x09, 0x11, 0x1E, 0x1, 0x63, // create timestamp
22 0x20, 0x31, 0x06, 0x0F, 0x09, 0x22, 0x3A, 0x00, // commit timestamp
23 0xAA, // creatorID
24 0x00, // logtype
25 0x00, // reserved
26 0x02, // section count
27 0x90, 0x91, 0x92, 0x93, // OpenBMC log ID
28 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0, // creator version
29 0x50, 0x51, 0x52, 0x53, // plid
Matt Spinler03c1d912019-07-10 14:12:15 -050030 0x80, 0x81, 0x82, 0x83, // id
Matt Spinlerd3335df2019-07-10 11:04:21 -050031
Matt Spinler03c1d912019-07-10 14:12:15 -050032 // user header section header
33 0x55, 0x48, // ID 'UH'
34 0x00, 0x18, // Size
35 0x01, 0x0A, // version, subtype
36 0x0B, 0x0C, // comp ID
37
38 // user header
39 0x10, 0x04, // subsystem, scope
40 0x20, 0x00, // severity, type
41 0x00, 0x00, 0x00, 0x00, // reserved
42 0x03, 0x04, // problem domain, vector
43 0x80, 0xC0, // action flags
44 0x00, 0x00, 0x00, 0x00 // reserved
45
46 // Add more as the code supports more
Matt Spinlerd3335df2019-07-10 11:04:21 -050047};
48
49std::unique_ptr<std::vector<uint8_t>> pelDataFactory(TestPelType type)
50{
51 std::unique_ptr<std::vector<uint8_t>> data;
52 switch (type)
53 {
54 case TestPelType::pelSimple:
55 data = std::make_unique<std::vector<uint8_t>>(
56 simplePEL, simplePEL + sizeof(simplePEL));
57 break;
58 case TestPelType::privateHeaderSimple:
59 data = std::make_unique<std::vector<uint8_t>>(
60 simplePEL, simplePEL + PrivateHeader::flattenedSize());
61 break;
Matt Spinler03c1d912019-07-10 14:12:15 -050062 case TestPelType::userHeaderSimple:
63 data = std::make_unique<std::vector<uint8_t>>(
64 simplePEL + PrivateHeader::flattenedSize(),
65 simplePEL + PrivateHeader::flattenedSize() +
66 UserHeader::flattenedSize());
67 break;
Matt Spinlerd3335df2019-07-10 11:04:21 -050068 }
69 return data;
70}
71
72std::unique_ptr<std::vector<uint8_t>> readPELFile(const fs::path& path)
73{
74 std::ifstream file{path};
75
76 auto pel = std::make_unique<std::vector<uint8_t>>(
77 std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
78 return pel;
79}