blob: f06ad7be1290abe4a62bd83a34499a346eaf9b15 [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),
Patrick Williams89e54fa2024-02-28 11:32:51 -060019 occStatus(eventP, "/test/path/occ1", manager
20#ifdef POWER10
21 ,
22 powerMode
23#endif
24 ),
25 pcap(occStatus)
Gunnar Mills94df8c92018-09-14 14:50:03 -050026 {
27 EXPECT_GE(rc, 0);
28 event = nullptr;
29 }
Patrick Williamsa49c9872023-05-10 07:50:35 -050030 ~VerifyOccInput() {}
Andrew Geissler4cea4d22017-07-10 15:13:33 -050031
Gunnar Mills94df8c92018-09-14 14:50:03 -050032 sd_event* event;
33 int rc;
34 open_power::occ::EventPtr eventP;
Vishwanatha Subbannaee4d83d2017-06-29 18:35:00 +053035
Gunnar Mills94df8c92018-09-14 14:50:03 -050036 Manager manager;
37 Status occStatus;
Patrick Williams89e54fa2024-02-28 11:32:51 -060038#ifdef POWER10
39 std::unique_ptr<powermode::PowerMode> powerMode = nullptr;
40#endif
Gunnar Mills94df8c92018-09-14 14:50:03 -050041 powercap::PowerCap pcap;
Andrew Geissler4cea4d22017-07-10 15:13:33 -050042};
43
Eddie James774f9af2019-03-19 20:58:53 +000044TEST(VerifyPathParsing, EmptyPath)
45{
George Liubcef3b42021-09-10 12:39:02 +080046 std::filesystem::path path = "";
Eddie James774f9af2019-03-19 20:58:53 +000047 std::string parsed = Device::getPathBack(path);
48
49 EXPECT_STREQ(parsed.c_str(), "");
50}
51
52TEST(VerifyPathParsing, FilenamePath)
53{
George Liubcef3b42021-09-10 12:39:02 +080054 std::filesystem::path path = "/test/foo.bar";
Eddie James774f9af2019-03-19 20:58:53 +000055 std::string parsed = Device::getPathBack(path);
56
57 EXPECT_STREQ(parsed.c_str(), "foo.bar");
58}
59
60TEST(VerifyPathParsing, DirectoryPath)
61{
George Liubcef3b42021-09-10 12:39:02 +080062 std::filesystem::path path = "/test/bar/";
Eddie James774f9af2019-03-19 20:58:53 +000063 std::string parsed = Device::getPathBack(path);
64
65 EXPECT_STREQ(parsed.c_str(), "bar");
66}