1 #include "powercap.hpp"
2 #include "utils.hpp"
3 
4 #include <occ_events.hpp>
5 #include <occ_manager.hpp>
6 
7 #include <filesystem>
8 
9 #include <gtest/gtest.h>
10 
11 using namespace open_power::occ;
12 using namespace open_power::occ::utils;
13 
14 class VerifyOccInput : public ::testing::Test
15 {
16   public:
17     VerifyOccInput() :
18         rc(sd_event_default(&event)), eventP(event), manager(eventP),
19         occStatus(eventP, "/test/path/occ1", manager), pcap(occStatus)
20     {
21         EXPECT_GE(rc, 0);
22         event = nullptr;
23     }
24     ~VerifyOccInput() {}
25 
26     sd_event* event;
27     int rc;
28     open_power::occ::EventPtr eventP;
29 
30     Manager manager;
31     Status occStatus;
32     powercap::PowerCap pcap;
33 };
34 
35 TEST_F(VerifyOccInput, PcapDisabled)
36 {
37     uint32_t occInput = pcap.getOccInput(100, false);
38     EXPECT_EQ(occInput, 0);
39 }
40 
41 TEST_F(VerifyOccInput, PcapEnabled)
42 {
43     uint32_t occInput = pcap.getOccInput(100, true);
44     EXPECT_EQ(occInput, 90);
45 }
46 
47 TEST(VerifyPathParsing, EmptyPath)
48 {
49     std::filesystem::path path = "";
50     std::string parsed = Device::getPathBack(path);
51 
52     EXPECT_STREQ(parsed.c_str(), "");
53 }
54 
55 TEST(VerifyPathParsing, FilenamePath)
56 {
57     std::filesystem::path path = "/test/foo.bar";
58     std::string parsed = Device::getPathBack(path);
59 
60     EXPECT_STREQ(parsed.c_str(), "foo.bar");
61 }
62 
63 TEST(VerifyPathParsing, DirectoryPath)
64 {
65     std::filesystem::path path = "/test/bar/";
66     std::string parsed = Device::getPathBack(path);
67 
68     EXPECT_STREQ(parsed.c_str(), "bar");
69 }
70