summaryrefslogtreecommitdiffstats
path: root/test/utest.cpp
blob: 39e525085c6baaa929cbee8f59324fbf6ba28e08 (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
#include "powercap.hpp"

#include <experimental/filesystem>
#include <occ_events.hpp>
#include <occ_manager.hpp>

#include <gtest/gtest.h>

using namespace open_power::occ;

class VerifyOccInput : public ::testing::Test
{
  public:
    VerifyOccInput() :
        bus(sdbusplus::bus::new_default()), rc(sd_event_default(&event)),
        eventP(event), manager(bus, eventP),
        occStatus(bus, eventP, "/test/path/occ1", manager), pcap(bus, occStatus)
    {
        EXPECT_GE(rc, 0);
        event = nullptr;
    }
    ~VerifyOccInput()
    {
    }

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

    Manager manager;
    Status occStatus;
    powercap::PowerCap pcap;
};

TEST_F(VerifyOccInput, PcapDisabled)
{
    uint32_t occInput = pcap.getOccInput(100, false);
    EXPECT_EQ(occInput, 0);
}

TEST_F(VerifyOccInput, PcapEnabled)
{
    uint32_t occInput = pcap.getOccInput(100, true);
    EXPECT_EQ(occInput, 90);
}

TEST(VerifyPathParsing, EmptyPath)
{
    std::experimental::filesystem::path path = "";
    std::string parsed = Device::getPathBack(path);

    EXPECT_STREQ(parsed.c_str(), "");
}

TEST(VerifyPathParsing, FilenamePath)
{
    std::experimental::filesystem::path path = "/test/foo.bar";
    std::string parsed = Device::getPathBack(path);

    EXPECT_STREQ(parsed.c_str(), "foo.bar");
}

TEST(VerifyPathParsing, DirectoryPath)
{
    std::experimental::filesystem::path path = "/test/bar/";
    std::string parsed = Device::getPathBack(path);

    EXPECT_STREQ(parsed.c_str(), "bar");
}
OpenPOWER on IntegriCloud