blob: 1c4eebb3640bd279ec91f97ce0f28bf10eceaf06 [file] [log] [blame]
Matt Spinlercb6b0592019-07-16 15:58:51 -05001#include "extensions/openpower-pels/paths.hpp"
2
Matt Spinlerd3335df2019-07-10 11:04:21 -05003#include <filesystem>
4#include <memory>
5#include <vector>
6
7#include <gtest/gtest.h>
8
9/**
Matt Spinlercb6b0592019-07-16 15:58:51 -050010 * @brief Test fixture to remove the pelID file that PELs use.
11 */
12class CleanLogID : public ::testing::Test
13{
14 protected:
15 static void SetUpTestCase()
16 {
17 pelIDFile = openpower::pels::getPELIDFile();
18 }
19
20 static void TearDownTestCase()
21 {
22 std::filesystem::remove_all(
23 std::filesystem::path{pelIDFile}.parent_path());
24 }
25
26 static std::filesystem::path pelIDFile;
27};
28
Matt Spinler89fa0822019-07-17 13:54:30 -050029class CleanPELFiles : public ::testing::Test
30{
31 protected:
Matt Spinlera943b152019-12-11 14:44:50 -060032 void SetUp() override
Matt Spinler89fa0822019-07-17 13:54:30 -050033 {
34 pelIDFile = openpower::pels::getPELIDFile();
35 repoPath = openpower::pels::getPELRepoPath();
Matt Spinler0d804ef2020-05-12 16:16:26 -050036 registryPath = openpower::pels::getPELReadOnlyDataPath();
Matt Spinler89fa0822019-07-17 13:54:30 -050037 }
38
Matt Spinlera943b152019-12-11 14:44:50 -060039 void TearDown() override
Matt Spinler89fa0822019-07-17 13:54:30 -050040 {
41 std::filesystem::remove_all(
42 std::filesystem::path{pelIDFile}.parent_path());
43 std::filesystem::remove_all(repoPath);
Matt Spinler367144c2019-09-19 15:33:52 -050044 std::filesystem::remove_all(registryPath);
Matt Spinler89fa0822019-07-17 13:54:30 -050045 }
46
47 static std::filesystem::path pelIDFile;
48 static std::filesystem::path repoPath;
Matt Spinler367144c2019-09-19 15:33:52 -050049 static std::filesystem::path registryPath;
Matt Spinler89fa0822019-07-17 13:54:30 -050050};
51
Matt Spinlercb6b0592019-07-16 15:58:51 -050052/**
Matt Spinlerd3335df2019-07-10 11:04:21 -050053 * @brief Tells the factory which PEL to create
54 */
Matt Spinler42828bd2019-10-11 10:39:30 -050055enum class TestPELType
Matt Spinlerd3335df2019-07-10 11:04:21 -050056{
57 pelSimple,
Matt Spinler42828bd2019-10-11 10:39:30 -050058 privateHeaderSection,
59 userHeaderSection,
60 primarySRCSection,
Matt Spinler213e5c12019-10-11 10:57:49 -050061 primarySRCSection2Callouts,
62 failingMTMSSection
Matt Spinlerd3335df2019-07-10 11:04:21 -050063};
64
65/**
Matt Spinler6c9662c2019-10-09 11:27:20 -050066 * @brief Tells the SRC factory which data to create
67 */
68enum class TestSRCType
69{
70 fruIdentityStructure,
71 pceIdentityStructure,
72 mruStructure,
Matt Spinler32f13c92019-10-09 12:48:25 -050073 calloutStructureA,
Matt Spinlerf9bae182019-10-09 13:37:38 -050074 calloutStructureB,
Matt Spinler42828bd2019-10-11 10:39:30 -050075 calloutSection2Callouts
Matt Spinler6c9662c2019-10-09 11:27:20 -050076};
77
78/**
Matt Spinlerd3335df2019-07-10 11:04:21 -050079 * @brief PEL data factory, for testing
80 *
81 * @param[in] type - the type of data to create
82 *
Matt Spinler42828bd2019-10-11 10:39:30 -050083 * @return std::vector<uint8_t> - the PEL data
Matt Spinlerd3335df2019-07-10 11:04:21 -050084 */
Matt Spinler42828bd2019-10-11 10:39:30 -050085std::vector<uint8_t> pelDataFactory(TestPELType type);
Matt Spinlerd3335df2019-07-10 11:04:21 -050086
87/**
Matt Spinler454f6562020-07-07 11:22:47 -050088 * @brief PEL factory to create a PEL with the specified fields.
89 *
90 * The size is obtained by adding a UserData section of
91 * the size necessary after adding the 5 required sections.
92 *
93 * @param[in] id - The desired PEL ID
94 * @param[in] creatorID - The desired creator ID
95 * @param[in] severity - The desired severity
96 * @param[in] actionFlags - The desired action flags
97 * @param[in] size - The desired size.
98 * Must be:
99 * * 4B aligned
100 * * min 276 (size of the 5 required sections)
101 * * max 16834
102 *
103 * @return std::vector<uint8_t> - The PEL data
104 */
105std::vector<uint8_t> pelFactory(uint32_t id, char creatorID, uint8_t severity,
106 uint16_t actionFlags, size_t size);
107
108/**
Matt Spinler6c9662c2019-10-09 11:27:20 -0500109 * @brief SRC data factory, for testing
110 *
111 * Provides pieces of the SRC PEL section, such as a callout.
112 *
113 * @param[in] type - the type of data to create
114 *
115 * @return std::vector<uint8_t> - The SRC data
116 */
117std::vector<uint8_t> srcDataFactory(TestSRCType type);
118
119/**
Matt Spinlerd3335df2019-07-10 11:04:21 -0500120 * @brief Helper function to read raw PEL data from a file
121 *
122 * @param[in] path - the path to read
123 *
124 * @return std::unique_ptr<std::vector<uint8_t>> - the data from the file
125 */
126std::unique_ptr<std::vector<uint8_t>>
127 readPELFile(const std::filesystem::path& path);