Skip to content

Commit 5e15f15

Browse files
authored
Revert "migrate from catch2v2 to catch2v3 and implement VisorTest helper lib (#689)" (#691)
This reverts commit 20403fb.
1 parent 20403fb commit 5e15f15

File tree

88 files changed

+869
-383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+869
-383
lines changed

conanfile.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[requires]
2-
catch2/3.4.0
2+
benchmark/1.8.3
3+
catch2/2.13.10
34
corrade/2020.06
45
cpp-httplib/0.14.0
56
docopt.cpp/0.6.3

libs/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
message(STATUS "Custom Libraries")
22

3-
add_subdirectory(visor_test)
43
add_subdirectory(visor_transaction)
54
add_subdirectory(visor_tcp)
65
add_subdirectory(visor_dns)

libs/visor_dns/CMakeLists.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,4 @@ target_link_libraries(VisorLibDns
2424
${CONAN_LIBS_FMT}
2525
)
2626

27-
## TEST SUITE
28-
add_executable(unit-tests-visor-dns
29-
tests/test_dns.cpp
30-
tests/benchmark_dns.cpp)
31-
32-
target_link_libraries(unit-tests-visor-dns
33-
PRIVATE
34-
Visor::Lib::Dns
35-
${CONAN_LIBS_CATCH2})
36-
37-
add_test(NAME unit-tests-visor-dns
38-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/libs/visor_dns
39-
COMMAND unit-tests-visor-dns)
27+
add_subdirectory(tests)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Unit
2+
add_executable(unit-tests-visor-dns
3+
main.cpp
4+
test_dns.cpp
5+
)
6+
7+
target_link_libraries(unit-tests-visor-dns
8+
PRIVATE
9+
${CONAN_LIBS_JSON-SCHEMA-VALIDATOR}
10+
Visor::Lib::Dns)
11+
12+
add_test(NAME unit-tests-visor-dns
13+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
14+
COMMAND unit-tests-visor-dns
15+
)
16+
17+
# Benchmark
18+
add_executable(benchmark-visor-dns
19+
benchmark_dns.cpp
20+
)
21+
22+
target_link_libraries(benchmark-visor-dns PRIVATE
23+
Visor::Lib::Dns
24+
${CONAN_LIBS_BENCHMARK})
Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4-
#include <catch2/benchmark/catch_benchmark.hpp>
5-
#include <catch2/catch_test_macros.hpp>
64

5+
#include "benchmark/benchmark.h"
76
#include "dns.h"
87
#ifdef __GNUC__
98
#pragma GCC diagnostic push
@@ -22,65 +21,66 @@
2221

2322
using namespace visor::lib::dns;
2423

25-
void BM_aggregateDomain(const std::string &domain)
24+
static void BM_aggregateDomain(benchmark::State &state)
2625
{
2726
AggDomainResult result;
28-
result = aggregateDomain(domain);
27+
std::string domain{"biz.foo.bar.com"};
28+
for (auto _ : state) {
29+
result = aggregateDomain(domain);
30+
}
2931
}
32+
BENCHMARK(BM_aggregateDomain);
3033

31-
void BM_pcapReadNoParse()
34+
static void BM_aggregateDomainLong(benchmark::State &state)
3235
{
33-
auto reader = pcpp::IFileReaderDevice::getReader("tests/dns_udp_tcp_random.pcap");
34-
35-
if (!reader->open()) {
36-
throw std::runtime_error("Cannot open pcap/pcapng file");
37-
}
38-
39-
pcpp::RawPacket rawPacket;
40-
while (reader->getNextPacket(rawPacket)) {
36+
AggDomainResult result;
37+
std::string domain{"long1.long2.long3.long4.long5.long6.long7.long8.biz.foo.bar.com"};
38+
for (auto _ : state) {
39+
result = aggregateDomain(domain);
4140
}
42-
43-
reader->close();
44-
delete reader;
4541
}
4642

47-
void BM_pcapReadParse()
43+
BENCHMARK(BM_aggregateDomainLong);
44+
45+
static void BM_pcapReadNoParse(benchmark::State &state)
4846
{
4947

50-
auto reader = pcpp::IFileReaderDevice::getReader("tests/dns_udp_tcp_random.pcap");
48+
for (auto _ : state) {
49+
auto reader = pcpp::IFileReaderDevice::getReader("fixtures/dns_udp_tcp_random.pcap");
5150

52-
if (!reader->open()) {
53-
throw std::runtime_error("Cannot open pcap/pcapng file");
54-
}
51+
if (!reader->open()) {
52+
throw std::runtime_error("Cannot open pcap/pcapng file");
53+
}
5554

56-
pcpp::RawPacket rawPacket;
57-
while (reader->getNextPacket(rawPacket)) {
58-
pcpp::Packet packet(&rawPacket, pcpp::OsiModelTransportLayer);
59-
}
55+
pcpp::RawPacket rawPacket;
56+
while (reader->getNextPacket(rawPacket)) {
57+
}
6058

61-
reader->close();
62-
delete reader;
59+
reader->close();
60+
delete reader;
61+
}
6362
}
63+
BENCHMARK(BM_pcapReadNoParse);
6464

65-
TEST_CASE("DNS benchmark")
65+
static void BM_pcapReadParse1(benchmark::State &state)
6666
{
67-
BENCHMARK("Aggregate Domain")
68-
{
69-
return BM_aggregateDomain("biz.foo.bar.com");
70-
};
71-
72-
BENCHMARK("Aggregate Domain Long")
73-
{
74-
return BM_aggregateDomain("long1.long2.long3.long4.long5.long6.long7.long8.biz.foo.bar.com");
75-
};
76-
77-
BENCHMARK("Pcap Read No Parse")
78-
{
79-
return BM_pcapReadNoParse();
80-
};
81-
82-
BENCHMARK("Pcap Read No Parse")
83-
{
84-
return BM_pcapReadParse();
85-
};
67+
68+
for (auto _ : state) {
69+
auto reader = pcpp::IFileReaderDevice::getReader("fixtures/dns_udp_tcp_random.pcap");
70+
71+
if (!reader->open()) {
72+
throw std::runtime_error("Cannot open pcap/pcapng file");
73+
}
74+
75+
pcpp::RawPacket rawPacket;
76+
while (reader->getNextPacket(rawPacket)) {
77+
pcpp::Packet packet(&rawPacket, pcpp::OsiModelTransportLayer);
78+
}
79+
80+
reader->close();
81+
delete reader;
82+
}
8683
}
84+
BENCHMARK(BM_pcapReadParse1);
85+
86+
BENCHMARK_MAIN();
-1.69 MB
Binary file not shown.

libs/visor_dns/tests/main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#define CATCH_CONFIG_RUNNER
2+
#include <catch2/catch.hpp>
3+
#include <cstdlib>
4+
#include <spdlog/sinks/stdout_color_sinks.h>
5+
#include <spdlog/spdlog.h>
6+
7+
int main(int argc, char *argv[])
8+
{
9+
Catch::Session session;
10+
11+
auto logger = spdlog::get("visor");
12+
if (!logger) {
13+
spdlog::stderr_color_mt("visor");
14+
}
15+
16+
int result = session.applyCommandLine(argc, argv);
17+
if (result != 0) {
18+
return result;
19+
}
20+
21+
result = session.run();
22+
23+
return (result == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
24+
}

libs/visor_dns/tests/test_dns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <catch2/catch_all.hpp>
1+
#include "catch2/catch.hpp"
22

33
#include "dns.h"
44

libs/visor_test/CMakeLists.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.

libs/visor_test/catch2/catch_test_visor.hpp

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)