diff --git a/plugins/apitracing/src/lib/ApiTracing.cpp b/plugins/apitracing/src/lib/ApiTracing.cpp index edb256a1..5cfa0dcb 100644 --- a/plugins/apitracing/src/lib/ApiTracing.cpp +++ b/plugins/apitracing/src/lib/ApiTracing.cpp @@ -46,12 +46,20 @@ namespace ApiTracing logger->debug("ApiTracing plugin version info", {{"Version", PLUGIN_VERSION}, {"BuildNumber", BUILD_VERSION}}); - auto apiTracingConfig = std::make_unique(config); + auto apiTracingConfig = std::make_unique(pluginInterface, config); + + std::string commandLine; + for (const auto& piece : args) + { + commandLine += " " + piece; + } + logger->info("ApiTracing command line", {{"commandLine:", commandLine}}); if (functionDefinitionsPath.isSet()) { apiTracingConfig->setFunctionDefinitionsPath(functionDefinitionsPath); } + if (traceProcessName.isSet()) { apiTracingConfig->addTracingTarget(traceProcessName); diff --git a/plugins/apitracing/src/lib/config/Config.cpp b/plugins/apitracing/src/lib/config/Config.cpp index 843bf839..6e4bfe29 100644 --- a/plugins/apitracing/src/lib/config/Config.cpp +++ b/plugins/apitracing/src/lib/config/Config.cpp @@ -1,10 +1,14 @@ #include "Config.h" +#include "../Filenames.h" #include "TracingDefinitions.h" #include +#include namespace ApiTracing { - Config::Config(const VmiCore::Plugin::IPluginConfig& pluginConfig) + Config::Config(VmiCore::Plugin::PluginInterface* pluginInterface, + const VmiCore::Plugin::IPluginConfig& pluginConfig) + : logger(pluginInterface->newNamedLogger(APITRACING_LOGGER_NAME)) { auto configRootNode = pluginConfig.rootNode(); if (auto configFilePath = pluginConfig.configFilePath()) @@ -96,7 +100,12 @@ namespace ApiTracing void Config::addTracingTarget(const std::string& name) { + logger->debug("addTracingTarget", {{"Name", name}}); processTracingProfiles.emplace(name, profiles["default"]); + for (auto profile : processTracingProfiles) + { + logger->debug("tracing profiles", {{"Name", profile.first}, {"Profile", profile.second.name}}); + } } void Config::setFunctionDefinitionsPath(const std::filesystem::path& path) diff --git a/plugins/apitracing/src/lib/config/Config.h b/plugins/apitracing/src/lib/config/Config.h index 06e7c2b1..819da270 100644 --- a/plugins/apitracing/src/lib/config/Config.h +++ b/plugins/apitracing/src/lib/config/Config.h @@ -6,7 +6,9 @@ #include #include #include +#include #include +#include #include namespace ApiTracing @@ -31,7 +33,8 @@ namespace ApiTracing class Config : public IConfig { public: - explicit Config(const VmiCore::Plugin::IPluginConfig& pluginConfig); + explicit Config(VmiCore::Plugin::PluginInterface* pluginInterface, + const VmiCore::Plugin::IPluginConfig& pluginConfig); ~Config() override = default; @@ -44,6 +47,7 @@ namespace ApiTracing void setFunctionDefinitionsPath(const std::filesystem::path& path) override; private: + std::unique_ptr logger; std::filesystem::path configFileDir; std::filesystem::path functionDefinitions; std::map> profiles; diff --git a/plugins/apitracing/test/Config_UnitTest.cpp b/plugins/apitracing/test/Config_UnitTest.cpp index c504cb21..272e3987 100644 --- a/plugins/apitracing/test/Config_UnitTest.cpp +++ b/plugins/apitracing/test/Config_UnitTest.cpp @@ -2,10 +2,15 @@ #include #include #include +#include #include +#include +using testing::_; // NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp) +using testing::NiceMock; using testing::Return; using VmiCore::Plugin::MockPluginConfig; +using VmiCore::Plugin::MockPluginInterface; namespace ApiTracing { @@ -35,14 +40,20 @@ namespace ApiTracing TEST(ConfigTests, constructor_functionDefinitionsKeyMissing_throws) { YAML::Node emptyConfigRootNode; + std::unique_ptr pluginInterface = std::make_unique>(); + ON_CALL(*pluginInterface, newNamedLogger(_)) + .WillByDefault([]() { return std::make_unique>(); }); - EXPECT_ANY_THROW(std::make_unique(*createMockPluginConfig(emptyConfigRootNode))); + EXPECT_ANY_THROW(std::make_unique(pluginInterface.get(), *createMockPluginConfig(emptyConfigRootNode))); } TEST(ConfigTests, getTracingProfile_calcProcess_correctProfile) { - - auto config = std::make_unique(*createMockPluginConfig("testConfiguration.yaml")); + std::unique_ptr pluginInterface = std::make_unique>(); + ON_CALL(*pluginInterface, newNamedLogger(_)) + .WillByDefault([]() { return std::make_unique>(); }); + auto config = + std::make_unique(pluginInterface.get(), *createMockPluginConfig("testConfiguration.yaml")); TracingProfile expectedTracingProfile{ .name = "calc", .traceChildren = true, @@ -56,7 +67,11 @@ namespace ApiTracing TEST(ConfigTests, getTracingProfile_processWithoutProfile_defaultProfile) { - auto config = std::make_unique(*createMockPluginConfig("testConfiguration.yaml")); + std::unique_ptr pluginInterface = std::make_unique>(); + ON_CALL(*pluginInterface, newNamedLogger(_)) + .WillByDefault([]() { return std::make_unique>(); }); + auto config = + std::make_unique(pluginInterface.get(), *createMockPluginConfig("testConfiguration.yaml")); TracingProfile expectedTracingProfile{ .name = "default", .traceChildren = true, .modules = {{.name = "ntdll.dll", .functions = {{"function1"}}}}}; @@ -67,7 +82,11 @@ namespace ApiTracing TEST(ConfigTests, getTracingProfile_unknownProcessName_nullopt) { - auto config = std::make_unique(*createMockPluginConfig("testConfiguration.yaml")); + std::unique_ptr pluginInterface = std::make_unique>(); + ON_CALL(*pluginInterface, newNamedLogger(_)) + .WillByDefault([]() { return std::make_unique>(); }); + auto config = + std::make_unique(pluginInterface.get(), *createMockPluginConfig("testConfiguration.yaml")); auto tracingProfile = config->getTracingProfile("unknown.exe"); @@ -76,17 +95,25 @@ namespace ApiTracing TEST(ConfigTests, getFunctionDefinitionsPath_configFromVmiCoreConfigFile_correctAbsolutePath) { + std::unique_ptr pluginInterface = std::make_unique>(); + ON_CALL(*pluginInterface, newNamedLogger(_)) + .WillByDefault([]() { return std::make_unique>(); }); YAML::Node configRootNode; configRootNode["function_definitions"] = "test.yaml"; - auto config = std::make_unique(*createMockPluginConfig(configRootNode)); + auto config = std::make_unique(pluginInterface.get(), *createMockPluginConfig(configRootNode)); EXPECT_EQ(config->getFunctionDefinitionsPath(), std::filesystem::path(defaultMainConfigFileDir) / "test.yaml"); } TEST(ConfigTests, getFunctionDefinitionsPath_configWithFunctionDefinitionsKey_correctFilePath) { - auto config = std::make_unique(*createMockPluginConfig("testConfiguration.yaml")); + std::unique_ptr pluginInterface = std::make_unique>(); + ON_CALL(*pluginInterface, newNamedLogger(_)) + .WillByDefault([]() { return std::make_unique>(); }); + + auto config = + std::make_unique(pluginInterface.get(), *createMockPluginConfig("testConfiguration.yaml")); EXPECT_NO_THROW(YAML::LoadFile(config->getFunctionDefinitionsPath())); }