summaryrefslogtreecommitdiffstats
path: root/test/openpower-pels/pel_utils.hpp
blob: 78c6401b6489c169929b71dd38a6325d4ac14e1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "extensions/openpower-pels/paths.hpp"

#include <filesystem>
#include <memory>
#include <vector>

#include <gtest/gtest.h>

/**
 * @brief Test fixture to remove the pelID file that PELs use.
 */
class CleanLogID : public ::testing::Test
{
  protected:
    static void SetUpTestCase()
    {
        pelIDFile = openpower::pels::getPELIDFile();
    }

    static void TearDownTestCase()
    {
        std::filesystem::remove_all(
            std::filesystem::path{pelIDFile}.parent_path());
    }

    static std::filesystem::path pelIDFile;
};

class CleanPELFiles : public ::testing::Test
{
  protected:
    static void SetUpTestCase()
    {
        pelIDFile = openpower::pels::getPELIDFile();
        repoPath = openpower::pels::getPELRepoPath();
        registryPath = openpower::pels::getMessageRegistryPath();
    }

    static void TearDownTestCase()
    {
        std::filesystem::remove_all(
            std::filesystem::path{pelIDFile}.parent_path());
        std::filesystem::remove_all(repoPath);
        std::filesystem::remove_all(registryPath);
    }

    static std::filesystem::path pelIDFile;
    static std::filesystem::path repoPath;
    static std::filesystem::path registryPath;
};

/**
 * @brief Tells the factory which PEL to create
 */
enum class TestPELType
{
    pelSimple,
    privateHeaderSection,
    userHeaderSection,
    primarySRCSection,
    primarySRCSection2Callouts,
    failingMTMSSection
};

/**
 * @brief Tells the SRC factory which data to create
 */
enum class TestSRCType
{
    fruIdentityStructure,
    pceIdentityStructure,
    mruStructure,
    calloutStructureA,
    calloutStructureB,
    calloutSection2Callouts
};

/**
 * @brief PEL data factory, for testing
 *
 * @param[in] type - the type of data to create
 *
 * @return std::vector<uint8_t> - the PEL data
 */
std::vector<uint8_t> pelDataFactory(TestPELType type);

/**
 * @brief SRC data factory, for testing
 *
 * Provides pieces of the SRC PEL section, such as a callout.
 *
 * @param[in] type - the type of data to create
 *
 * @return std::vector<uint8_t> - The SRC data
 */
std::vector<uint8_t> srcDataFactory(TestSRCType type);

/**
 * @brief Helper function to read raw PEL data from a file
 *
 * @param[in] path - the path to read
 *
 * @return std::unique_ptr<std::vector<uint8_t>> - the data from the file
 */
std::unique_ptr<std::vector<uint8_t>>
    readPELFile(const std::filesystem::path& path);
OpenPOWER on IntegriCloud