Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 1 | #include "powercap.hpp" |
George Liu | 1390159 | 2021-06-03 14:13:21 +0800 | [diff] [blame] | 2 | #include "utils.hpp" |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 3 | |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 4 | #include <occ_events.hpp> |
Edward A. James | 636577f | 2017-10-06 10:53:55 -0500 | [diff] [blame] | 5 | #include <occ_manager.hpp> |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 6 | |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 7 | #include <filesystem> |
George Liu | b5ca101 | 2021-09-10 12:53:11 +0800 | [diff] [blame] | 8 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 9 | #include <gtest/gtest.h> |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 10 | |
| 11 | using namespace open_power::occ; |
George Liu | 1390159 | 2021-06-03 14:13:21 +0800 | [diff] [blame] | 12 | using namespace open_power::occ::utils; |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 13 | |
| 14 | class VerifyOccInput : public ::testing::Test |
| 15 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 16 | public: |
| 17 | VerifyOccInput() : |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame] | 18 | rc(sd_event_default(&event)), eventP(event), manager(eventP), |
Patrick Williams | 89e54fa | 2024-02-28 11:32:51 -0600 | [diff] [blame^] | 19 | occStatus(eventP, "/test/path/occ1", manager |
| 20 | #ifdef POWER10 |
| 21 | , |
| 22 | powerMode |
| 23 | #endif |
| 24 | ), |
| 25 | pcap(occStatus) |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 26 | { |
| 27 | EXPECT_GE(rc, 0); |
| 28 | event = nullptr; |
| 29 | } |
Patrick Williams | a49c987 | 2023-05-10 07:50:35 -0500 | [diff] [blame] | 30 | ~VerifyOccInput() {} |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 31 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 32 | sd_event* event; |
| 33 | int rc; |
| 34 | open_power::occ::EventPtr eventP; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 35 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 36 | Manager manager; |
| 37 | Status occStatus; |
Patrick Williams | 89e54fa | 2024-02-28 11:32:51 -0600 | [diff] [blame^] | 38 | #ifdef POWER10 |
| 39 | std::unique_ptr<powermode::PowerMode> powerMode = nullptr; |
| 40 | #endif |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 41 | powercap::PowerCap pcap; |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 42 | }; |
| 43 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 44 | TEST_F(VerifyOccInput, PcapDisabled) |
| 45 | { |
| 46 | uint32_t occInput = pcap.getOccInput(100, false); |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 47 | EXPECT_EQ(occInput, 0); |
| 48 | } |
| 49 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 50 | TEST_F(VerifyOccInput, PcapEnabled) |
| 51 | { |
| 52 | uint32_t occInput = pcap.getOccInput(100, true); |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 53 | EXPECT_EQ(occInput, 90); |
| 54 | } |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 55 | |
| 56 | TEST(VerifyPathParsing, EmptyPath) |
| 57 | { |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 58 | std::filesystem::path path = ""; |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 59 | std::string parsed = Device::getPathBack(path); |
| 60 | |
| 61 | EXPECT_STREQ(parsed.c_str(), ""); |
| 62 | } |
| 63 | |
| 64 | TEST(VerifyPathParsing, FilenamePath) |
| 65 | { |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 66 | std::filesystem::path path = "/test/foo.bar"; |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 67 | std::string parsed = Device::getPathBack(path); |
| 68 | |
| 69 | EXPECT_STREQ(parsed.c_str(), "foo.bar"); |
| 70 | } |
| 71 | |
| 72 | TEST(VerifyPathParsing, DirectoryPath) |
| 73 | { |
George Liu | bcef3b4 | 2021-09-10 12:39:02 +0800 | [diff] [blame] | 74 | std::filesystem::path path = "/test/bar/"; |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 75 | std::string parsed = Device::getPathBack(path); |
| 76 | |
| 77 | EXPECT_STREQ(parsed.c_str(), "bar"); |
| 78 | } |