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 2989fa082aSMatt Spinler class CleanPELFiles : public ::testing::Test 3089fa082aSMatt Spinler { 3189fa082aSMatt Spinler protected: 3289fa082aSMatt Spinler static void SetUpTestCase() 3389fa082aSMatt Spinler { 3489fa082aSMatt Spinler pelIDFile = openpower::pels::getPELIDFile(); 3589fa082aSMatt Spinler repoPath = openpower::pels::getPELRepoPath(); 36367144cfSMatt Spinler registryPath = openpower::pels::getMessageRegistryPath(); 3789fa082aSMatt Spinler } 3889fa082aSMatt Spinler 3989fa082aSMatt Spinler static void TearDownTestCase() 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 */ 55*42828bd9SMatt Spinler enum class TestPELType 56d3335dfaSMatt Spinler { 57d3335dfaSMatt Spinler pelSimple, 58*42828bd9SMatt Spinler privateHeaderSection, 59*42828bd9SMatt Spinler userHeaderSection, 60*42828bd9SMatt Spinler primarySRCSection, 61*42828bd9SMatt Spinler primarySRCSection2Callouts 62d3335dfaSMatt Spinler }; 63d3335dfaSMatt Spinler 64d3335dfaSMatt Spinler /** 656c9662c9SMatt Spinler * @brief Tells the SRC factory which data to create 666c9662c9SMatt Spinler */ 676c9662c9SMatt Spinler enum class TestSRCType 686c9662c9SMatt Spinler { 696c9662c9SMatt Spinler fruIdentityStructure, 706c9662c9SMatt Spinler pceIdentityStructure, 716c9662c9SMatt Spinler mruStructure, 7232f13c91SMatt Spinler calloutStructureA, 73f9bae185SMatt Spinler calloutStructureB, 74*42828bd9SMatt Spinler calloutSection2Callouts 756c9662c9SMatt Spinler }; 766c9662c9SMatt Spinler 776c9662c9SMatt Spinler /** 78d3335dfaSMatt Spinler * @brief PEL data factory, for testing 79d3335dfaSMatt Spinler * 80d3335dfaSMatt Spinler * @param[in] type - the type of data to create 81d3335dfaSMatt Spinler * 82*42828bd9SMatt Spinler * @return std::vector<uint8_t> - the PEL data 83d3335dfaSMatt Spinler */ 84*42828bd9SMatt Spinler std::vector<uint8_t> pelDataFactory(TestPELType type); 85d3335dfaSMatt Spinler 86d3335dfaSMatt Spinler /** 876c9662c9SMatt Spinler * @brief SRC data factory, for testing 886c9662c9SMatt Spinler * 896c9662c9SMatt Spinler * Provides pieces of the SRC PEL section, such as a callout. 906c9662c9SMatt Spinler * 916c9662c9SMatt Spinler * @param[in] type - the type of data to create 926c9662c9SMatt Spinler * 936c9662c9SMatt Spinler * @return std::vector<uint8_t> - The SRC data 946c9662c9SMatt Spinler */ 956c9662c9SMatt Spinler std::vector<uint8_t> srcDataFactory(TestSRCType type); 966c9662c9SMatt Spinler 976c9662c9SMatt Spinler /** 98d3335dfaSMatt Spinler * @brief Helper function to read raw PEL data from a file 99d3335dfaSMatt Spinler * 100d3335dfaSMatt Spinler * @param[in] path - the path to read 101d3335dfaSMatt Spinler * 102d3335dfaSMatt Spinler * @return std::unique_ptr<std::vector<uint8_t>> - the data from the file 103d3335dfaSMatt Spinler */ 104d3335dfaSMatt Spinler std::unique_ptr<std::vector<uint8_t>> 105d3335dfaSMatt Spinler readPELFile(const std::filesystem::path& path); 106