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:
SetUpTestCase()15cb6b059eSMatt Spinler     static void SetUpTestCase()
16cb6b059eSMatt Spinler     {
17cb6b059eSMatt Spinler         pelIDFile = openpower::pels::getPELIDFile();
18cb6b059eSMatt Spinler     }
19cb6b059eSMatt Spinler 
TearDownTestCase()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 
2989fa082aSMatt Spinler class CleanPELFiles : public ::testing::Test
3089fa082aSMatt Spinler {
3189fa082aSMatt Spinler   protected:
SetUp()32a943b15bSMatt Spinler     void SetUp() override
3389fa082aSMatt Spinler     {
3489fa082aSMatt Spinler         pelIDFile = openpower::pels::getPELIDFile();
3589fa082aSMatt Spinler         repoPath = openpower::pels::getPELRepoPath();
360d804ef5SMatt Spinler         registryPath = openpower::pels::getPELReadOnlyDataPath();
3789fa082aSMatt Spinler     }
3889fa082aSMatt Spinler 
TearDown()39a943b15bSMatt Spinler     void TearDown() override
4089fa082aSMatt Spinler     {
4189fa082aSMatt Spinler         std::filesystem::remove_all(
4289fa082aSMatt Spinler             std::filesystem::path{pelIDFile}.parent_path());
4389fa082aSMatt Spinler         std::filesystem::remove_all(repoPath);
44367144cfSMatt Spinler         std::filesystem::remove_all(registryPath);
4589fa082aSMatt Spinler     }
4689fa082aSMatt Spinler 
4789fa082aSMatt Spinler     static std::filesystem::path pelIDFile;
4889fa082aSMatt Spinler     static std::filesystem::path repoPath;
49367144cfSMatt Spinler     static std::filesystem::path registryPath;
5089fa082aSMatt Spinler };
5189fa082aSMatt Spinler 
52cb6b059eSMatt Spinler /**
53d3335dfaSMatt Spinler  * @brief Tells the factory which PEL to create
54d3335dfaSMatt Spinler  */
5542828bd9SMatt Spinler enum class TestPELType
56d3335dfaSMatt Spinler {
57d3335dfaSMatt Spinler     pelSimple,
5842828bd9SMatt Spinler     privateHeaderSection,
5942828bd9SMatt Spinler     userHeaderSection,
6042828bd9SMatt Spinler     primarySRCSection,
61213e5c1bSMatt Spinler     primarySRCSection2Callouts,
62*386a61e6SMatt Spinler     failingMTMSSection,
63*386a61e6SMatt Spinler     extendedUserDataSection
64d3335dfaSMatt Spinler };
65d3335dfaSMatt Spinler 
66d3335dfaSMatt Spinler /**
676c9662c9SMatt Spinler  * @brief Tells the SRC factory which data to create
686c9662c9SMatt Spinler  */
696c9662c9SMatt Spinler enum class TestSRCType
706c9662c9SMatt Spinler {
716c9662c9SMatt Spinler     fruIdentityStructure,
726c9662c9SMatt Spinler     pceIdentityStructure,
736c9662c9SMatt Spinler     mruStructure,
7432f13c91SMatt Spinler     calloutStructureA,
75f9bae185SMatt Spinler     calloutStructureB,
7642828bd9SMatt Spinler     calloutSection2Callouts
776c9662c9SMatt Spinler };
786c9662c9SMatt Spinler 
796c9662c9SMatt Spinler /**
80d3335dfaSMatt Spinler  * @brief PEL data factory, for testing
81d3335dfaSMatt Spinler  *
82d3335dfaSMatt Spinler  * @param[in] type - the type of data to create
83d3335dfaSMatt Spinler  *
8442828bd9SMatt Spinler  * @return std::vector<uint8_t> - the PEL data
85d3335dfaSMatt Spinler  */
8642828bd9SMatt Spinler std::vector<uint8_t> pelDataFactory(TestPELType type);
87d3335dfaSMatt Spinler 
88d3335dfaSMatt Spinler /**
89454f656fSMatt Spinler  * @brief PEL factory to create a PEL with the specified fields.
90454f656fSMatt Spinler  *
91454f656fSMatt Spinler  * The size is obtained by adding a UserData section of
92454f656fSMatt Spinler  * the size necessary after adding the 5 required sections.
93454f656fSMatt Spinler  *
94454f656fSMatt Spinler  * @param[in] id - The desired PEL ID
95454f656fSMatt Spinler  * @param[in] creatorID - The desired creator ID
96454f656fSMatt Spinler  * @param[in] severity - The desired severity
97454f656fSMatt Spinler  * @param[in] actionFlags - The desired action flags
98454f656fSMatt Spinler  * @param[in] size - The desired size.
99454f656fSMatt Spinler  *                   Must be:
100454f656fSMatt Spinler  *                     * 4B aligned
101454f656fSMatt Spinler  *                     * min 276 (size of the 5 required sections)
102454f656fSMatt Spinler  *                     * max 16834
103454f656fSMatt Spinler  *
104454f656fSMatt Spinler  * @return std::vector<uint8_t> - The PEL data
105454f656fSMatt Spinler  */
106454f656fSMatt Spinler std::vector<uint8_t> pelFactory(uint32_t id, char creatorID, uint8_t severity,
107454f656fSMatt Spinler                                 uint16_t actionFlags, size_t size);
108454f656fSMatt Spinler 
109454f656fSMatt Spinler /**
1106c9662c9SMatt Spinler  * @brief SRC data factory, for testing
1116c9662c9SMatt Spinler  *
1126c9662c9SMatt Spinler  * Provides pieces of the SRC PEL section, such as a callout.
1136c9662c9SMatt Spinler  *
1146c9662c9SMatt Spinler  * @param[in] type - the type of data to create
1156c9662c9SMatt Spinler  *
1166c9662c9SMatt Spinler  * @return std::vector<uint8_t> - The SRC data
1176c9662c9SMatt Spinler  */
1186c9662c9SMatt Spinler std::vector<uint8_t> srcDataFactory(TestSRCType type);
1196c9662c9SMatt Spinler 
1206c9662c9SMatt Spinler /**
121d3335dfaSMatt Spinler  * @brief Helper function to read raw PEL data from a file
122d3335dfaSMatt Spinler  *
123d3335dfaSMatt Spinler  * @param[in] path - the path to read
124d3335dfaSMatt Spinler  *
125d3335dfaSMatt Spinler  * @return std::unique_ptr<std::vector<uint8_t>> - the data from the file
126d3335dfaSMatt Spinler  */
127d3335dfaSMatt Spinler std::unique_ptr<std::vector<uint8_t>>
128d3335dfaSMatt Spinler     readPELFile(const std::filesystem::path& path);
129