xref: /openbmc/openpower-occ-control/test/utest.cpp (revision d6ced7cba1e883131f2dd3fc73616930e1082639)
194df8c90SGunnar Mills #include "powercap.hpp"
213901597SGeorge Liu #include "utils.hpp"
394df8c90SGunnar Mills 
4ee4d83dfSVishwanatha Subbanna #include <occ_events.hpp>
5636577f4SEdward A. James #include <occ_manager.hpp>
694df8c90SGunnar Mills 
7bcef3b48SGeorge Liu #include <filesystem>
8b5ca1015SGeorge Liu 
994df8c90SGunnar Mills #include <gtest/gtest.h>
104cea4d2bSAndrew Geissler 
114cea4d2bSAndrew Geissler using namespace open_power::occ;
1213901597SGeorge Liu using namespace open_power::occ::utils;
134cea4d2bSAndrew Geissler 
144cea4d2bSAndrew Geissler class VerifyOccInput : public ::testing::Test
154cea4d2bSAndrew Geissler {
164cea4d2bSAndrew Geissler   public:
VerifyOccInput()174cea4d2bSAndrew Geissler     VerifyOccInput() :
18f3b7514eSGeorge Liu         rc(sd_event_default(&event)), eventP(event), manager(eventP),
19*89e54fabSPatrick Williams         occStatus(eventP, "/test/path/occ1", manager
20*89e54fabSPatrick Williams #ifdef POWER10
21*89e54fabSPatrick Williams                   ,
22*89e54fabSPatrick Williams                   powerMode
23*89e54fabSPatrick Williams #endif
24*89e54fabSPatrick Williams                   ),
25*89e54fabSPatrick Williams         pcap(occStatus)
26ee4d83dfSVishwanatha Subbanna     {
27ee4d83dfSVishwanatha Subbanna         EXPECT_GE(rc, 0);
28ee4d83dfSVishwanatha Subbanna         event = nullptr;
29ee4d83dfSVishwanatha Subbanna     }
~VerifyOccInput()30a49c987eSPatrick Williams     ~VerifyOccInput() {}
314cea4d2bSAndrew Geissler 
32ee4d83dfSVishwanatha Subbanna     sd_event* event;
33ee4d83dfSVishwanatha Subbanna     int rc;
34ee4d83dfSVishwanatha Subbanna     open_power::occ::EventPtr eventP;
35ee4d83dfSVishwanatha Subbanna 
36636577f4SEdward A. James     Manager manager;
374cea4d2bSAndrew Geissler     Status occStatus;
38*89e54fabSPatrick Williams #ifdef POWER10
39*89e54fabSPatrick Williams     std::unique_ptr<powermode::PowerMode> powerMode = nullptr;
40*89e54fabSPatrick Williams #endif
414cea4d2bSAndrew Geissler     powercap::PowerCap pcap;
424cea4d2bSAndrew Geissler };
434cea4d2bSAndrew Geissler 
TEST(VerifyPathParsing,EmptyPath)44774f9af9SEddie James TEST(VerifyPathParsing, EmptyPath)
45774f9af9SEddie James {
46bcef3b48SGeorge Liu     std::filesystem::path path = "";
47774f9af9SEddie James     std::string parsed = Device::getPathBack(path);
48774f9af9SEddie James 
49774f9af9SEddie James     EXPECT_STREQ(parsed.c_str(), "");
50774f9af9SEddie James }
51774f9af9SEddie James 
TEST(VerifyPathParsing,FilenamePath)52774f9af9SEddie James TEST(VerifyPathParsing, FilenamePath)
53774f9af9SEddie James {
54bcef3b48SGeorge Liu     std::filesystem::path path = "/test/foo.bar";
55774f9af9SEddie James     std::string parsed = Device::getPathBack(path);
56774f9af9SEddie James 
57774f9af9SEddie James     EXPECT_STREQ(parsed.c_str(), "foo.bar");
58774f9af9SEddie James }
59774f9af9SEddie James 
TEST(VerifyPathParsing,DirectoryPath)60774f9af9SEddie James TEST(VerifyPathParsing, DirectoryPath)
61774f9af9SEddie James {
62bcef3b48SGeorge Liu     std::filesystem::path path = "/test/bar/";
63774f9af9SEddie James     std::string parsed = Device::getPathBack(path);
64774f9af9SEddie James 
65774f9af9SEddie James     EXPECT_STREQ(parsed.c_str(), "bar");
66774f9af9SEddie James }
67