Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 1 | #include "elog_entry.hpp" |
| 2 | #include "extensions.hpp" |
| 3 | |
Matt Spinler | b181d9d | 2020-06-05 14:49:59 -0500 | [diff] [blame] | 4 | #include <sdbusplus/test/sdbus_mock.hpp> |
| 5 | |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 6 | #include <gtest/gtest.h> |
| 7 | |
| 8 | using namespace phosphor::logging; |
| 9 | |
| 10 | // gtest doesn't like this happening in another file, so do it here. |
| 11 | StartupFunctions Extensions::startupFunctions{}; |
| 12 | CreateFunctions Extensions::createFunctions{}; |
| 13 | DeleteFunctions Extensions::deleteFunctions{}; |
| 14 | DeleteProhibitedFunctions Extensions::deleteProhibitedFunctions{}; |
| 15 | Extensions::DefaultErrorCaps Extensions::defaultErrorCaps = |
| 16 | Extensions::DefaultErrorCaps::enable; |
| 17 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 18 | void startup1(internal::Manager& /*manager*/) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 19 | { |
| 20 | } |
| 21 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 22 | void startup2(internal::Manager& /*manager*/) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 23 | { |
| 24 | } |
| 25 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 26 | void create1(const std::string& /*message*/, uint32_t /*id*/, |
| 27 | uint64_t /*timestamp*/, Entry::Level /*severity*/, |
| 28 | const AdditionalDataArg& /*additionalData*/, |
| 29 | const AssociationEndpointsArg& /*assocs*/, const FFDCArg& /*ffdc*/) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 30 | { |
| 31 | } |
| 32 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 33 | void create2(const std::string& /*message*/, uint32_t /*id*/, |
| 34 | uint64_t /*timestamp*/, Entry::Level /*severity*/, |
| 35 | const AdditionalDataArg& /*additionalData*/, |
| 36 | const AssociationEndpointsArg& /*assocs*/, const FFDCArg& /*ffdc*/) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 37 | { |
| 38 | } |
| 39 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 40 | void deleteLog1(uint32_t /*id*/) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 41 | { |
| 42 | } |
| 43 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 44 | void deleteLog2(uint32_t /*id*/) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 48 | void deleteProhibited1(uint32_t /*id*/, bool& prohibited) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 49 | { |
| 50 | prohibited = true; |
| 51 | } |
| 52 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 53 | void deleteProhibited2(uint32_t /*id*/, bool& prohibited) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 54 | { |
| 55 | prohibited = true; |
| 56 | } |
| 57 | |
Patrick Williams | ce0bdf1 | 2021-04-16 20:09:22 -0500 | [diff] [blame] | 58 | DISABLE_LOG_ENTRY_CAPS() |
| 59 | REGISTER_EXTENSION_FUNCTION(startup1) |
| 60 | REGISTER_EXTENSION_FUNCTION(startup2) |
| 61 | REGISTER_EXTENSION_FUNCTION(create1) |
| 62 | REGISTER_EXTENSION_FUNCTION(create2) |
| 63 | REGISTER_EXTENSION_FUNCTION(deleteProhibited1) |
| 64 | REGISTER_EXTENSION_FUNCTION(deleteProhibited2) |
| 65 | REGISTER_EXTENSION_FUNCTION(deleteLog1) |
| 66 | REGISTER_EXTENSION_FUNCTION(deleteLog2) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 67 | |
| 68 | TEST(ExtensionsTest, FunctionCallTest) |
| 69 | { |
Matt Spinler | b181d9d | 2020-06-05 14:49:59 -0500 | [diff] [blame] | 70 | sdbusplus::SdBusMock sdbusMock; |
| 71 | sdbusplus::bus::bus bus = sdbusplus::get_mocked_new(&sdbusMock); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 72 | internal::Manager manager(bus, "testpath"); |
| 73 | |
| 74 | EXPECT_EQ(Extensions::getStartupFunctions().size(), 2); |
| 75 | for (auto& s : Extensions::getStartupFunctions()) |
| 76 | { |
| 77 | s(manager); |
| 78 | } |
| 79 | |
| 80 | AdditionalDataArg ad; |
| 81 | AssociationEndpointsArg assocs; |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 82 | FFDCArg ffdc; |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 83 | EXPECT_EQ(Extensions::getCreateFunctions().size(), 2); |
| 84 | for (auto& c : Extensions::getCreateFunctions()) |
| 85 | { |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 86 | c("test", 5, 6, Entry::Level::Informational, ad, assocs, ffdc); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2); |
| 90 | for (auto& d : Extensions::getDeleteFunctions()) |
| 91 | { |
| 92 | d(5); |
| 93 | } |
| 94 | |
| 95 | EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2); |
| 96 | for (auto& p : Extensions::getDeleteProhibitedFunctions()) |
| 97 | { |
| 98 | bool prohibited = false; |
| 99 | p(5, prohibited); |
| 100 | EXPECT_TRUE(prohibited); |
| 101 | } |
| 102 | |
| 103 | EXPECT_TRUE(Extensions::disableDefaultLogCaps()); |
| 104 | } |