Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 1 | #include "extensions/openpower-pels/paths.hpp" |
| 2 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 3 | #include <filesystem> |
| 4 | #include <memory> |
| 5 | #include <vector> |
| 6 | |
| 7 | #include <gtest/gtest.h> |
| 8 | |
| 9 | /** |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 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 | |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 29 | class CleanPELFiles : public ::testing::Test |
| 30 | { |
| 31 | protected: |
Matt Spinler | a943b15 | 2019-12-11 14:44:50 -0600 | [diff] [blame] | 32 | void SetUp() override |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 33 | { |
| 34 | pelIDFile = openpower::pels::getPELIDFile(); |
| 35 | repoPath = openpower::pels::getPELRepoPath(); |
Matt Spinler | 0d804ef | 2020-05-12 16:16:26 -0500 | [diff] [blame] | 36 | registryPath = openpower::pels::getPELReadOnlyDataPath(); |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 37 | } |
| 38 | |
Matt Spinler | a943b15 | 2019-12-11 14:44:50 -0600 | [diff] [blame] | 39 | void TearDown() override |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 40 | { |
| 41 | std::filesystem::remove_all( |
| 42 | std::filesystem::path{pelIDFile}.parent_path()); |
| 43 | std::filesystem::remove_all(repoPath); |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 44 | std::filesystem::remove_all(registryPath); |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static std::filesystem::path pelIDFile; |
| 48 | static std::filesystem::path repoPath; |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 49 | static std::filesystem::path registryPath; |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 50 | }; |
| 51 | |
Matt Spinler | cb6b059 | 2019-07-16 15:58:51 -0500 | [diff] [blame] | 52 | /** |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 53 | * @brief Tells the factory which PEL to create |
| 54 | */ |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 55 | enum class TestPELType |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 56 | { |
| 57 | pelSimple, |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 58 | privateHeaderSection, |
| 59 | userHeaderSection, |
| 60 | primarySRCSection, |
Matt Spinler | 213e5c1 | 2019-10-11 10:57:49 -0500 | [diff] [blame] | 61 | primarySRCSection2Callouts, |
Matt Spinler | 386a61e | 2020-08-13 15:51:12 -0500 | [diff] [blame] | 62 | failingMTMSSection, |
| 63 | extendedUserDataSection |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | /** |
Matt Spinler | 6c9662c | 2019-10-09 11:27:20 -0500 | [diff] [blame] | 67 | * @brief Tells the SRC factory which data to create |
| 68 | */ |
| 69 | enum class TestSRCType |
| 70 | { |
| 71 | fruIdentityStructure, |
| 72 | pceIdentityStructure, |
| 73 | mruStructure, |
Matt Spinler | 32f13c9 | 2019-10-09 12:48:25 -0500 | [diff] [blame] | 74 | calloutStructureA, |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 75 | calloutStructureB, |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 76 | calloutSection2Callouts |
Matt Spinler | 6c9662c | 2019-10-09 11:27:20 -0500 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | /** |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 80 | * @brief PEL data factory, for testing |
| 81 | * |
| 82 | * @param[in] type - the type of data to create |
| 83 | * |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 84 | * @return std::vector<uint8_t> - the PEL data |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 85 | */ |
Matt Spinler | 42828bd | 2019-10-11 10:39:30 -0500 | [diff] [blame] | 86 | std::vector<uint8_t> pelDataFactory(TestPELType type); |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 87 | |
| 88 | /** |
Matt Spinler | 454f656 | 2020-07-07 11:22:47 -0500 | [diff] [blame] | 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 | /** |
Matt Spinler | 6c9662c | 2019-10-09 11:27:20 -0500 | [diff] [blame] | 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 | /** |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 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); |