Skip to content

Commit

Permalink
Uncomment running test with msan
Browse files Browse the repository at this point in the history
  • Loading branch information
sashashura committed Nov 18, 2023
1 parent 9fbc712 commit 11289d2
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 31 deletions.
27 changes: 13 additions & 14 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,19 @@ task:
- export SAMPLES="Tests/Fuzzers/RegressionTests/regression_samples"
- Tests/Fuzzers/RegressionTests/run_tests.sh

# Compilation failed due too issue w/ MemPlumber
# task:
# name: Regression Tests Linux (Memory Sanitizer)
# container:
# image: gcr.io/oss-fuzz-base/base-clang
# configure_script:
# - apt-get update && apt-get install -y cmake git libpcap-dev
# - cmake -S . -B $BUILD_DIR -DPCAPPP_USE_SANITIZER=MemorySanitizer -DPCAPPP_BUILD_FUZZERS=ON -DPCAPPP_BUILD_EXAMPLES=OFF
# build_script:
# - cmake --build $BUILD_DIR -j 2
# test_script:
# - export BINARY="$BUILD_DIR/Tests/Fuzzers/FuzzTarget"
# - export SAMPLES="Tests/Fuzzers/RegressionTests/regression_samples"
# - Tests/Fuzzers/RegressionTests/run_tests.sh
task:
name: Regression Tests Linux (Memory Sanitizer)
container:
image: gcr.io/oss-fuzz-base/base-clang
configure_script:
- apt-get update && apt-get install -y cmake git libpcap-dev
- cmake -S . -B $BUILD_DIR -DPCAPPP_USE_SANITIZER=MemorySanitizer -DPCAPPP_BUILD_FUZZERS=ON -DPCAPPP_BUILD_EXAMPLES=OFF
build_script:
- cmake --build $BUILD_DIR -j 2
test_script:
- export BINARY="$BUILD_DIR/Tests/Fuzzers/FuzzTarget"
- export SAMPLES="Tests/Fuzzers/RegressionTests/regression_samples"
- Tests/Fuzzers/RegressionTests/run_tests.sh

task:
name: Regression Tests Linux (Undefined Behavior Sanitizer)
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ if(PCAPPP_BUILD_EXAMPLES)
add_subdirectory(Examples)
endif()

if(PCAPPP_BUILD_FUZZERS)
add_definitions(-DPCAPPP_BUILD_FUZZERS)
endif()

if(PCAPPP_BUILD_TESTS
OR PCAPPP_BUILD_FUZZERS
OR PCAPPP_BUILD_EXAMPLES)
Expand Down
20 changes: 14 additions & 6 deletions Tests/Packet++Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,20 @@ add_executable(
Tests/WakeOnLanTests.cpp
Utils/TestUtils.cpp)

target_link_libraries(
Packet++Test
PUBLIC memplumber
Packet++
PcppTestFramework
EndianPortable)
if(PCAPPP_BUILD_FUZZERS)
target_link_libraries(
Packet++Test
PUBLIC Packet++
PcppTestFramework
EndianPortable)
else()
target_link_libraries(
Packet++Test
PUBLIC memplumber
Packet++
PcppTestFramework
EndianPortable)
endif()

if(MSVC)
# This executable requires getopt.h not available on VStudio
Expand Down
20 changes: 14 additions & 6 deletions Tests/Pcap++Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ add_executable(
Tests/TcpReassemblyTests.cpp
Tests/XdpTests.cpp)

target_link_libraries(
Pcap++Test
PUBLIC memplumber
Pcap++
PcppTestFramework
EndianPortable)
if(PCAPPP_BUILD_FUZZERS)
target_link_libraries(
Pcap++Test
PUBLIC Pcap++
PcppTestFramework
EndianPortable)
else()
target_link_libraries(
Pcap++Test
PUBLIC memplumber
Pcap++
PcppTestFramework
EndianPortable)
endif()

if(MSVC)
# This executable requires getopt.h not available on VStudio
Expand Down
4 changes: 3 additions & 1 deletion Tests/PcppTestFramework/PcppTestFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#include <iomanip>
#include <iostream>
#include "memplumber.h"
#ifndef PCAPPP_BUILD_FUZZERS
#include "memplumber.h"
#endif
#include "PcppTestFrameworkCommon.h"

#define _PTF_PRINT_TYPE_ACTUAL(exp, val) val
Expand Down
18 changes: 14 additions & 4 deletions Tests/PcppTestFramework/PcppTestFrameworkRun.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ static bool __ptfCheckTags(const std::string &tagSet, const std::string &tagSetT
return false;
}

#ifdef PCAPPP_BUILD_FUZZERS
#define MEMPLUMBER_START
#define MEMPLUMBER_STOP
#define MEMPLUMBER_CHECK
#else
#define MEMPLUMBER_START MemPlumber::start(memAllocVerbose)
#define MEMPLUMBER_STOP MemPlumber::stopAndFreeAllMemory()
#define MEMPLUMBER_CHECK MemPlumber::memLeakCheck(memLeakCount, memLeakSize, true)
#endif

#define PTF_START_RUNNING_TESTS(userIncludeTags, userExcludeTags, configTags) \
bool allTestsPassed = true; \
int testsPassed = 0; \
Expand Down Expand Up @@ -73,21 +83,21 @@ static bool __ptfCheckTags(const std::string &tagSet, const std::string &tagSetT
if (runMemLeakCheck) \
{ \
bool memAllocVerbose = __ptfCheckTags("mem_leak_check_verbose", configTagsToRun, false); \
MemPlumber::start(memAllocVerbose); \
MEMPLUMBER_START; \
} \
TestName(TestName##_result, verboseMode, showSkippedTests); \
if (runMemLeakCheck) \
{ \
if (TestName##_result != PTF_RESULT_PASSED) \
{ \
MemPlumber::stopAndFreeAllMemory(); \
MEMPLUMBER_STOP; \
} \
else \
{ \
size_t memLeakCount = 0; \
uint64_t memLeakSize = 0; \
MemPlumber::memLeakCheck(memLeakCount, memLeakSize, true); \
MemPlumber::stopAndFreeAllMemory(); \
MEMPLUMBER_CHECK; \
MEMPLUMBER_STOP; \
if (memLeakCount > 0 || memLeakSize > 0) \
{ \
TestName##_result = PTF_RESULT_FAILED; \
Expand Down

0 comments on commit 11289d2

Please sign in to comment.