blob: fb608b82a538706acaf7ff7b0e9453c8da855b3d [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();
Matt Spinler367144c2019-09-19 15:33:52 -050036 registryPath = openpower::pels::getMessageRegistryPath();
Matt Spinler89fa0822019-07-17 13:54:30 -050037 }
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 Spinler367144c2019-09-19 15:33:52 -050044 std::filesystem::remove_all(registryPath);
Matt Spinler89fa0822019-07-17 13:54:30 -050045 }
46
47 static std::filesystem::path pelIDFile;
48 static std::filesystem::path repoPath;
Matt Spinler367144c2019-09-19 15:33:52 -050049 static std::filesystem::path registryPath;
Matt Spinler89fa0822019-07-17 13:54:30 -050050};
51
Matt Spinlercb6b0592019-07-16 15:58:51 -050052/**
Matt Spinlerd3335df2019-07-10 11:04:21 -050053 * @brief Tells the factory which PEL to create
54 */
Matt Spinler42828bd2019-10-11 10:39:30 -050055enum class TestPELType
Matt Spinlerd3335df2019-07-10 11:04:21 -050056{
57 pelSimple,
Matt Spinler42828bd2019-10-11 10:39:30 -050058 privateHeaderSection,
59 userHeaderSection,
60 primarySRCSection,
61 primarySRCSection2Callouts
Matt Spinlerd3335df2019-07-10 11:04:21 -050062};
63
64/**
Matt Spinler6c9662c2019-10-09 11:27:20 -050065 * @brief Tells the SRC factory which data to create
66 */
67enum class TestSRCType
68{
69 fruIdentityStructure,
70 pceIdentityStructure,
71 mruStructure,
Matt Spinler32f13c92019-10-09 12:48:25 -050072 calloutStructureA,
Matt Spinlerf9bae182019-10-09 13:37:38 -050073 calloutStructureB,
Matt Spinler42828bd2019-10-11 10:39:30 -050074 calloutSection2Callouts
Matt Spinler6c9662c2019-10-09 11:27:20 -050075};
76
77/**
Matt Spinlerd3335df2019-07-10 11:04:21 -050078 * @brief PEL data factory, for testing
79 *
80 * @param[in] type - the type of data to create
81 *
Matt Spinler42828bd2019-10-11 10:39:30 -050082 * @return std::vector<uint8_t> - the PEL data
Matt Spinlerd3335df2019-07-10 11:04:21 -050083 */
Matt Spinler42828bd2019-10-11 10:39:30 -050084std::vector<uint8_t> pelDataFactory(TestPELType type);
Matt Spinlerd3335df2019-07-10 11:04:21 -050085
86/**
Matt Spinler6c9662c2019-10-09 11:27:20 -050087 * @brief SRC data factory, for testing
88 *
89 * Provides pieces of the SRC PEL section, such as a callout.
90 *
91 * @param[in] type - the type of data to create
92 *
93 * @return std::vector<uint8_t> - The SRC data
94 */
95std::vector<uint8_t> srcDataFactory(TestSRCType type);
96
97/**
Matt Spinlerd3335df2019-07-10 11:04:21 -050098 * @brief Helper function to read raw PEL data from a file
99 *
100 * @param[in] path - the path to read
101 *
102 * @return std::unique_ptr<std::vector<uint8_t>> - the data from the file
103 */
104std::unique_ptr<std::vector<uint8_t>>
105 readPELFile(const std::filesystem::path& path);