Skip to content

Commit b66a285

Browse files
authored
Merge pull request #8 from Z80coder/add-memory-checks
add valgrind memory leak tests
2 parents 82b5a6e + 2e1e780 commit b66a285

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

.github/workflows/linux_check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010
- uses: actions/checkout@v2
1111
- name: build
1212
run: |
13+
sudo apt install -y valgrind
1314
mkdir build && cd build
1415
cmake ../src
1516
make

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ bool unbindTest()
1515
return returnVal;
1616
}
1717

18+
bool leakTest() {
19+
double* leak = new double[10];
20+
std::cout << "Hello!" << std::endl;
21+
delete[] leak;
22+
return true;
23+
}
24+
1825
TEST_CASE("tuple binding test", "[tuple-binding]")
1926
{
2027
REQUIRE(unbindTest());
28+
REQUIRE(leakTest());
2129
}

0 commit comments

Comments
 (0)