Skip to content

add valgrind memory leak tests #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/linux_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
- uses: actions/checkout@v2
- name: build
run: |
sudo apt install -y valgrind
mkdir build && cd build
cmake ../src
make
Expand Down
8 changes: 8 additions & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Overview of the build system
`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.

You `valgrind` installed to run memory checks: `sudo apt install valgrind`

To run all regression tests:
```
cd tests
./run_tests.sh
```

# Building with Makefiles
From the command line inside a git clone, run the following:
```
Expand Down
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ project("datalog-cpp")
# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)

# cpp memory checker
include (CTest)

# unit-test library
add_library(tests_main STATIC ../tests/tests_main.cpp)

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

# variable_test target
add_executable(variable_test ../tests/variable_test.cpp)
target_include_directories(variable_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(variable_test tests_main)
target_compile_definitions(variable_test PUBLIC UNIX)
add_test(variable_test_memory variable_test)

# tuple_binding_test target
add_executable(tuple_binding_test ../tests/tuple_binding_test.cpp)
target_include_directories(tuple_binding_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(tuple_binding_test tests_main)
target_compile_definitions(tuple_binding_test PUBLIC UNIX)
add_test(tuple_binding_test_memory tuple_binding_test)
5 changes: 4 additions & 1 deletion tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash
set -e
echo "Running tests"
../build/types_test
../build/variable_test
../build/tuple_binding_test
../build/tuple_binding_test
echo "Checking for memory leaks"
cd ../build; ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --error-exitcode=1" -T memcheck
8 changes: 8 additions & 0 deletions tests/tuple_binding_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ bool unbindTest()
return returnVal;
}

bool leakTest() {
double* leak = new double[10];
std::cout << "Hello!" << std::endl;
delete[] leak;
return true;
}

TEST_CASE("tuple binding test", "[tuple-binding]")
{
REQUIRE(unbindTest());
REQUIRE(leakTest());
}