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