blob: ff75a60595f7df5bd65637f39f936254c251b2de [file] [log] [blame]
Gunnar Mills94df8c92018-09-14 14:50:03 -05001#include "powercap.hpp"
George Liu13901592021-06-03 14:13:21 +08002#include "utils.hpp"
Gunnar Mills94df8c92018-09-14 14:50:03 -05003
Eddie James774f9af2019-03-19 20:58:53 +00004#include <experimental/filesystem>
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +05305#include <occ_events.hpp>
Edward A. James636577f2017-10-06 10:53:55 -05006#include <occ_manager.hpp>
Gunnar Mills94df8c92018-09-14 14:50:03 -05007
8#include <gtest/gtest.h>
Andrew Geissler4cea4d22017-07-10 15:13:33 -05009
10using namespace open_power::occ;
George Liu13901592021-06-03 14:13:21 +080011using namespace open_power::occ::utils;
Andrew Geissler4cea4d22017-07-10 15:13:33 -050012
13class VerifyOccInput : public ::testing::Test
14{
Gunnar Mills94df8c92018-09-14 14:50:03 -050015 public:
16 VerifyOccInput() :
George Liuf3b75142021-06-10 11:22:50 +080017 rc(sd_event_default(&event)), eventP(event), manager(eventP),
18 occStatus(eventP, "/test/path/occ1", manager), pcap(occStatus)
Gunnar Mills94df8c92018-09-14 14:50:03 -050019 {
20 EXPECT_GE(rc, 0);
21 event = nullptr;
22 }
23 ~VerifyOccInput()
24 {
25 }
Andrew Geissler4cea4d22017-07-10 15:13:33 -050026
Gunnar Mills94df8c92018-09-14 14:50:03 -050027 sd_event* event;
28 int rc;
29 open_power::occ::EventPtr eventP;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053030
Gunnar Mills94df8c92018-09-14 14:50:03 -050031 Manager manager;
32 Status occStatus;
33 powercap::PowerCap pcap;
Andrew Geissler4cea4d22017-07-10 15:13:33 -050034};
35
Gunnar Mills94df8c92018-09-14 14:50:03 -050036TEST_F(VerifyOccInput, PcapDisabled)
37{
38 uint32_t occInput = pcap.getOccInput(100, false);
Andrew Geissler4cea4d22017-07-10 15:13:33 -050039 EXPECT_EQ(occInput, 0);
40}
41
Gunnar Mills94df8c92018-09-14 14:50:03 -050042TEST_F(VerifyOccInput, PcapEnabled)
43{
44 uint32_t occInput = pcap.getOccInput(100, true);
Andrew Geissler4cea4d22017-07-10 15:13:33 -050045 EXPECT_EQ(occInput, 90);
46}
Eddie James774f9af2019-03-19 20:58:53 +000047
48TEST(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
56TEST(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
64TEST(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}
George Liu13901592021-06-03 14:13:21 +080071
72TEST(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}