1 #include "extensions/openpower-pels/paths.hpp"
2 
3 #include <filesystem>
4 #include <memory>
5 #include <vector>
6 
7 #include <gtest/gtest.h>
8 
9 /**
10  * @brief Test fixture to remove the pelID file that PELs use.
11  */
12 class 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 
29 class CleanPELFiles : public ::testing::Test
30 {
31   protected:
32     void SetUp() override
33     {
34         pelIDFile = openpower::pels::getPELIDFile();
35         repoPath = openpower::pels::getPELRepoPath();
36         registryPath = openpower::pels::getMessageRegistryPath();
37     }
38 
39     void TearDown() override
40     {
41         std::filesystem::remove_all(
42             std::filesystem::path{pelIDFile}.parent_path());
43         std::filesystem::remove_all(repoPath);
44         std::filesystem::remove_all(registryPath);
45     }
46 
47     static std::filesystem::path pelIDFile;
48     static std::filesystem::path repoPath;
49     static std::filesystem::path registryPath;
50 };
51 
52 /**
53  * @brief Tells the factory which PEL to create
54  */
55 enum class TestPELType
56 {
57     pelSimple,
58     privateHeaderSection,
59     userHeaderSection,
60     primarySRCSection,
61     primarySRCSection2Callouts,
62     failingMTMSSection
63 };
64 
65 /**
66  * @brief Tells the SRC factory which data to create
67  */
68 enum class TestSRCType
69 {
70     fruIdentityStructure,
71     pceIdentityStructure,
72     mruStructure,
73     calloutStructureA,
74     calloutStructureB,
75     calloutSection2Callouts
76 };
77 
78 /**
79  * @brief PEL data factory, for testing
80  *
81  * @param[in] type - the type of data to create
82  *
83  * @return std::vector<uint8_t> - the PEL data
84  */
85 std::vector<uint8_t> pelDataFactory(TestPELType type);
86 
87 /**
88  * @brief SRC data factory, for testing
89  *
90  * Provides pieces of the SRC PEL section, such as a callout.
91  *
92  * @param[in] type - the type of data to create
93  *
94  * @return std::vector<uint8_t> - The SRC data
95  */
96 std::vector<uint8_t> srcDataFactory(TestSRCType type);
97 
98 /**
99  * @brief Helper function to read raw PEL data from a file
100  *
101  * @param[in] path - the path to read
102  *
103  * @return std::unique_ptr<std::vector<uint8_t>> - the data from the file
104  */
105 std::unique_ptr<std::vector<uint8_t>>
106     readPELFile(const std::filesystem::path& path);
107