Skip to content

Commit

Permalink
Revert "migrate from catch2v2 to catch2v3 and implement VisorTest hel…
Browse files Browse the repository at this point in the history
…per lib (#689)"

This reverts commit 20403fb.
  • Loading branch information
weyrick committed Oct 7, 2023
1 parent 20403fb commit 6e79b4d
Show file tree
Hide file tree
Showing 88 changed files with 869 additions and 383 deletions.
3 changes: 2 additions & 1 deletion conanfile.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
message(STATUS "Custom Libraries")

add_subdirectory(visor_test)
add_subdirectory(visor_transaction)
add_subdirectory(visor_tcp)
add_subdirectory(visor_dns)
Expand Down
14 changes: 1 addition & 13 deletions libs/visor_dns/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
add_subdirectory(tests)
24 changes: 24 additions & 0 deletions libs/visor_dns/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
94 changes: 47 additions & 47 deletions libs/visor_dns/tests/benchmark_dns.cpp
Original file line number Diff line number Diff line change
@@ -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 <catch2/benchmark/catch_benchmark.hpp>
#include <catch2/catch_test_macros.hpp>

#include "benchmark/benchmark.h"
#include "dns.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
Expand All @@ -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();
Binary file removed libs/visor_dns/tests/dns_udp_tcp_random.pcap
Binary file not shown.
24 changes: 24 additions & 0 deletions libs/visor_dns/tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#define CATCH_CONFIG_RUNNER
#include <catch2/catch.hpp>
#include <cstdlib>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>

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);
}
2 changes: 1 addition & 1 deletion libs/visor_dns/tests/test_dns.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <catch2/catch_all.hpp>
#include "catch2/catch.hpp"

#include "dns.h"

Expand Down
17 changes: 0 additions & 17 deletions libs/visor_test/CMakeLists.txt

This file was deleted.

24 changes: 0 additions & 24 deletions libs/visor_test/catch2/catch_test_visor.hpp

This file was deleted.

12 changes: 1 addition & 11 deletions libs/visor_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
add_subdirectory(tests)
15 changes: 15 additions & 0 deletions libs/visor_utils/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
24 changes: 24 additions & 0 deletions libs/visor_utils/tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#define CATCH_CONFIG_RUNNER
#include <catch2/catch.hpp>
#include <cstdlib>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>

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);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <catch2/catch_test_macros.hpp>
#include "catch2/catch.hpp"
#include "utils.h"

#ifdef _WIN32
Expand Down
14 changes: 7 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
COMMAND unit-tests-visor-core
)
21 changes: 5 additions & 16 deletions src/handlers/bgp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,14 @@ add_library(Visor::Handler::Bgp ALIAS VisorHandlerBgp)

target_include_directories(VisorHandlerBgp
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

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)
add_subdirectory(tests)
Loading

0 comments on commit 6e79b4d

Please sign in to comment.