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:
VerifyOccInput()17 VerifyOccInput() :
18 rc(sd_event_default(&event)), eventP(event), manager(eventP),
19 occStatus(eventP, "/test/path/occ1", manager
20 #ifdef POWER10
21 ,
22 powerMode
23 #endif
24 ),
25 pcap(occStatus)
26 {
27 EXPECT_GE(rc, 0);
28 event = nullptr;
29 }
~VerifyOccInput()30 ~VerifyOccInput() {}
31
32 sd_event* event;
33 int rc;
34 open_power::occ::EventPtr eventP;
35
36 Manager manager;
37 Status occStatus;
38 #ifdef POWER10
39 std::unique_ptr<powermode::PowerMode> powerMode = nullptr;
40 #endif
41 powercap::PowerCap pcap;
42 };
43
TEST_F(VerifyOccInput,PcapDisabled)44 TEST_F(VerifyOccInput, PcapDisabled)
45 {
46 uint32_t occInput = pcap.getOccInput(100, false);
47 EXPECT_EQ(occInput, 0);
48 }
49
TEST_F(VerifyOccInput,PcapEnabled)50 TEST_F(VerifyOccInput, PcapEnabled)
51 {
52 uint32_t occInput = pcap.getOccInput(100, true);
53 EXPECT_EQ(occInput, 90);
54 }
55
TEST(VerifyPathParsing,EmptyPath)56 TEST(VerifyPathParsing, EmptyPath)
57 {
58 std::filesystem::path path = "";
59 std::string parsed = Device::getPathBack(path);
60
61 EXPECT_STREQ(parsed.c_str(), "");
62 }
63
TEST(VerifyPathParsing,FilenamePath)64 TEST(VerifyPathParsing, FilenamePath)
65 {
66 std::filesystem::path path = "/test/foo.bar";
67 std::string parsed = Device::getPathBack(path);
68
69 EXPECT_STREQ(parsed.c_str(), "foo.bar");
70 }
71
TEST(VerifyPathParsing,DirectoryPath)72 TEST(VerifyPathParsing, DirectoryPath)
73 {
74 std::filesystem::path path = "/test/bar/";
75 std::string parsed = Device::getPathBack(path);
76
77 EXPECT_STREQ(parsed.c_str(), "bar");
78 }
79