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::getPELReadOnlyDataPath(); 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 extendedUserDataSection 64 }; 65 66 /** 67 * @brief Tells the SRC factory which data to create 68 */ 69 enum class TestSRCType 70 { 71 fruIdentityStructure, 72 pceIdentityStructure, 73 mruStructure, 74 calloutStructureA, 75 calloutStructureB, 76 calloutSection2Callouts 77 }; 78 79 /** 80 * @brief PEL data factory, for testing 81 * 82 * @param[in] type - the type of data to create 83 * 84 * @return std::vector<uint8_t> - the PEL data 85 */ 86 std::vector<uint8_t> pelDataFactory(TestPELType type); 87 88 /** 89 * @brief PEL factory to create a PEL with the specified fields. 90 * 91 * The size is obtained by adding a UserData section of 92 * the size necessary after adding the 5 required sections. 93 * 94 * @param[in] id - The desired PEL ID 95 * @param[in] creatorID - The desired creator ID 96 * @param[in] severity - The desired severity 97 * @param[in] actionFlags - The desired action flags 98 * @param[in] size - The desired size. 99 * Must be: 100 * * 4B aligned 101 * * min 276 (size of the 5 required sections) 102 * * max 16834 103 * 104 * @return std::vector<uint8_t> - The PEL data 105 */ 106 std::vector<uint8_t> pelFactory(uint32_t id, char creatorID, uint8_t severity, 107 uint16_t actionFlags, size_t size); 108 109 /** 110 * @brief SRC data factory, for testing 111 * 112 * Provides pieces of the SRC PEL section, such as a callout. 113 * 114 * @param[in] type - the type of data to create 115 * 116 * @return std::vector<uint8_t> - The SRC data 117 */ 118 std::vector<uint8_t> srcDataFactory(TestSRCType type); 119 120 /** 121 * @brief Helper function to read raw PEL data from a file 122 * 123 * @param[in] path - the path to read 124 * 125 * @return std::unique_ptr<std::vector<uint8_t>> - the data from the file 126 */ 127 std::unique_ptr<std::vector<uint8_t>> 128 readPELFile(const std::filesystem::path& path); 129