blob: 04fa492c7a73ac37b09440c37df931468693b604 [file] [log] [blame]
Gunnar Mills94df8c92018-09-14 14:50:03 -05001#include "powercap.hpp"
2
Eddie James774f9af2019-03-19 20:58:53 +00003#include <experimental/filesystem>
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +05304#include <occ_events.hpp>
Edward A. James636577f2017-10-06 10:53:55 -05005#include <occ_manager.hpp>
Gunnar Mills94df8c92018-09-14 14:50:03 -05006
7#include <gtest/gtest.h>
Andrew Geissler4cea4d22017-07-10 15:13:33 -05008
9using namespace open_power::occ;
10
11class VerifyOccInput : public ::testing::Test
12{
Gunnar Mills94df8c92018-09-14 14:50:03 -050013 public:
14 VerifyOccInput() :
George Liuf3b75142021-06-10 11:22:50 +080015 rc(sd_event_default(&event)), eventP(event), manager(eventP),
16 occStatus(eventP, "/test/path/occ1", manager), pcap(occStatus)
Gunnar Mills94df8c92018-09-14 14:50:03 -050017 {
18 EXPECT_GE(rc, 0);
19 event = nullptr;
20 }
21 ~VerifyOccInput()
22 {
23 }
Andrew Geissler4cea4d22017-07-10 15:13:33 -050024
Gunnar Mills94df8c92018-09-14 14:50:03 -050025 sd_event* event;
26 int rc;
27 open_power::occ::EventPtr eventP;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053028
Gunnar Mills94df8c92018-09-14 14:50:03 -050029 Manager manager;
30 Status occStatus;
31 powercap::PowerCap pcap;
Andrew Geissler4cea4d22017-07-10 15:13:33 -050032};
33
Gunnar Mills94df8c92018-09-14 14:50:03 -050034TEST_F(VerifyOccInput, PcapDisabled)
35{
36 uint32_t occInput = pcap.getOccInput(100, false);
Andrew Geissler4cea4d22017-07-10 15:13:33 -050037 EXPECT_EQ(occInput, 0);
38}
39
Gunnar Mills94df8c92018-09-14 14:50:03 -050040TEST_F(VerifyOccInput, PcapEnabled)
41{
42 uint32_t occInput = pcap.getOccInput(100, true);
Andrew Geissler4cea4d22017-07-10 15:13:33 -050043 EXPECT_EQ(occInput, 90);
44}
Eddie James774f9af2019-03-19 20:58:53 +000045
46TEST(VerifyPathParsing, EmptyPath)
47{
48 std::experimental::filesystem::path path = "";
49 std::string parsed = Device::getPathBack(path);
50
51 EXPECT_STREQ(parsed.c_str(), "");
52}
53
54TEST(VerifyPathParsing, FilenamePath)
55{
56 std::experimental::filesystem::path path = "/test/foo.bar";
57 std::string parsed = Device::getPathBack(path);
58
59 EXPECT_STREQ(parsed.c_str(), "foo.bar");
60}
61
62TEST(VerifyPathParsing, DirectoryPath)
63{
64 std::experimental::filesystem::path path = "/test/bar/";
65 std::string parsed = Device::getPathBack(path);
66
67 EXPECT_STREQ(parsed.c_str(), "bar");
68}