diff --git a/.github/workflows/test_valgrind.yml b/.github/workflows/test_valgrind.yml index 4429e56e4f..94cac89a40 100644 --- a/.github/workflows/test_valgrind.yml +++ b/.github/workflows/test_valgrind.yml @@ -21,22 +21,40 @@ name: valgrind check # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. on: + # Allows you to run this workflow manually. + workflow_dispatch: + inputs: + MAKEFLAGS: + type: string + description: 'Make flags to use for compilation (like -j4)' + default: '-j4' + MPI: + type: string + description: 'Use MPI for compilation (ON/OFF)' + default: 'ON' + BUILD_TYPE: + type: string + description: 'Build type (Release/Debug)' + default: 'Debug' + TEST_LEVEL: + type: string + description: 'Test level used for configuring (T8_TEST_LEVEL_FULL, T8_TEST_LEVEL_MEDIUM, or T8_TEST_LEVEL_BASIC)' + default: 'T8_TEST_LEVEL_BASIC' workflow_call: inputs: MAKEFLAGS: - required: true type: string description: 'Make flags to use for compilation (like -j4)' + default: '-j4' MPI: - required: true type: string description: 'Use MPI for compilation (ON/OFF)' + default: 'ON' BUILD_TYPE: - required: true type: string description: 'Build type (Release/Debug)' + default: 'Debug' TEST_LEVEL: - required: true type: string description: 'Test level used for configuring (T8_TEST_LEVEL_FULL, T8_TEST_LEVEL_MEDIUM, or T8_TEST_LEVEL_BASIC)' default: 'T8_TEST_LEVEL_FULL' @@ -101,9 +119,7 @@ jobs: path: build/CMakeFiles/CMakeOutput.log - name: ninja run: cd build && ninja $MAKEFLAGS - - name: ninja install - run: cd build && ninja install $MAKEFLAGS # Execute script that runs a Valgrind check for all test binaries. - # We use 3 parallel processes to run the binaries in parallel with MPI. + # We use 4 parallel processes to run the binaries in parallel with MPI. - name: Valgrind check - run: cd scripts && bash ./check_all_test_binaries_valgrind.sh --ntasks=3 + run: cd scripts && bash ./check_all_test_binaries_valgrind.sh --ntasks=4 diff --git a/.github/workflows/testsuite.yml b/.github/workflows/testsuite.yml index 4c10076a54..b3ab042463 100644 --- a/.github/workflows/testsuite.yml +++ b/.github/workflows/testsuite.yml @@ -194,9 +194,6 @@ jobs: needs: preparation uses: ./.github/workflows/test_valgrind.yml with: - MAKEFLAGS: -j4 - MPI: ON - BUILD_TYPE: Debug TEST_LEVEL: T8_TEST_LEVEL_BASIC # Do Valgrind check for test level T8_TEST_LEVEL_BASIC for performance reasons. # Generate code coverage and deploy to Codecov. diff --git a/scripts/README.md b/scripts/README.md index 5f6633ac61..c573496467 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -51,7 +51,7 @@ The paths are relative paths assuming an execution from the test/ folder in the #### check_all_test_binaries_valgrind.sh This script performs a valgrind check on each test binary found by [find_all_test_binary_paths.sh](find_all_test_binary_paths.sh). -The valgrind check is done by [check_valgrind.sh](check_valgrind.sh). It is assumed that the build folder ../build/test/ with the correct test binaries exists. With `--ntasks=[NUMBER]`, you can provide the number of processes to use with mpi (default is 1). +The valgrind check is done by [check_valgrind.sh](check_valgrind.sh). It is assumed that the build folder ../build/test/ with the correct test binaries exists. With `--ntasks=[NUMBER]`, you can provide the number of processes to use with mpi for parallel tests (default is 1). ## Others diff --git a/scripts/check_all_test_binaries_valgrind.sh b/scripts/check_all_test_binaries_valgrind.sh index f0b39cffe2..c4f5796b30 100644 --- a/scripts/check_all_test_binaries_valgrind.sh +++ b/scripts/check_all_test_binaries_valgrind.sh @@ -26,12 +26,12 @@ # The script returns 1 if an error is found and 0 otherwise. # This script must be executed from the scripts/ folder. # It is assumed that the build folder ../build/test/ with the correct test binaries exists. -# With "--ntasks=[NUMBER]", you can provide the number of processes to use with MPI (default is 1). +# With "--ntasks=[NUMBER]", you can provide the number of processes to use with MPI for parallel tests (default is 1). # USAGE="\nUSAGE: This script executes valgrind in parallel on each test binary available. Use the syntax \n $0 --ntasks=[NUM_TASKS]\n -Providing the number of parallel processes to use with MPI is optional.\n" +Providing the number of parallel processes to use with MPI for parallel tests is optional.\n" # Check if a number of processes is provided. If not, set to 1. num_procs=1 @@ -79,16 +79,39 @@ status=0 counter=0 valgrind_suppressions_file=../../scripts/valgrind_suppressions_file.supp +# First run all serial tests in parallel. +serial_count=$(echo $test_bin_paths | tr ' ' '\n' | grep -c '_serial') +echo "Running valgrind checks on $serial_count serial test binaries in parallel..." for bin_path in $test_bin_paths; do - counter=$(( $counter + 1 )) - echo -n "[$counter/$num_paths] " - # Run check_valgrind script for each test binary. - bash ../../scripts/check_valgrind.sh $bin_path --supp=$valgrind_suppressions_file --ntasks=$num_procs 2>&1 - status=$? - # If status is not 0, an error occurred. - if test $status -ne 0; then - echo "Error occurred during the valgrind check of $bin_path." - exit 1 + if [[ $bin_path == *"_serial"* ]]; then + counter=$(( $counter + 1 )) + # Run check_valgrind script for each test binary. The & at the end allows parallel execution. + bash ../../scripts/check_valgrind.sh $bin_path --supp=$valgrind_suppressions_file --ntasks=1 2>&1 & + status=$? + # If status is not 0, an error occurred. + if test $status -ne 0; then + echo "Error occurred during the valgrind check of $bin_path." + kill $(jobs -p) + exit 1 + fi + fi +done +# Wait until all serial valgrind checks are done. +wait +echo "Valgrind found no errors in the ${counter} serial test executables." +echo "Check remaining parallel tests." +for bin_path in $test_bin_paths; do + if [[ $bin_path == *"_parallel"* ]]; then + counter=$(( $counter + 1 )) + echo -n "[$counter/$num_paths] " + # Run check_valgrind script for each test binary. + bash ../../scripts/check_valgrind.sh $bin_path --supp=$valgrind_suppressions_file --ntasks=$num_procs 2>&1 + status=$? + # If status is not 0, an error occurred. + if test $status -ne 0; then + echo "Error occurred during the valgrind check of $bin_path." + exit 1 + fi fi done diff --git a/scripts/check_valgrind.sh b/scripts/check_valgrind.sh index 8e96fe21c7..635bdfd34b 100644 --- a/scripts/check_valgrind.sh +++ b/scripts/check_valgrind.sh @@ -83,7 +83,7 @@ done echo "Valgrind check of ${FILE} using ${num_procs} processes..." # Write valgrind output to variable OUTPUT_FILE. -OUTPUT_FILE="valgrind-output.log" +OUTPUT_FILE="valgrind-output-$(basename "$FILE").log" # Set valgrind flags. VALGRIND_FLAGS="${VALGRIND_FLAGS} --leak-check=full --track-origins=yes \ --trace-children=yes --show-leak-kinds=definite,indirect,possible \