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: |
| 32 | static void SetUpTestCase() |
| 33 | { |
| 34 | pelIDFile = openpower::pels::getPELIDFile(); |
| 35 | repoPath = openpower::pels::getPELRepoPath(); |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 36 | registryPath = openpower::pels::getMessageRegistryPath(); |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static void TearDownTestCase() |
| 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 | */ |
| 55 | enum class TestPelType |
| 56 | { |
| 57 | pelSimple, |
Matt Spinler | 03c1d91 | 2019-07-10 14:12:15 -0500 | [diff] [blame] | 58 | privateHeaderSimple, |
| 59 | userHeaderSimple |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | /** |
| 63 | * @brief PEL data factory, for testing |
| 64 | * |
| 65 | * @param[in] type - the type of data to create |
| 66 | * |
| 67 | * @return std::unique_ptr<std::vector<uint8_t>> - the PEL data |
| 68 | */ |
| 69 | std::unique_ptr<std::vector<uint8_t>> pelDataFactory(TestPelType type); |
| 70 | |
| 71 | /** |
| 72 | * @brief Helper function to read raw PEL data from a file |
| 73 | * |
| 74 | * @param[in] path - the path to read |
| 75 | * |
| 76 | * @return std::unique_ptr<std::vector<uint8_t>> - the data from the file |
| 77 | */ |
| 78 | std::unique_ptr<std::vector<uint8_t>> |
| 79 | readPELFile(const std::filesystem::path& path); |