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