Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 1 | #include "powercap.hpp" |
| 2 | |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 3 | #include <experimental/filesystem> |
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 | |
| 7 | #include <gtest/gtest.h> |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 8 | |
| 9 | using namespace open_power::occ; |
| 10 | |
| 11 | class VerifyOccInput : public ::testing::Test |
| 12 | { |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 13 | public: |
| 14 | VerifyOccInput() : |
George Liu | f3b7514 | 2021-06-10 11:22:50 +0800 | [diff] [blame^] | 15 | rc(sd_event_default(&event)), eventP(event), manager(eventP), |
| 16 | occStatus(eventP, "/test/path/occ1", manager), pcap(occStatus) |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 17 | { |
| 18 | EXPECT_GE(rc, 0); |
| 19 | event = nullptr; |
| 20 | } |
| 21 | ~VerifyOccInput() |
| 22 | { |
| 23 | } |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 24 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 25 | sd_event* event; |
| 26 | int rc; |
| 27 | open_power::occ::EventPtr eventP; |
Vishwanatha Subbanna | ee4d83d | 2017-06-29 18:35:00 +0530 | [diff] [blame] | 28 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 29 | Manager manager; |
| 30 | Status occStatus; |
| 31 | powercap::PowerCap pcap; |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 32 | }; |
| 33 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 34 | TEST_F(VerifyOccInput, PcapDisabled) |
| 35 | { |
| 36 | uint32_t occInput = pcap.getOccInput(100, false); |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 37 | EXPECT_EQ(occInput, 0); |
| 38 | } |
| 39 | |
Gunnar Mills | 94df8c9 | 2018-09-14 14:50:03 -0500 | [diff] [blame] | 40 | TEST_F(VerifyOccInput, PcapEnabled) |
| 41 | { |
| 42 | uint32_t occInput = pcap.getOccInput(100, true); |
Andrew Geissler | 4cea4d2 | 2017-07-10 15:13:33 -0500 | [diff] [blame] | 43 | EXPECT_EQ(occInput, 90); |
| 44 | } |
Eddie James | 774f9af | 2019-03-19 20:58:53 +0000 | [diff] [blame] | 45 | |
| 46 | TEST(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 | |
| 54 | TEST(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 | |
| 62 | TEST(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 | } |