diff --git a/conanfile.txt b/conanfile.txt index c290e3e8e..ea7f4413a 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,5 +1,6 @@ [requires] -catch2/3.4.0 +benchmark/1.8.3 +catch2/2.13.10 corrade/2020.06 cpp-httplib/0.14.0 docopt.cpp/0.6.3 diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index e6480f56e..046236340 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -1,6 +1,5 @@ message(STATUS "Custom Libraries") -add_subdirectory(visor_test) add_subdirectory(visor_transaction) add_subdirectory(visor_tcp) add_subdirectory(visor_dns) diff --git a/libs/visor_dns/CMakeLists.txt b/libs/visor_dns/CMakeLists.txt index 376cf9828..06191035e 100644 --- a/libs/visor_dns/CMakeLists.txt +++ b/libs/visor_dns/CMakeLists.txt @@ -24,16 +24,4 @@ target_link_libraries(VisorLibDns ${CONAN_LIBS_FMT} ) -## TEST SUITE -add_executable(unit-tests-visor-dns - tests/test_dns.cpp - tests/benchmark_dns.cpp) - -target_link_libraries(unit-tests-visor-dns - PRIVATE - Visor::Lib::Dns - ${CONAN_LIBS_CATCH2}) - -add_test(NAME unit-tests-visor-dns - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/libs/visor_dns - COMMAND unit-tests-visor-dns) \ No newline at end of file +add_subdirectory(tests) \ No newline at end of file diff --git a/libs/visor_dns/tests/CMakeLists.txt b/libs/visor_dns/tests/CMakeLists.txt new file mode 100644 index 000000000..396462e66 --- /dev/null +++ b/libs/visor_dns/tests/CMakeLists.txt @@ -0,0 +1,24 @@ +# Unit +add_executable(unit-tests-visor-dns + main.cpp + test_dns.cpp + ) + +target_link_libraries(unit-tests-visor-dns + PRIVATE + ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} + Visor::Lib::Dns) + +add_test(NAME unit-tests-visor-dns + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND unit-tests-visor-dns + ) + +# Benchmark +add_executable(benchmark-visor-dns + benchmark_dns.cpp + ) + +target_link_libraries(benchmark-visor-dns PRIVATE + Visor::Lib::Dns + ${CONAN_LIBS_BENCHMARK}) \ No newline at end of file diff --git a/libs/visor_dns/tests/benchmark_dns.cpp b/libs/visor_dns/tests/benchmark_dns.cpp index 4144dd372..46d604342 100644 --- a/libs/visor_dns/tests/benchmark_dns.cpp +++ b/libs/visor_dns/tests/benchmark_dns.cpp @@ -1,9 +1,8 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include -#include +#include "benchmark/benchmark.h" #include "dns.h" #ifdef __GNUC__ #pragma GCC diagnostic push @@ -22,65 +21,66 @@ using namespace visor::lib::dns; -void BM_aggregateDomain(const std::string &domain) +static void BM_aggregateDomain(benchmark::State &state) { AggDomainResult result; - result = aggregateDomain(domain); + std::string domain{"biz.foo.bar.com"}; + for (auto _ : state) { + result = aggregateDomain(domain); + } } +BENCHMARK(BM_aggregateDomain); -void BM_pcapReadNoParse() +static void BM_aggregateDomainLong(benchmark::State &state) { - auto reader = pcpp::IFileReaderDevice::getReader("tests/dns_udp_tcp_random.pcap"); - - if (!reader->open()) { - throw std::runtime_error("Cannot open pcap/pcapng file"); - } - - pcpp::RawPacket rawPacket; - while (reader->getNextPacket(rawPacket)) { + AggDomainResult result; + std::string domain{"long1.long2.long3.long4.long5.long6.long7.long8.biz.foo.bar.com"}; + for (auto _ : state) { + result = aggregateDomain(domain); } - - reader->close(); - delete reader; } -void BM_pcapReadParse() +BENCHMARK(BM_aggregateDomainLong); + +static void BM_pcapReadNoParse(benchmark::State &state) { - auto reader = pcpp::IFileReaderDevice::getReader("tests/dns_udp_tcp_random.pcap"); + for (auto _ : state) { + auto reader = pcpp::IFileReaderDevice::getReader("fixtures/dns_udp_tcp_random.pcap"); - if (!reader->open()) { - throw std::runtime_error("Cannot open pcap/pcapng file"); - } + if (!reader->open()) { + throw std::runtime_error("Cannot open pcap/pcapng file"); + } - pcpp::RawPacket rawPacket; - while (reader->getNextPacket(rawPacket)) { - pcpp::Packet packet(&rawPacket, pcpp::OsiModelTransportLayer); - } + pcpp::RawPacket rawPacket; + while (reader->getNextPacket(rawPacket)) { + } - reader->close(); - delete reader; + reader->close(); + delete reader; + } } +BENCHMARK(BM_pcapReadNoParse); -TEST_CASE("DNS benchmark") +static void BM_pcapReadParse1(benchmark::State &state) { - BENCHMARK("Aggregate Domain") - { - return BM_aggregateDomain("biz.foo.bar.com"); - }; - - BENCHMARK("Aggregate Domain Long") - { - return BM_aggregateDomain("long1.long2.long3.long4.long5.long6.long7.long8.biz.foo.bar.com"); - }; - - BENCHMARK("Pcap Read No Parse") - { - return BM_pcapReadNoParse(); - }; - - BENCHMARK("Pcap Read No Parse") - { - return BM_pcapReadParse(); - }; + + for (auto _ : state) { + auto reader = pcpp::IFileReaderDevice::getReader("fixtures/dns_udp_tcp_random.pcap"); + + if (!reader->open()) { + throw std::runtime_error("Cannot open pcap/pcapng file"); + } + + pcpp::RawPacket rawPacket; + while (reader->getNextPacket(rawPacket)) { + pcpp::Packet packet(&rawPacket, pcpp::OsiModelTransportLayer); + } + + reader->close(); + delete reader; + } } +BENCHMARK(BM_pcapReadParse1); + +BENCHMARK_MAIN(); \ No newline at end of file diff --git a/libs/visor_dns/tests/dns_udp_tcp_random.pcap b/libs/visor_dns/tests/dns_udp_tcp_random.pcap deleted file mode 100644 index c831d0546..000000000 Binary files a/libs/visor_dns/tests/dns_udp_tcp_random.pcap and /dev/null differ diff --git a/libs/visor_dns/tests/main.cpp b/libs/visor_dns/tests/main.cpp new file mode 100644 index 000000000..3ab9e7842 --- /dev/null +++ b/libs/visor_dns/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/libs/visor_dns/tests/test_dns.cpp b/libs/visor_dns/tests/test_dns.cpp index b85b0e61e..4234e1bef 100644 --- a/libs/visor_dns/tests/test_dns.cpp +++ b/libs/visor_dns/tests/test_dns.cpp @@ -1,4 +1,4 @@ -#include +#include "catch2/catch.hpp" #include "dns.h" diff --git a/libs/visor_test/CMakeLists.txt b/libs/visor_test/CMakeLists.txt deleted file mode 100644 index d664f26ce..000000000 --- a/libs/visor_test/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -message(STATUS "Visor Lib Test Helper") - -add_library(VisorLibTest INTERFACE) -add_library(Visor::Lib::Test ALIAS VisorLibTest) - -target_include_directories(VisorLibTest - INTERFACE - $) - -target_link_libraries(VisorLibTest - INTERFACE - ${CONAN_LIBS_SPDLOG} - ${CONAN_LIBS_CATCH2}) - -target_compile_features(VisorLibTest INTERFACE cxx_std_17) - -target_sources(VisorLibTest INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/catch2/catch_test_visor.hpp) \ No newline at end of file diff --git a/libs/visor_test/catch2/catch_test_visor.hpp b/libs/visor_test/catch2/catch_test_visor.hpp deleted file mode 100644 index 99a40d5ab..000000000 --- a/libs/visor_test/catch2/catch_test_visor.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include - -class SpdlogInitializer : public Catch::EventListenerBase -{ -public: - using Catch::EventListenerBase::EventListenerBase; - - void testCaseStarting([[maybe_unused]] Catch::TestCaseInfo const &testInfo) override - { - static bool initialized = false; - if (!initialized) { - auto logger = spdlog::get("visor"); - if (!logger) { - spdlog::stderr_color_mt("visor"); - } - initialized = true; - } - } -}; - -CATCH_REGISTER_LISTENER(SpdlogInitializer) \ No newline at end of file diff --git a/libs/visor_utils/CMakeLists.txt b/libs/visor_utils/CMakeLists.txt index 4e2af3d4e..9eb2b25a0 100644 --- a/libs/visor_utils/CMakeLists.txt +++ b/libs/visor_utils/CMakeLists.txt @@ -20,14 +20,4 @@ target_link_libraries(VisorLibUtils ${CONAN_LIBS_FMT} ) -## TEST SUITE -add_executable(unit-tests-visor-utils test_utils.cpp) - -target_link_libraries(unit-tests-visor-utils - PRIVATE - Visor::Lib::Utils - ${CONAN_LIBS_CATCH2}) - -add_test(NAME unit-tests-visor-utils - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/libs - COMMAND unit-tests-visor-utils) \ No newline at end of file +add_subdirectory(tests) \ No newline at end of file diff --git a/libs/visor_utils/tests/CMakeLists.txt b/libs/visor_utils/tests/CMakeLists.txt new file mode 100644 index 000000000..f4e4e65d7 --- /dev/null +++ b/libs/visor_utils/tests/CMakeLists.txt @@ -0,0 +1,15 @@ +# Unit +add_executable(unit-tests-visor-utils + main.cpp + test_utils.cpp + ) + +target_link_libraries(unit-tests-visor-utils + PRIVATE + ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} + Visor::Lib::Utils) + +add_test(NAME unit-tests-visor-utils + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND unit-tests-visor-utils + ) \ No newline at end of file diff --git a/libs/visor_utils/tests/main.cpp b/libs/visor_utils/tests/main.cpp new file mode 100644 index 000000000..3ab9e7842 --- /dev/null +++ b/libs/visor_utils/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/libs/visor_utils/test_utils.cpp b/libs/visor_utils/tests/test_utils.cpp similarity index 98% rename from libs/visor_utils/test_utils.cpp rename to libs/visor_utils/tests/test_utils.cpp index 7b5dce792..8440994ed 100644 --- a/libs/visor_utils/test_utils.cpp +++ b/libs/visor_utils/tests/test_utils.cpp @@ -1,4 +1,4 @@ -#include +#include "catch2/catch.hpp" #include "utils.h" #ifdef _WIN32 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1d3d8de5e..ee1c8fc54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,6 +58,7 @@ set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} PARENT_SCOPE) ## TEST SUITE add_executable(unit-tests-visor-core + tests/main.cpp tests/test_sketches.cpp tests/test_metrics.cpp tests/test_geoip.cpp @@ -67,14 +68,13 @@ add_executable(unit-tests-visor-core tests/test_handlers.cpp ) -target_include_directories(unit-tests-visor-core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(unit-tests-visor-core + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + ) -target_link_libraries(unit-tests-visor-core - PRIVATE - Visor::Core - ${VISOR_STATIC_PLUGINS} - ${CONAN_LIBS_CATCH2}) +target_link_libraries(unit-tests-visor-core PRIVATE Visor::Core ${VISOR_STATIC_PLUGINS}) add_test(NAME unit-tests-visor-core WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-visor-core) \ No newline at end of file + COMMAND unit-tests-visor-core + ) \ No newline at end of file diff --git a/src/handlers/bgp/CMakeLists.txt b/src/handlers/bgp/CMakeLists.txt index 4ed0e0d65..6794a2bbd 100644 --- a/src/handlers/bgp/CMakeLists.txt +++ b/src/handlers/bgp/CMakeLists.txt @@ -11,25 +11,14 @@ add_library(Visor::Handler::Bgp ALIAS VisorHandlerBgp) target_include_directories(VisorHandlerBgp INTERFACE - $) + $ + ) target_link_libraries(VisorHandlerBgp PUBLIC - Visor::Input::Pcap) + Visor::Input::Pcap + ) set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Handler::Bgp PARENT_SCOPE) -## TEST SUITE -add_executable(unit-tests-handler-bgp - tests/test_bgp_layer.cpp - tests/test_json_schema.cpp) - -target_link_libraries(unit-tests-handler-bgp - PRIVATE - ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} - Visor::Handler::Bgp - Visor::Lib::Test) - -add_test(NAME unit-tests-handler-bgp - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-handler-bgp) \ No newline at end of file +add_subdirectory(tests) \ No newline at end of file diff --git a/src/handlers/bgp/tests/CMakeLists.txt b/src/handlers/bgp/tests/CMakeLists.txt new file mode 100644 index 000000000..ab824f241 --- /dev/null +++ b/src/handlers/bgp/tests/CMakeLists.txt @@ -0,0 +1,17 @@ + +## TEST SUITE +add_executable(unit-tests-handler-bgp + main.cpp + test_bgp_layer.cpp + test_json_schema.cpp + ) + +target_link_libraries(unit-tests-handler-bgp + PRIVATE + ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} + Visor::Handler::Bgp) + +add_test(NAME unit-tests-handler-bgp + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src + COMMAND unit-tests-handler-bgp + ) diff --git a/src/handlers/bgp/tests/main.cpp b/src/handlers/bgp/tests/main.cpp new file mode 100644 index 000000000..3ab9e7842 --- /dev/null +++ b/src/handlers/bgp/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/handlers/bgp/tests/test_bgp_layer.cpp b/src/handlers/bgp/tests/test_bgp_layer.cpp index cebba7668..1893040c7 100644 --- a/src/handlers/bgp/tests/test_bgp_layer.cpp +++ b/src/handlers/bgp/tests/test_bgp_layer.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include "PcapInputStream.h" #include "BgpStreamHandler.h" diff --git a/src/handlers/bgp/tests/test_json_schema.cpp b/src/handlers/bgp/tests/test_json_schema.cpp index d591ae128..c242f9a72 100644 --- a/src/handlers/bgp/tests/test_json_schema.cpp +++ b/src/handlers/bgp/tests/test_json_schema.cpp @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include +#include #include #include #include diff --git a/src/handlers/dhcp/CMakeLists.txt b/src/handlers/dhcp/CMakeLists.txt index 1fb89114b..208b41c8c 100644 --- a/src/handlers/dhcp/CMakeLists.txt +++ b/src/handlers/dhcp/CMakeLists.txt @@ -6,32 +6,21 @@ corrade_add_static_plugin(VisorHandlerDhcp ${CMAKE_CURRENT_BINARY_DIR} DhcpHandler.conf DhcpHandlerModulePlugin.cpp - DhcpStreamHandler.cpp) + DhcpStreamHandler.cpp + ) add_library(Visor::Handler::Dhcp ALIAS VisorHandlerDhcp) target_include_directories(VisorHandlerDhcp INTERFACE - $) + $ + ) target_link_libraries(VisorHandlerDhcp PUBLIC Visor::Lib::Transaction - Visor::Input::Pcap) + Visor::Input::Pcap + ) set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Handler::Dhcp PARENT_SCOPE) - -## TEST SUITE -add_executable(unit-tests-handler-dhcp - tests/test_dhcp_layer.cpp - tests/test_json_schema.cpp) - -target_link_libraries(unit-tests-handler-dhcp - PRIVATE - ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} - Visor::Handler::Dhcp - Visor::Lib::Test) - -add_test(NAME unit-tests-handler-dhcp - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-handler-dhcp) +add_subdirectory(tests) \ No newline at end of file diff --git a/src/handlers/dhcp/tests/CMakeLists.txt b/src/handlers/dhcp/tests/CMakeLists.txt new file mode 100644 index 000000000..5e5890380 --- /dev/null +++ b/src/handlers/dhcp/tests/CMakeLists.txt @@ -0,0 +1,17 @@ + +## TEST SUITE +add_executable(unit-tests-handler-dhcp + main.cpp + test_dhcp_layer.cpp + test_json_schema.cpp + ) + +target_link_libraries(unit-tests-handler-dhcp + PRIVATE + ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} + Visor::Handler::Dhcp) + +add_test(NAME unit-tests-handler-dhcp + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src + COMMAND unit-tests-handler-dhcp + ) diff --git a/src/handlers/dhcp/tests/main.cpp b/src/handlers/dhcp/tests/main.cpp new file mode 100644 index 000000000..3ab9e7842 --- /dev/null +++ b/src/handlers/dhcp/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/handlers/dhcp/tests/test_dhcp_layer.cpp b/src/handlers/dhcp/tests/test_dhcp_layer.cpp index d99888b56..ef86494a1 100644 --- a/src/handlers/dhcp/tests/test_dhcp_layer.cpp +++ b/src/handlers/dhcp/tests/test_dhcp_layer.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include "DhcpStreamHandler.h" #include "PcapInputStream.h" diff --git a/src/handlers/dhcp/tests/test_json_schema.cpp b/src/handlers/dhcp/tests/test_json_schema.cpp index 2d90de62f..655998dee 100644 --- a/src/handlers/dhcp/tests/test_json_schema.cpp +++ b/src/handlers/dhcp/tests/test_json_schema.cpp @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include +#include #include #include #include diff --git a/src/handlers/dns/v1/CMakeLists.txt b/src/handlers/dns/v1/CMakeLists.txt index 669eebe2c..bee5d1049 100644 --- a/src/handlers/dns/v1/CMakeLists.txt +++ b/src/handlers/dns/v1/CMakeLists.txt @@ -26,18 +26,4 @@ target_link_libraries(VisorHandlerDns set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Handler::Dns PARENT_SCOPE) -## TEST SUITE -add_executable(unit-tests-handler-dns - tests/test_dns_layer.cpp - tests/test_dnstap.cpp - tests/test_json_schema.cpp) - -target_link_libraries(unit-tests-handler-dns - PRIVATE - ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} - Visor::Handler::Dns - Visor::Lib::Test) - -add_test(NAME unit-tests-handler-dns - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-handler-dns) \ No newline at end of file +add_subdirectory(tests) \ No newline at end of file diff --git a/src/handlers/dns/v1/tests/CMakeLists.txt b/src/handlers/dns/v1/tests/CMakeLists.txt new file mode 100644 index 000000000..151ce1886 --- /dev/null +++ b/src/handlers/dns/v1/tests/CMakeLists.txt @@ -0,0 +1,18 @@ + +# Unit +add_executable(unit-tests-handler-dns + main.cpp + test_dns_layer.cpp + test_dnstap.cpp + test_json_schema.cpp + ) + +target_link_libraries(unit-tests-handler-dns + PRIVATE + ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} + Visor::Handler::Dns) + +add_test(NAME unit-tests-handler-dns + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src + COMMAND unit-tests-handler-dns + ) \ No newline at end of file diff --git a/src/handlers/dns/v1/tests/main.cpp b/src/handlers/dns/v1/tests/main.cpp new file mode 100644 index 000000000..3ab9e7842 --- /dev/null +++ b/src/handlers/dns/v1/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/handlers/dns/v1/tests/test_dns_layer.cpp b/src/handlers/dns/v1/tests/test_dns_layer.cpp index b4f8d4a3d..d85a8aec2 100644 --- a/src/handlers/dns/v1/tests/test_dns_layer.cpp +++ b/src/handlers/dns/v1/tests/test_dns_layer.cpp @@ -1,6 +1,4 @@ -#include -#include -#include +#include #include "DnsStreamHandler.h" #include "GeoDB.h" diff --git a/src/handlers/dns/v1/tests/test_dnstap.cpp b/src/handlers/dns/v1/tests/test_dnstap.cpp index a35e80211..5d4447040 100644 --- a/src/handlers/dns/v1/tests/test_dnstap.cpp +++ b/src/handlers/dns/v1/tests/test_dnstap.cpp @@ -1,6 +1,4 @@ -#include -#include -#include +#include #include "DnsStreamHandler.h" #include "DnstapInputStream.h" diff --git a/src/handlers/dns/v1/tests/test_json_schema.cpp b/src/handlers/dns/v1/tests/test_json_schema.cpp index eac352bc6..9adbb49a7 100644 --- a/src/handlers/dns/v1/tests/test_json_schema.cpp +++ b/src/handlers/dns/v1/tests/test_json_schema.cpp @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include +#include #include #include #include diff --git a/src/handlers/dns/v2/CMakeLists.txt b/src/handlers/dns/v2/CMakeLists.txt index 1814e775d..42c9b274f 100644 --- a/src/handlers/dns/v2/CMakeLists.txt +++ b/src/handlers/dns/v2/CMakeLists.txt @@ -26,17 +26,4 @@ target_link_libraries(VisorHandlerDnsV2 set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Handler::Dns::V2 PARENT_SCOPE) -## TEST SUITE -add_executable(unit-tests-handler-dns-v2 - tests/test_dns_layer.cpp - tests/test_dnstap.cpp) - -target_link_libraries(unit-tests-handler-dns-v2 - PRIVATE - ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} - Visor::Handler::Dns::V2 - Visor::Lib::Test) - -add_test(NAME unit-tests-handler-dns-v2 - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-handler-dns-v2) \ No newline at end of file +add_subdirectory(tests) \ No newline at end of file diff --git a/src/handlers/dns/v2/tests/CMakeLists.txt b/src/handlers/dns/v2/tests/CMakeLists.txt new file mode 100644 index 000000000..5972a423a --- /dev/null +++ b/src/handlers/dns/v2/tests/CMakeLists.txt @@ -0,0 +1,17 @@ + +# Unit +add_executable(unit-tests-handler-dns-v2 + main.cpp + test_dns_layer.cpp + test_dnstap.cpp + ) + +target_link_libraries(unit-tests-handler-dns-v2 + PRIVATE + ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} + Visor::Handler::Dns::V2) + +add_test(NAME unit-tests-handler-dns-v2 + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src + COMMAND unit-tests-handler-dns-v2 + ) \ No newline at end of file diff --git a/src/handlers/dns/v2/tests/main.cpp b/src/handlers/dns/v2/tests/main.cpp new file mode 100644 index 000000000..3ab9e7842 --- /dev/null +++ b/src/handlers/dns/v2/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/handlers/dns/v2/tests/test_dns_layer.cpp b/src/handlers/dns/v2/tests/test_dns_layer.cpp index 8834d8f96..be8ffe423 100644 --- a/src/handlers/dns/v2/tests/test_dns_layer.cpp +++ b/src/handlers/dns/v2/tests/test_dns_layer.cpp @@ -1,6 +1,4 @@ -#include -#include -#include +#include #include "DnsStreamHandler.h" #include "GeoDB.h" diff --git a/src/handlers/dns/v2/tests/test_dnstap.cpp b/src/handlers/dns/v2/tests/test_dnstap.cpp index 9da42dd8a..9513a8a6e 100644 --- a/src/handlers/dns/v2/tests/test_dnstap.cpp +++ b/src/handlers/dns/v2/tests/test_dnstap.cpp @@ -1,6 +1,4 @@ -#include -#include -#include +#include #include "DnsStreamHandler.h" #include "DnstapInputStream.h" diff --git a/src/handlers/dns/v2/tests/test_json_schema.cpp b/src/handlers/dns/v2/tests/test_json_schema.cpp index ca043f84d..394174cc2 100644 --- a/src/handlers/dns/v2/tests/test_json_schema.cpp +++ b/src/handlers/dns/v2/tests/test_json_schema.cpp @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include +#include #include #include #include diff --git a/src/handlers/flow/CMakeLists.txt b/src/handlers/flow/CMakeLists.txt index cf7234587..b938cf004 100644 --- a/src/handlers/flow/CMakeLists.txt +++ b/src/handlers/flow/CMakeLists.txt @@ -23,14 +23,4 @@ target_link_libraries(VisorHandlerFlow set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Handler::Flow PARENT_SCOPE) -## TEST SUITE -add_executable(unit-tests-handler-flow test_flows.cpp) - -target_link_libraries(unit-tests-handler-flow - PRIVATE - Visor::Handler::Flow - Visor::Lib::Test) - -add_test(NAME unit-tests-handler-flow - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-handler-flow) \ No newline at end of file +add_subdirectory(tests) \ No newline at end of file diff --git a/src/handlers/flow/tests/CMakeLists.txt b/src/handlers/flow/tests/CMakeLists.txt new file mode 100644 index 000000000..91fc406cc --- /dev/null +++ b/src/handlers/flow/tests/CMakeLists.txt @@ -0,0 +1,15 @@ +## TEST SUITE +add_executable(unit-tests-handler-flow + main.cpp + test_flows.cpp + ) + +target_link_libraries(unit-tests-handler-flow + PRIVATE + ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} + Visor::Handler::Flow) + +add_test(NAME unit-tests-handler-flow + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src + COMMAND unit-tests-handler-flow + ) diff --git a/src/handlers/flow/tests/main.cpp b/src/handlers/flow/tests/main.cpp new file mode 100644 index 000000000..3ab9e7842 --- /dev/null +++ b/src/handlers/flow/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/handlers/flow/test_flows.cpp b/src/handlers/flow/tests/test_flows.cpp similarity index 99% rename from src/handlers/flow/test_flows.cpp rename to src/handlers/flow/tests/test_flows.cpp index a0aeded68..2b689945e 100644 --- a/src/handlers/flow/test_flows.cpp +++ b/src/handlers/flow/tests/test_flows.cpp @@ -1,6 +1,4 @@ -#include -#include -#include +#include #include "FlowInputStream.h" #include "FlowStreamHandler.h" diff --git a/src/handlers/input_resources/CMakeLists.txt b/src/handlers/input_resources/CMakeLists.txt index bee66ddcd..fc0076272 100644 --- a/src/handlers/input_resources/CMakeLists.txt +++ b/src/handlers/input_resources/CMakeLists.txt @@ -26,14 +26,4 @@ target_link_libraries(VisorHandlerInputResources set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Handler::InputResources PARENT_SCOPE) -## TEST SUITE -add_executable(unit-tests-handler-input-resources test_resources_layer.cpp) - -target_link_libraries(unit-tests-handler-input-resources - PRIVATE - Visor::Handler::InputResources - Visor::Lib::Test) - -add_test(NAME unit-tests-handler-input-resources - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-handler-input-resources) \ No newline at end of file +add_subdirectory(tests) \ No newline at end of file diff --git a/src/handlers/input_resources/tests/CMakeLists.txt b/src/handlers/input_resources/tests/CMakeLists.txt new file mode 100644 index 000000000..6e3075cb2 --- /dev/null +++ b/src/handlers/input_resources/tests/CMakeLists.txt @@ -0,0 +1,16 @@ + +## TEST SUITE +add_executable(unit-tests-handler-input-resources + main.cpp + test_resources_layer.cpp + ) + +target_link_libraries(unit-tests-handler-input-resources + PRIVATE + ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} + Visor::Handler::InputResources) + +add_test(NAME unit-tests-handler-input-resources + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src + COMMAND unit-tests-handler-input-resources + ) diff --git a/src/handlers/input_resources/tests/main.cpp b/src/handlers/input_resources/tests/main.cpp new file mode 100644 index 000000000..3b6e7e5b3 --- /dev/null +++ b/src/handlers/input_resources/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/handlers/input_resources/test_resources_layer.cpp b/src/handlers/input_resources/tests/test_resources_layer.cpp similarity index 97% rename from src/handlers/input_resources/test_resources_layer.cpp rename to src/handlers/input_resources/tests/test_resources_layer.cpp index f73e9c664..7c0c34101 100644 --- a/src/handlers/input_resources/test_resources_layer.cpp +++ b/src/handlers/input_resources/tests/test_resources_layer.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include "DnstapInputStream.h" #include "FlowInputStream.h" diff --git a/src/handlers/net/v1/CMakeLists.txt b/src/handlers/net/v1/CMakeLists.txt index e6e542480..e5e6ed287 100644 --- a/src/handlers/net/v1/CMakeLists.txt +++ b/src/handlers/net/v1/CMakeLists.txt @@ -24,24 +24,4 @@ target_link_libraries(VisorHandlerNet set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Handler::Net PARENT_SCOPE) - -## TEST SUITE -if(WIN32) - #dnstap not supported - add_executable(unit-tests-handler-net tests/test_json_schema.cpp) -else() - add_executable(unit-tests-handler-net - tests/test_net_layer.cpp - tests/test_json_schema.cpp) -endif() - -target_link_libraries(unit-tests-handler-net - PRIVATE - ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} - Visor::Handler::Net - Visor::Handler::Dns - Visor::Lib::Test) - -add_test(NAME unit-tests-handler-net - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-handler-net) +add_subdirectory(tests) \ No newline at end of file diff --git a/src/handlers/net/v1/tests/CMakeLists.txt b/src/handlers/net/v1/tests/CMakeLists.txt new file mode 100644 index 000000000..cf0f0efb7 --- /dev/null +++ b/src/handlers/net/v1/tests/CMakeLists.txt @@ -0,0 +1,26 @@ + +## TEST SUITE +if(WIN32) + #dnstap not supported + add_executable(unit-tests-handler-net + main.cpp + test_json_schema.cpp + ) +else() + add_executable(unit-tests-handler-net + main.cpp + test_net_layer.cpp + test_json_schema.cpp + ) +endif() + +target_link_libraries(unit-tests-handler-net + PRIVATE + ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} + Visor::Handler::Net + Visor::Handler::Dns) + +add_test(NAME unit-tests-handler-net + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src + COMMAND unit-tests-handler-net + ) diff --git a/src/handlers/net/v1/tests/main.cpp b/src/handlers/net/v1/tests/main.cpp new file mode 100644 index 000000000..cd298f86e --- /dev/null +++ b/src/handlers/net/v1/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include "catch2/catch.hpp" +#include "spdlog/sinks/stdout_color_sinks.h" +#include "spdlog/spdlog.h" +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/handlers/net/v1/tests/test_json_schema.cpp b/src/handlers/net/v1/tests/test_json_schema.cpp index 608256829..9ae5d3c9f 100644 --- a/src/handlers/net/v1/tests/test_json_schema.cpp +++ b/src/handlers/net/v1/tests/test_json_schema.cpp @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include +#include "catch2/catch.hpp" #include "nlohmann/json-schema.hpp" #include #include diff --git a/src/handlers/net/v1/tests/test_net_layer.cpp b/src/handlers/net/v1/tests/test_net_layer.cpp index 5dfb37dbd..df36c2360 100644 --- a/src/handlers/net/v1/tests/test_net_layer.cpp +++ b/src/handlers/net/v1/tests/test_net_layer.cpp @@ -1,6 +1,4 @@ -#include -#include -#include +#include "catch2/catch.hpp" #include "DnsStreamHandler.h" #include "DnstapInputStream.h" diff --git a/src/handlers/net/v2/CMakeLists.txt b/src/handlers/net/v2/CMakeLists.txt index 38e017234..a26bfa33f 100644 --- a/src/handlers/net/v2/CMakeLists.txt +++ b/src/handlers/net/v2/CMakeLists.txt @@ -24,20 +24,4 @@ target_link_libraries(VisorHandlerNetV2 set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Handler::Net::V2 PARENT_SCOPE) - -## TEST SUITE -if (NOT WIN32) - add_executable(unit-tests-handler-net-v2 tests/test_net_layer.cpp) - - target_link_libraries(unit-tests-handler-net-v2 - PRIVATE - ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} - Visor::Handler::Net::V2 - Visor::Handler::Dns::V2 - Visor::Lib::Test) - - add_test(NAME unit-tests-handler-net-v2 - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-handler-net-v2) -endif() - \ No newline at end of file +add_subdirectory(tests) \ No newline at end of file diff --git a/src/handlers/net/v2/tests/CMakeLists.txt b/src/handlers/net/v2/tests/CMakeLists.txt new file mode 100644 index 000000000..35204889b --- /dev/null +++ b/src/handlers/net/v2/tests/CMakeLists.txt @@ -0,0 +1,24 @@ + +## TEST SUITE +if(WIN32) + #dnstap not supported + add_executable(unit-tests-handler-net-v2 + main.cpp + ) +else() + add_executable(unit-tests-handler-net-v2 + main.cpp + test_net_layer.cpp + ) +endif() + +target_link_libraries(unit-tests-handler-net-v2 + PRIVATE + ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} + Visor::Handler::Net::V2 + Visor::Handler::Dns::V2) + +add_test(NAME unit-tests-handler-net-v2 + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src + COMMAND unit-tests-handler-net-v2 + ) diff --git a/src/handlers/net/v2/tests/main.cpp b/src/handlers/net/v2/tests/main.cpp new file mode 100644 index 000000000..cd298f86e --- /dev/null +++ b/src/handlers/net/v2/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include "catch2/catch.hpp" +#include "spdlog/sinks/stdout_color_sinks.h" +#include "spdlog/spdlog.h" +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/handlers/net/v2/tests/test_json_schema.cpp b/src/handlers/net/v2/tests/test_json_schema.cpp new file mode 100644 index 000000000..aa3c14d05 --- /dev/null +++ b/src/handlers/net/v2/tests/test_json_schema.cpp @@ -0,0 +1,63 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#include "catch2/catch.hpp" +#include "nlohmann/json-schema.hpp" +#include +#include +#include + +#include "PcapInputStream.h" +#include "NetStreamHandler.h" + +using namespace visor::handler::net::v2; +using namespace visor::input::pcap; +using namespace nlohmann; +using nlohmann::json_schema::json_validator; + +TEST_CASE("Net JSON Schema", "[net][iface][json]") +{ + + SECTION("json iface") + { + + PcapInputStream stream{"pcap-test"}; + stream.config_set("pcap_file", "tests/fixtures/dns_udp_tcp_random.pcap"); + stream.config_set("bpf", ""); + stream.config_set("host_spec", "192.168.0.0/24"); + stream.parse_host_spec(); + + visor::Config c; + auto stream_proxy = stream.add_event_proxy(c); + NetStreamHandler net_handler{"net-test", stream_proxy, &c}; + net_handler.config_set("recorded_stream", true); + + net_handler.start(); + stream.start(); + stream.stop(); + net_handler.stop(); + + json net_json; + net_handler.metrics()->window_merged_json(net_json, net_handler.schema_key(), 5); + std::ifstream sfile("handlers/net/v2/tests/window-schema.json"); + CHECK(sfile.is_open()); + std::string schema; + + sfile.seekg(0, std::ios::end); + schema.reserve(sfile.tellg()); + sfile.seekg(0, std::ios::beg); + + schema.assign((std::istreambuf_iterator(sfile)), std::istreambuf_iterator()); + json_validator validator; + + auto schema_json = json::parse(schema); + + try { + validator.set_root_schema(schema_json); + validator.validate(net_json); + } catch (const std::exception &e) { + FAIL(e.what()); + } + } +} diff --git a/src/handlers/net/v2/tests/test_net_layer.cpp b/src/handlers/net/v2/tests/test_net_layer.cpp index 27714c2c8..de015f048 100644 --- a/src/handlers/net/v2/tests/test_net_layer.cpp +++ b/src/handlers/net/v2/tests/test_net_layer.cpp @@ -1,6 +1,4 @@ -#include -#include -#include +#include "catch2/catch.hpp" #include "DnsStreamHandler.h" #include "DnstapInputStream.h" diff --git a/src/handlers/netprobe/CMakeLists.txt b/src/handlers/netprobe/CMakeLists.txt index 8c8bb145e..c3ba79537 100644 --- a/src/handlers/netprobe/CMakeLists.txt +++ b/src/handlers/netprobe/CMakeLists.txt @@ -23,15 +23,4 @@ target_link_libraries(VisorHandlerNetProbe set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Handler::NetProbe PARENT_SCOPE) - -## TEST SUITE -add_executable(unit-tests-handler-netprobe test_net_probe.cpp) - -target_link_libraries(unit-tests-handler-netprobe - PRIVATE - Visor::Handler::NetProbe - Visor::Lib::Test) - -add_test(NAME unit-tests-handler-netprobe - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-handler-netprobe) +add_subdirectory(tests) \ No newline at end of file diff --git a/src/handlers/netprobe/tests/CMakeLists.txt b/src/handlers/netprobe/tests/CMakeLists.txt new file mode 100644 index 000000000..593c542fe --- /dev/null +++ b/src/handlers/netprobe/tests/CMakeLists.txt @@ -0,0 +1,16 @@ + +## TEST SUITE +add_executable(unit-tests-handler-netprobe + main.cpp + test_net_probe.cpp + ) + +target_link_libraries(unit-tests-handler-netprobe + PRIVATE + ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} + Visor::Handler::NetProbe) + +add_test(NAME unit-tests-handler-netprobe + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src + COMMAND unit-tests-handler-netprobe + ) diff --git a/src/handlers/netprobe/tests/main.cpp b/src/handlers/netprobe/tests/main.cpp new file mode 100644 index 000000000..3ab9e7842 --- /dev/null +++ b/src/handlers/netprobe/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/handlers/netprobe/test_net_probe.cpp b/src/handlers/netprobe/tests/test_net_probe.cpp similarity index 97% rename from src/handlers/netprobe/test_net_probe.cpp rename to src/handlers/netprobe/tests/test_net_probe.cpp index 8aeae7fb5..e1fd0119f 100644 --- a/src/handlers/netprobe/test_net_probe.cpp +++ b/src/handlers/netprobe/tests/test_net_probe.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include "NetProbeInputStream.h" #include "NetProbeStreamHandler.h" diff --git a/src/handlers/pcap/CMakeLists.txt b/src/handlers/pcap/CMakeLists.txt index ef8ce2e92..38c91ca7d 100644 --- a/src/handlers/pcap/CMakeLists.txt +++ b/src/handlers/pcap/CMakeLists.txt @@ -21,18 +21,4 @@ target_link_libraries(VisorHandlerPcap set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Handler::Pcap PARENT_SCOPE) - -## TEST SUITE -add_executable(unit-tests-handler-pcap - tests/test_pcap_layer.cpp - tests/test_json_schema.cpp) - -target_link_libraries(unit-tests-handler-pcap - PRIVATE - ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} - Visor::Handler::Pcap - Visor::Lib::Test) - -add_test(NAME unit-tests-handler-pcap - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-handler-pcap) +add_subdirectory(tests) \ No newline at end of file diff --git a/src/handlers/pcap/tests/CMakeLists.txt b/src/handlers/pcap/tests/CMakeLists.txt new file mode 100644 index 000000000..943453032 --- /dev/null +++ b/src/handlers/pcap/tests/CMakeLists.txt @@ -0,0 +1,17 @@ + +## TEST SUITE +add_executable(unit-tests-handler-pcap + main.cpp + test_pcap_layer.cpp + test_json_schema.cpp + ) + +target_link_libraries(unit-tests-handler-pcap + PRIVATE + ${CONAN_LIBS_JSON-SCHEMA-VALIDATOR} + Visor::Handler::Pcap) + +add_test(NAME unit-tests-handler-pcap + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src + COMMAND unit-tests-handler-pcap + ) diff --git a/src/handlers/pcap/tests/main.cpp b/src/handlers/pcap/tests/main.cpp new file mode 100644 index 000000000..3ab9e7842 --- /dev/null +++ b/src/handlers/pcap/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/handlers/pcap/tests/test_json_schema.cpp b/src/handlers/pcap/tests/test_json_schema.cpp index be045da1d..ee0eb9bc8 100644 --- a/src/handlers/pcap/tests/test_json_schema.cpp +++ b/src/handlers/pcap/tests/test_json_schema.cpp @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include +#include #include #include #include diff --git a/src/handlers/pcap/tests/test_pcap_layer.cpp b/src/handlers/pcap/tests/test_pcap_layer.cpp index 102ab325d..ccc643a26 100644 --- a/src/handlers/pcap/tests/test_pcap_layer.cpp +++ b/src/handlers/pcap/tests/test_pcap_layer.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include "GeoDB.h" #include "PcapInputStream.h" diff --git a/src/inputs/dnstap/CMakeLists.txt b/src/inputs/dnstap/CMakeLists.txt index 1da5bf540..ae5b86ce4 100644 --- a/src/inputs/dnstap/CMakeLists.txt +++ b/src/inputs/dnstap/CMakeLists.txt @@ -37,13 +37,16 @@ target_link_libraries(VisorInputDnstap set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Input::Dnstap PARENT_SCOPE) ## TEST SUITE -add_executable(unit-tests-input-dnstap tests/test_dnstap.cpp) +add_executable(unit-tests-input-dnstap + tests/main.cpp + tests/test_dnstap.cpp + ) target_link_libraries(unit-tests-input-dnstap - PRIVATE - Visor::Input::Dnstap - Visor::Lib::Test) + PRIVATE Visor::Input::Dnstap + ) add_test(NAME unit-tests-input-dnstap WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-input-dnstap) \ No newline at end of file + COMMAND unit-tests-input-dnstap + ) \ No newline at end of file diff --git a/src/inputs/dnstap/tests/main.cpp b/src/inputs/dnstap/tests/main.cpp new file mode 100644 index 000000000..3b6e7e5b3 --- /dev/null +++ b/src/inputs/dnstap/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/inputs/dnstap/tests/test_dnstap.cpp b/src/inputs/dnstap/tests/test_dnstap.cpp index 42a1426dd..68c7f83da 100644 --- a/src/inputs/dnstap/tests/test_dnstap.cpp +++ b/src/inputs/dnstap/tests/test_dnstap.cpp @@ -1,8 +1,5 @@ #include "DnstapInputStream.h" - -#include -#include -#include +#include using namespace visor::input::dnstap; using namespace std::chrono; diff --git a/src/inputs/flow/CMakeLists.txt b/src/inputs/flow/CMakeLists.txt index f822d0be3..77309a8b5 100644 --- a/src/inputs/flow/CMakeLists.txt +++ b/src/inputs/flow/CMakeLists.txt @@ -30,13 +30,16 @@ target_link_libraries(VisorInputFlow set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Input::Flow PARENT_SCOPE) ## TEST SUITE -add_executable(unit-tests-input-flow test_flow.cpp) +add_executable(unit-tests-input-flow + tests/main.cpp + tests/test_flow.cpp + ) target_link_libraries(unit-tests-input-flow - PRIVATE - Visor::Input::Flow - Visor::Lib::Test) + PRIVATE Visor::Input::Flow + ) add_test(NAME unit-tests-input-flow WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-input-flow) \ No newline at end of file + COMMAND unit-tests-input-flow + ) \ No newline at end of file diff --git a/src/inputs/flow/tests/main.cpp b/src/inputs/flow/tests/main.cpp new file mode 100644 index 000000000..3b6e7e5b3 --- /dev/null +++ b/src/inputs/flow/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/inputs/flow/test_flow.cpp b/src/inputs/flow/tests/test_flow.cpp similarity index 96% rename from src/inputs/flow/test_flow.cpp rename to src/inputs/flow/tests/test_flow.cpp index fa00036e1..9774becaa 100644 --- a/src/inputs/flow/test_flow.cpp +++ b/src/inputs/flow/tests/test_flow.cpp @@ -1,8 +1,5 @@ #include "FlowInputStream.h" - -#include -#include -#include +#include #include #include diff --git a/src/inputs/mock/CMakeLists.txt b/src/inputs/mock/CMakeLists.txt index 7069b7683..7f9b279d5 100644 --- a/src/inputs/mock/CMakeLists.txt +++ b/src/inputs/mock/CMakeLists.txt @@ -22,13 +22,16 @@ target_link_libraries(VisorInputMock set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Input::Mock PARENT_SCOPE) ## TEST SUITE -add_executable(unit-tests-input-mock test_mock.cpp) +add_executable(unit-tests-input-mock + tests/main.cpp + tests/test_mock.cpp + ) target_link_libraries(unit-tests-input-mock - PRIVATE - Visor::Input::Mock - ${CONAN_LIBS_CATCH2}) + PRIVATE Visor::Input::Mock + ) add_test(NAME unit-tests-input-mock WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-input-mock) + COMMAND unit-tests-input-mock + ) diff --git a/src/inputs/mock/tests/main.cpp b/src/inputs/mock/tests/main.cpp new file mode 100644 index 000000000..3ab9e7842 --- /dev/null +++ b/src/inputs/mock/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/inputs/mock/test_mock.cpp b/src/inputs/mock/tests/test_mock.cpp similarity index 71% rename from src/inputs/mock/test_mock.cpp rename to src/inputs/mock/tests/test_mock.cpp index 90ae121fb..1c73796a3 100644 --- a/src/inputs/mock/test_mock.cpp +++ b/src/inputs/mock/tests/test_mock.cpp @@ -1,5 +1,5 @@ -#include +#include //using namespace visor; //using namespace visor::input::mock; diff --git a/src/inputs/netprobe/CMakeLists.txt b/src/inputs/netprobe/CMakeLists.txt index 84246e4ee..63a39a1ac 100644 --- a/src/inputs/netprobe/CMakeLists.txt +++ b/src/inputs/netprobe/CMakeLists.txt @@ -32,13 +32,16 @@ target_link_libraries(VisorInputNetProbe set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Input::NetProbe PARENT_SCOPE) ## TEST SUITE -add_executable(unit-tests-input-netprobe test_netprobe.cpp) +add_executable(unit-tests-input-netprobe + tests/main.cpp + tests/test_netprobe.cpp + ) target_link_libraries(unit-tests-input-netprobe - PRIVATE - Visor::Input::NetProbe - Visor::Lib::Test) + PRIVATE Visor::Input::NetProbe + ) add_test(NAME unit-tests-input-netprobe WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-input-netprobe) \ No newline at end of file + COMMAND unit-tests-input-netprobe + ) \ No newline at end of file diff --git a/src/inputs/netprobe/tests/main.cpp b/src/inputs/netprobe/tests/main.cpp new file mode 100644 index 000000000..3ab9e7842 --- /dev/null +++ b/src/inputs/netprobe/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/inputs/netprobe/test_netprobe.cpp b/src/inputs/netprobe/tests/test_netprobe.cpp similarity index 96% rename from src/inputs/netprobe/test_netprobe.cpp rename to src/inputs/netprobe/tests/test_netprobe.cpp index 12f64bcc9..100950faf 100644 --- a/src/inputs/netprobe/test_netprobe.cpp +++ b/src/inputs/netprobe/tests/test_netprobe.cpp @@ -1,8 +1,5 @@ #include "NetProbeInputStream.h" - -#include -#include -#include +#include using namespace visor::input::netprobe; using namespace std::chrono; diff --git a/src/inputs/pcap/CMakeLists.txt b/src/inputs/pcap/CMakeLists.txt index a32635af7..59eeb4264 100644 --- a/src/inputs/pcap/CMakeLists.txt +++ b/src/inputs/pcap/CMakeLists.txt @@ -29,13 +29,16 @@ set(VISOR_STATIC_PLUGINS ${VISOR_STATIC_PLUGINS} Visor::Input::Pcap PARENT_SCOPE ## TEST SUITE add_executable(unit-tests-input-pcap + tests/main.cpp tests/test_mock_traffic.cpp - tests/test_parse_pcap.cpp) + tests/test_parse_pcap.cpp + ) target_link_libraries(unit-tests-input-pcap PRIVATE Visor::Input::Pcap - ${CONAN_LIBS_CATCH2}) + ) add_test(NAME unit-tests-input-pcap WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src - COMMAND unit-tests-input-pcap) \ No newline at end of file + COMMAND unit-tests-input-pcap + ) \ No newline at end of file diff --git a/src/inputs/pcap/tests/main.cpp b/src/inputs/pcap/tests/main.cpp new file mode 100644 index 000000000..3ab9e7842 --- /dev/null +++ b/src/inputs/pcap/tests/main.cpp @@ -0,0 +1,24 @@ +#define CATCH_CONFIG_RUNNER +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + auto logger = spdlog::get("visor"); + if (!logger) { + spdlog::stderr_color_mt("visor"); + } + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/inputs/pcap/tests/test_mock_traffic.cpp b/src/inputs/pcap/tests/test_mock_traffic.cpp index afb609994..2a00ded0a 100644 --- a/src/inputs/pcap/tests/test_mock_traffic.cpp +++ b/src/inputs/pcap/tests/test_mock_traffic.cpp @@ -1,5 +1,5 @@ #include "PcapInputStream.h" -#include +#include using namespace visor::input::pcap; using namespace std::chrono; diff --git a/src/inputs/pcap/tests/test_parse_pcap.cpp b/src/inputs/pcap/tests/test_parse_pcap.cpp index 0633701b3..83e38ef59 100644 --- a/src/inputs/pcap/tests/test_parse_pcap.cpp +++ b/src/inputs/pcap/tests/test_parse_pcap.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #ifdef __GNUC__ #pragma GCC diagnostic pop diff --git a/src/tests/main.cpp b/src/tests/main.cpp new file mode 100644 index 000000000..6cfe48b5e --- /dev/null +++ b/src/tests/main.cpp @@ -0,0 +1,27 @@ +#define CATCH_CONFIG_RUNNER +#include +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-declarations" +#endif +#include "inputs/static_plugins.h" +#include "handlers/static_plugins.h" +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif +#include +#include + +int main(int argc, char *argv[]) +{ + Catch::Session session; + + int result = session.applyCommandLine(argc, argv); + if (result != 0) { + return result; + } + + result = session.run(); + + return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); +} diff --git a/src/tests/test_geoip.cpp b/src/tests/test_geoip.cpp index 7288a75fb..cf275d474 100644 --- a/src/tests/test_geoip.cpp +++ b/src/tests/test_geoip.cpp @@ -4,7 +4,7 @@ #else #include #endif -#include +#include #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wold-style-cast" #endif diff --git a/src/tests/test_handlers.cpp b/src/tests/test_handlers.cpp index 6e96d3392..c3f22cebe 100644 --- a/src/tests/test_handlers.cpp +++ b/src/tests/test_handlers.cpp @@ -1,6 +1,6 @@ #include "StreamHandler.h" -#include +#include using namespace visor; diff --git a/src/tests/test_ipport.cpp b/src/tests/test_ipport.cpp index b7b1e7312..54c42464e 100644 --- a/src/tests/test_ipport.cpp +++ b/src/tests/test_ipport.cpp @@ -1,6 +1,6 @@ #include "IpPort.h" -#include +#include using namespace visor::network; diff --git a/src/tests/test_metrics.cpp b/src/tests/test_metrics.cpp index 1c263ec2b..710b8cdcb 100644 --- a/src/tests/test_metrics.cpp +++ b/src/tests/test_metrics.cpp @@ -1,7 +1,5 @@ #include "AbstractMetricsManager.h" - -#include -#include +#include using namespace visor; diff --git a/src/tests/test_policies.cpp b/src/tests/test_policies.cpp index f0e483815..a9ebfae35 100644 --- a/src/tests/test_policies.cpp +++ b/src/tests/test_policies.cpp @@ -1,23 +1,10 @@ -#include -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmissing-declarations" -#endif -#include "inputs/static_plugins.h" -#include "handlers/static_plugins.h" -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif - #include "CoreRegistry.h" #include "HandlerManager.h" #include "HandlerModulePlugin.h" #include "InputStream.h" #include "InputStreamManager.h" #include "Policies.h" - -#include -#include +#include #include #include #include diff --git a/src/tests/test_sketches.cpp b/src/tests/test_sketches.cpp index 4f89f7714..1e4c0858f 100644 --- a/src/tests/test_sketches.cpp +++ b/src/tests/test_sketches.cpp @@ -4,7 +4,7 @@ #pragma GCC diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wrange-loop-analysis" #endif -#include +#include #include #include #include diff --git a/src/tests/test_taps.cpp b/src/tests/test_taps.cpp index fa8867542..fd2c8f5fb 100644 --- a/src/tests/test_taps.cpp +++ b/src/tests/test_taps.cpp @@ -1,19 +1,6 @@ -#include -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wmissing-declarations" -#endif -#include "inputs/static_plugins.h" -#include "handlers/static_plugins.h" -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif - #include "CoreRegistry.h" #include "Taps.h" - -#include -#include +#include #include #include #include