Skip to content

Commit daf9931

Browse files
committed
add valgrind memory leak tests; add a memory leak
1 parent 82b5a6e commit daf9931

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

docs/build.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Overview of the build system
22
`datalog-cpp` uses the [CMake](www.cmake.org) build tool to generate build files for other build systems. Currently, building using clang and gcc with Makefiles are supported.
33

4+
You `valgrind` installed to run memory checks: `sudo apt install valgrind`
5+
6+
To run all regression tests:
7+
```
8+
cd tests
9+
./run_tests.sh
10+
```
11+
412
# Building with Makefiles
513
From the command line inside a git clone, run the following:
614
```

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ project("datalog-cpp")
2121
# specify the C++ standard
2222
set(CMAKE_CXX_STANDARD 17)
2323

24+
# cpp memory checker
25+
include (CTest)
26+
2427
# unit-test library
2528
add_library(tests_main STATIC ../tests/tests_main.cpp)
2629

@@ -29,15 +32,18 @@ add_executable(types_test ../tests/types_test.cpp)
2932
target_include_directories(types_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
3033
target_link_libraries(types_test tests_main)
3134
target_compile_definitions(types_test PUBLIC UNIX)
35+
add_test(types_test_memory types_test)
3236

3337
# variable_test target
3438
add_executable(variable_test ../tests/variable_test.cpp)
3539
target_include_directories(variable_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
3640
target_link_libraries(variable_test tests_main)
3741
target_compile_definitions(variable_test PUBLIC UNIX)
42+
add_test(variable_test_memory variable_test)
3843

3944
# tuple_binding_test target
4045
add_executable(tuple_binding_test ../tests/tuple_binding_test.cpp)
4146
target_include_directories(tuple_binding_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
4247
target_link_libraries(tuple_binding_test tests_main)
4348
target_compile_definitions(tuple_binding_test PUBLIC UNIX)
49+
add_test(tuple_binding_test_memory tuple_binding_test)

tests/run_tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22
set -e
3+
echo "Running tests"
34
../build/types_test
45
../build/variable_test
5-
../build/tuple_binding_test
6+
../build/tuple_binding_test
7+
echo "Checking for memory leaks"
8+
cd ../build; ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --error-exitcode=1" -T memcheck

tests/tuple_binding_test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ bool unbindTest()
1515
return returnVal;
1616
}
1717

18+
bool leakTest() {
19+
double* leak = new double[10];
20+
std::cout << "Hello!" << std::endl;
21+
return true;
22+
}
23+
1824
TEST_CASE("tuple binding test", "[tuple-binding]")
1925
{
2026
REQUIRE(unbindTest());
27+
REQUIRE(leakTest());
2128
}

0 commit comments

Comments
 (0)