blob: 262a6e76ffb66f0aafa6d2186f293903f0689cb9 [file] [log] [blame]
Matt Spinlercb6b0592019-07-16 15:58:51 -05001#include "extensions/openpower-pels/paths.hpp"
2
Matt Spinlerd3335df2019-07-10 11:04:21 -05003#include <filesystem>
4#include <memory>
5#include <vector>
6
7#include <gtest/gtest.h>
8
9/**
Matt Spinlercb6b0592019-07-16 15:58:51 -050010 * @brief Test fixture to remove the pelID file that PELs use.
11 */
12class 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 Spinler89fa0822019-07-17 13:54:30 -050029class CleanPELFiles : public ::testing::Test
30{
31 protected:
32 static void SetUpTestCase()
33 {
34 pelIDFile = openpower::pels::getPELIDFile();
35 repoPath = openpower::pels::getPELRepoPath();
36 }
37
38 static void TearDownTestCase()
39 {
40 std::filesystem::remove_all(
41 std::filesystem::path{pelIDFile}.parent_path());
42 std::filesystem::remove_all(repoPath);
43 }
44
45 static std::filesystem::path pelIDFile;
46 static std::filesystem::path repoPath;
47};
48
Matt Spinlercb6b0592019-07-16 15:58:51 -050049/**
Matt Spinlerd3335df2019-07-10 11:04:21 -050050 * @brief Tells the factory which PEL to create
51 */
52enum class TestPelType
53{
54 pelSimple,
Matt Spinler03c1d912019-07-10 14:12:15 -050055 privateHeaderSimple,
56 userHeaderSimple
Matt Spinlerd3335df2019-07-10 11:04:21 -050057};
58
59/**
60 * @brief PEL data factory, for testing
61 *
62 * @param[in] type - the type of data to create
63 *
64 * @return std::unique_ptr<std::vector<uint8_t>> - the PEL data
65 */
66std::unique_ptr<std::vector<uint8_t>> pelDataFactory(TestPelType type);
67
68/**
69 * @brief Helper function to read raw PEL data from a file
70 *
71 * @param[in] path - the path to read
72 *
73 * @return std::unique_ptr<std::vector<uint8_t>> - the data from the file
74 */
75std::unique_ptr<std::vector<uint8_t>>
76 readPELFile(const std::filesystem::path& path);