1cb6b059eSMatt Spinler #include "extensions/openpower-pels/paths.hpp"
2cb6b059eSMatt Spinler 
3d3335dfaSMatt Spinler #include <filesystem>
4d3335dfaSMatt Spinler #include <memory>
5d3335dfaSMatt Spinler #include <vector>
6d3335dfaSMatt Spinler 
7d3335dfaSMatt Spinler #include <gtest/gtest.h>
8d3335dfaSMatt Spinler 
9d3335dfaSMatt Spinler /**
10cb6b059eSMatt Spinler  * @brief Test fixture to remove the pelID file that PELs use.
11cb6b059eSMatt Spinler  */
12cb6b059eSMatt Spinler class CleanLogID : public ::testing::Test
13cb6b059eSMatt Spinler {
14cb6b059eSMatt Spinler   protected:
15cb6b059eSMatt Spinler     static void SetUpTestCase()
16cb6b059eSMatt Spinler     {
17cb6b059eSMatt Spinler         pelIDFile = openpower::pels::getPELIDFile();
18cb6b059eSMatt Spinler     }
19cb6b059eSMatt Spinler 
20cb6b059eSMatt Spinler     static void TearDownTestCase()
21cb6b059eSMatt Spinler     {
22cb6b059eSMatt Spinler         std::filesystem::remove_all(
23cb6b059eSMatt Spinler             std::filesystem::path{pelIDFile}.parent_path());
24cb6b059eSMatt Spinler     }
25cb6b059eSMatt Spinler 
26cb6b059eSMatt Spinler     static std::filesystem::path pelIDFile;
27cb6b059eSMatt Spinler };
28cb6b059eSMatt Spinler 
29*89fa082aSMatt Spinler class CleanPELFiles : public ::testing::Test
30*89fa082aSMatt Spinler {
31*89fa082aSMatt Spinler   protected:
32*89fa082aSMatt Spinler     static void SetUpTestCase()
33*89fa082aSMatt Spinler     {
34*89fa082aSMatt Spinler         pelIDFile = openpower::pels::getPELIDFile();
35*89fa082aSMatt Spinler         repoPath = openpower::pels::getPELRepoPath();
36*89fa082aSMatt Spinler     }
37*89fa082aSMatt Spinler 
38*89fa082aSMatt Spinler     static void TearDownTestCase()
39*89fa082aSMatt Spinler     {
40*89fa082aSMatt Spinler         std::filesystem::remove_all(
41*89fa082aSMatt Spinler             std::filesystem::path{pelIDFile}.parent_path());
42*89fa082aSMatt Spinler         std::filesystem::remove_all(repoPath);
43*89fa082aSMatt Spinler     }
44*89fa082aSMatt Spinler 
45*89fa082aSMatt Spinler     static std::filesystem::path pelIDFile;
46*89fa082aSMatt Spinler     static std::filesystem::path repoPath;
47*89fa082aSMatt Spinler };
48*89fa082aSMatt Spinler 
49cb6b059eSMatt Spinler /**
50d3335dfaSMatt Spinler  * @brief Tells the factory which PEL to create
51d3335dfaSMatt Spinler  */
52d3335dfaSMatt Spinler enum class TestPelType
53d3335dfaSMatt Spinler {
54d3335dfaSMatt Spinler     pelSimple,
5503c1d915SMatt Spinler     privateHeaderSimple,
5603c1d915SMatt Spinler     userHeaderSimple
57d3335dfaSMatt Spinler };
58d3335dfaSMatt Spinler 
59d3335dfaSMatt Spinler /**
60d3335dfaSMatt Spinler  * @brief PEL data factory, for testing
61d3335dfaSMatt Spinler  *
62d3335dfaSMatt Spinler  * @param[in] type - the type of data to create
63d3335dfaSMatt Spinler  *
64d3335dfaSMatt Spinler  * @return std::unique_ptr<std::vector<uint8_t>> - the PEL data
65d3335dfaSMatt Spinler  */
66d3335dfaSMatt Spinler std::unique_ptr<std::vector<uint8_t>> pelDataFactory(TestPelType type);
67d3335dfaSMatt Spinler 
68d3335dfaSMatt Spinler /**
69d3335dfaSMatt Spinler  * @brief Helper function to read raw PEL data from a file
70d3335dfaSMatt Spinler  *
71d3335dfaSMatt Spinler  * @param[in] path - the path to read
72d3335dfaSMatt Spinler  *
73d3335dfaSMatt Spinler  * @return std::unique_ptr<std::vector<uint8_t>> - the data from the file
74d3335dfaSMatt Spinler  */
75d3335dfaSMatt Spinler std::unique_ptr<std::vector<uint8_t>>
76d3335dfaSMatt Spinler     readPELFile(const std::filesystem::path& path);
77