xref: /openbmc/openpower-occ-control/test/utest.cpp (revision d6ced7cba1e883131f2dd3fc73616930e1082639)
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(VerifyPathParsing,EmptyPath)44 TEST(VerifyPathParsing, EmptyPath)
45 {
46     std::filesystem::path path = "";
47     std::string parsed = Device::getPathBack(path);
48 
49     EXPECT_STREQ(parsed.c_str(), "");
50 }
51 
TEST(VerifyPathParsing,FilenamePath)52 TEST(VerifyPathParsing, FilenamePath)
53 {
54     std::filesystem::path path = "/test/foo.bar";
55     std::string parsed = Device::getPathBack(path);
56 
57     EXPECT_STREQ(parsed.c_str(), "foo.bar");
58 }
59 
TEST(VerifyPathParsing,DirectoryPath)60 TEST(VerifyPathParsing, DirectoryPath)
61 {
62     std::filesystem::path path = "/test/bar/";
63     std::string parsed = Device::getPathBack(path);
64 
65     EXPECT_STREQ(parsed.c_str(), "bar");
66 }
67