summaryrefslogtreecommitdiffstats
path: root/test/error_files_tests.cpp
blob: 532818a03ee8bdf9bdffb07613fc2132a6510a1d (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
#include "occ_manager.hpp"

#include <stdlib.h>

#include <filesystem>
#include <fstream>

#include <gtest/gtest.h>

constexpr auto num_error_files = 8;
constexpr auto device = "occ-hwmon.1";
constexpr auto error = "occ_error";
constexpr auto errorMem = "occ_mem_throttle";
constexpr auto errorPower = "occ_dvfs_power";
constexpr auto errorTemp = "occ_dvfs_overtemp";
constexpr auto legacyDevice = "occ-hwmon.2";
constexpr auto legacyErrorTemp = "occ_dvfs_ot";
constexpr auto noError = "0";

namespace fs = std::experimental::filesystem;
using namespace open_power::occ;

class ErrorFiles : public ::testing::Test
{
  public:
    ErrorFiles() :
        bus(sdbusplus::bus::new_default()), rc(sd_event_default(&event)),
        pEvent(event), manager(bus, pEvent),
        status(bus, pEvent, "/dummy1", manager)
    {
        EXPECT_GE(rc, 0);
        event = nullptr;
    }

    virtual void SetUp()
    {
        fs::path files[num_error_files];
        char tmpDirTemplate[64];

        strcpy(tmpDirTemplate, "/tmp/occXXXXXX");
        auto path = mkdtemp(tmpDirTemplate);
        assert(path != nullptr);

        occPath = path;
        devicePath = occPath / device;
        legacyDevicePath = occPath / legacyDevice;

        fs::create_directory(devicePath);
        fs::create_directory(legacyDevicePath);

        files[0] = devicePath / error;
        files[1] = devicePath / errorMem;
        files[2] = devicePath / errorPower;
        files[3] = devicePath / errorTemp;
        files[4] = legacyDevicePath / error;
        files[5] = legacyDevicePath / errorMem;
        files[6] = legacyDevicePath / errorPower;
        files[7] = legacyDevicePath / legacyErrorTemp;

        for (const fs::path& f : files)
        {
            auto stream = std::ofstream(f.c_str());

            if (stream)
            {
                stream << noError;
            }
        }
    }

    virtual void TearDown()
    {
        fs::remove_all(occPath);
    }

    sdbusplus::bus::bus bus;
    sd_event* event;
    int rc;
    open_power::occ::EventPtr pEvent;

    Manager manager;
    Status status;

    fs::path devicePath;
    fs::path legacyDevicePath;
    fs::path occPath;
};

TEST_F(ErrorFiles, AddDeviceErrorWatch)
{
    Device occDevice(pEvent, devicePath, manager, status);

    occDevice.addErrorWatch(false);
    occDevice.removeErrorWatch();
}

TEST_F(ErrorFiles, AddLegacyDeviceErrorWatch)
{
    Device legacyOccDevice(pEvent, legacyDevicePath, manager, status);

    legacyOccDevice.addErrorWatch(false);
    legacyOccDevice.removeErrorWatch();
}
OpenPOWER on IntegriCloud