Skip to content

Commit

Permalink
Make valgrind work again
Browse files Browse the repository at this point in the history
  • Loading branch information
fbtom committed Oct 7, 2024
1 parent 053e8ec commit a320630
Show file tree
Hide file tree
Showing 10 changed files with 847 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ compile_commands.json
build/

# Build directory for tests
build_tests/
build/

# Build directory
buildDebug/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ This will not rebuild external_libraries from scratch if they exist and there is

### Running ctest
After building test targets, ctest running all the tests can be run in 2 ways:
1. from `build_tests` directory, simply using command `ctest`
1. from `build` directory, simply using command `ctest`
2. from main desktop-app-folder via script
```bash
./ctest_run.sh
Expand Down
8 changes: 4 additions & 4 deletions backend_clean_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ if [ ! -d "external_libraries" ]; then
mkdir external_libraries
fi

# Check if the own_libraries directory does not exist
if [ ! -d "own_libraries" ]; then
# Check if the libs directory does not exist
if [ ! -d "libs" ]; then
# If it does not exist, create it
mkdir own_libraries
mkdir libs
fi

# Clean the build library
Expand All @@ -24,5 +24,5 @@ mkdir build && cd build
# Configure with CMake
cmake -DCMAKE_BUILD_TYPE=Debug ../modules/backend/

# Build the target and install backend libs and headers to own_libraries
# Build the target and install backend libs and headers to libs
cmake --build . --parallel --target install -- -j2
6 changes: 3 additions & 3 deletions ctest_run.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

# Find the build_tests directory
BUILD_TESTS_DIR=$(find . -type d -name "build_tests")
# Find the build directory
BUILD_TESTS_DIR=$(find . -type d -name "build")

if [ -z "$BUILD_TESTS_DIR" ]
then
echo "build_tests directory not found"
echo "build directory not found"
exit 1
fi

Expand Down
12 changes: 6 additions & 6 deletions documentation/building_and_running_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ If we we have `backend` cmake configuration run beforehand and/or built `backend
After having `backend` module built, we can proceed to building `test` module itself.

If we want to build `tests` module from clean state (and we have `backend` built), we need to:
1. Create or cleanup "build_tests" directory
2. ```cd build_tests```
1. Create or cleanup "build" directory
2. ```cd build```
3. Run cmake configuration:
```cmake -DCMAKE_BUILD_TYPE=Debug ../modules/tests/```
4. Build `tests` module
```cmake --build . --parallel```
NOTE: `-j2` flag (or with any other reasonable number) can be used to limit number of threads for building if problems are encountered.

If we we have `tests` cmake configuration run beforehand and/or built `tests` it is enough to perform step 4 from "build_tests" directory.
If we we have `tests` cmake configuration run beforehand and/or built `tests` it is enough to perform step 4 from "build" directory.

## Building backend with script from clean state

Expand All @@ -42,7 +42,7 @@ If backend was built previously it might be more efficient to perform just the r
### Building tests and backend with script from clean state

If we want to build `backend` and `tests` together from clean state, we can just run from top level folder the `tests_and_backend_clean_build.sh` script.
NOTE: this script cleans "build" and "build_tests" directory each time so it performs build from the start (**but external_libraries will be reused if built previously**).
NOTE: this script cleans "build" and "build" directory each time so it performs build from the start (**but external_libraries will be reused if built previously**).
It is up to developer if one prefers to rebuild from clean build each time because it is handy to use script (with the cost of time).
If backend and tests were built previously it might be more efficient to perform just the required steps explained in manual building section.
But remember, that each change in `backend` requires it to be rebuild itself.
Expand Down Expand Up @@ -85,7 +85,7 @@ We have to scripts for run all tests with ctest:
- `ctest_run.sh` - for normal test running
- `valgrind_ctest_run.sh` - for running ctest under valgrind.

Optionally we can run ctest manually from "build_tests" directory with simple commands:
Optionally we can run ctest manually from "build" directory with simple commands:
```ctest```

It is still recommended to use valgrind script for memory checking instead of trying to run ctest with valgrind manually.
Expand All @@ -97,7 +97,7 @@ The `valgrind_ctest_run.sh` when run will give us some interesting info. Example
6/7 MemCheck: #6: TreatmentStateTests .............. Defects: 4
7/7 MemCheck: #7: basic_construction-test .......... Defects: 1
MemCheck log files can be found here: (<#> corresponds to test number)
/home/piworzuop/Klub-Ninja/projekt/desktop-business-app/build_tests/Testing/Temporary/MemoryChecker.<#>.log
/home/piworzuop/Klub-Ninja/projekt/desktop-business-app/build/Testing/Temporary/MemoryChecker.<#>.log
Memory checking results:
Memory Leak - 1
Uninitialized Memory Conditional - 6
Expand Down
6 changes: 3 additions & 3 deletions documentation/cmake_policy/Cmake_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ It is supposed to be completely independent from other modules.
In fact, backend module won't produce typical executable binary (it has no `main.cpp` file).

Instead it will produce multiple libraries, each corresponding directly to its submodule.
Those libraries will land in separate folder (currently called `own_libraries`).
Those libraries will land in separate folder (currently called `libs`).

For example:
`libclinic-lib.a` - relates to `modules/clinic` subfolder.
Expand Down Expand Up @@ -129,13 +129,13 @@ Other submodules look very similar.

Regardless of the above, whenever we include something, which is in same folder as our file we just write `#include "someFile.hpp"`

6. In one of final steps we need to install our library in own_libraries folder. This is done through:
6. In one of final steps we need to install our library in libs folder. This is done through:

![](image-snippets/image-17.png)

This is required for development of other modules like `tests` or `frontend` in independent cmake trees.

7. But besides the binaries of libs we also need to install/copy include files of current submodule in own_libraries folder.
7. But besides the binaries of libs we also need to install/copy include files of current submodule in libs folder.

![](image-snippets/image-18.png)

Expand Down
2 changes: 1 addition & 1 deletion modules/backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED on)

set(EXTERNAL_LIBRARIES_DIR ${PROJECT_SOURCE_DIR}/../../external_libraries/)
set(OWN_LIBRARIES_DIR ${PROJECT_SOURCE_DIR}/../../own_libraries/)
set(OWN_LIBRARIES_DIR ${PROJECT_SOURCE_DIR}/../../libs/)

include(installation_rules.cmake)

Expand Down
14 changes: 11 additions & 3 deletions modules/backend/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../../bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../../bin)

include(install_gtest.cmake)

include(GoogleTest)
enable_testing()

include(CTest)
set(MEMORYCHECK_COMMAND_OPTIONS
"--trace-children=yes --leak-check=full --show-reachable=yes --read-var-info=yes --track-origins=yes --error-limit=no -error-exitcode=1")
set(MEMORYCHECK_COMMAND valgrind)
set(MEMORYCHECK_COMMAND_OPTIONS
"--trace-children=yes
--gen-suppressions=all
--leak-check=full
--show-reachable=yes
--read-var-info=yes
--track-origins=yes
--error-limit=no
--child-silent-after-fork=yes
-error-exitcode=1")

add_subdirectory(unit)
add_subdirectory(integration)
Loading

0 comments on commit a320630

Please sign in to comment.