blob: cf3401a44562ac4a3b61cf1e997a4bf0b7d7d61c [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
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
George Liubcef3b42021-09-10 12:39:02 +08007#include <filesystem>
George Liub5ca1012021-09-10 12:53:11 +08008
Gunnar Mills94df8c92018-09-14 14:50:03 -05009#include <gtest/gtest.h>
Andrew Geissler4cea4d22017-07-10 15:13:33 -050010
11using namespace open_power::occ;
George Liu13901592021-06-03 14:13:21 +080012using namespace open_power::occ::utils;
Andrew Geissler4cea4d22017-07-10 15:13:33 -050013
14class VerifyOccInput : public ::testing::Test
15{
Gunnar Mills94df8c92018-09-14 14:50:03 -050016 public:
17 VerifyOccInput() :
George Liuf3b75142021-06-10 11:22:50 +080018 rc(sd_event_default(&event)), eventP(event), manager(eventP),
19 occStatus(eventP, "/test/path/occ1", manager), pcap(occStatus)
Gunnar Mills94df8c92018-09-14 14:50:03 -050020 {
21 EXPECT_GE(rc, 0);
22 event = nullptr;
23 }
Patrick Williamsa49c9872023-05-10 07:50:35 -050024 ~VerifyOccInput() {}
Andrew Geissler4cea4d22017-07-10 15:13:33 -050025
Gunnar Mills94df8c92018-09-14 14:50:03 -050026 sd_event* event;
27 int rc;
28 open_power::occ::EventPtr eventP;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053029
Gunnar Mills94df8c92018-09-14 14:50:03 -050030 Manager manager;
31 Status occStatus;
32 powercap::PowerCap pcap;
Andrew Geissler4cea4d22017-07-10 15:13:33 -050033};
34
Gunnar Mills94df8c92018-09-14 14:50:03 -050035TEST_F(VerifyOccInput, PcapDisabled)
36{
37 uint32_t occInput = pcap.getOccInput(100, false);
Andrew Geissler4cea4d22017-07-10 15:13:33 -050038 EXPECT_EQ(occInput, 0);
39}
40
Gunnar Mills94df8c92018-09-14 14:50:03 -050041TEST_F(VerifyOccInput, PcapEnabled)
42{
43 uint32_t occInput = pcap.getOccInput(100, true);
Andrew Geissler4cea4d22017-07-10 15:13:33 -050044 EXPECT_EQ(occInput, 90);
45}
Eddie James774f9af2019-03-19 20:58:53 +000046
47TEST(VerifyPathParsing, EmptyPath)
48{
George Liubcef3b42021-09-10 12:39:02 +080049 std::filesystem::path path = "";
Eddie James774f9af2019-03-19 20:58:53 +000050 std::string parsed = Device::getPathBack(path);
51
52 EXPECT_STREQ(parsed.c_str(), "");
53}
54
55TEST(VerifyPathParsing, FilenamePath)
56{
George Liubcef3b42021-09-10 12:39:02 +080057 std::filesystem::path path = "/test/foo.bar";
Eddie James774f9af2019-03-19 20:58:53 +000058 std::string parsed = Device::getPathBack(path);
59
60 EXPECT_STREQ(parsed.c_str(), "foo.bar");
61}
62
63TEST(VerifyPathParsing, DirectoryPath)
64{
George Liubcef3b42021-09-10 12:39:02 +080065 std::filesystem::path path = "/test/bar/";
Eddie James774f9af2019-03-19 20:58:53 +000066 std::string parsed = Device::getPathBack(path);
67
68 EXPECT_STREQ(parsed.c_str(), "bar");
69}