Path: blob/main/scripts/check_all_test_binaries_valgrind.sh
901 views
#!/bin/bash12# This file is part of t8code.3# t8code is a C library to manage a collection (a forest) of multiple4# connected adaptive space-trees of general element classes in parallel.5#6# Copyright (C) 2025 the developers7#8# t8code is free software; you can redistribute it and/or modify9# it under the terms of the GNU General Public License as published by10# the Free Software Foundation; either version 2 of the License, or11# (at your option) any later version.12#13# t8code is distributed in the hope that it will be useful,14# but WITHOUT ANY WARRANTY; without even the implied warranty of15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16# GNU General Public License for more details.17#18# You should have received a copy of the GNU General Public License19# along with t8code; if not, write to the Free Software Foundation, Inc.,20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.2122#23# This script performs a valgrind check on each test binary given by find_all_test_binary_paths.sh.24# The valgrind check is done by the check_valgrind.sh script.25# The script returns 1 if an error is found and 0 otherwise.26# This script must be executed from the scripts/ folder.27# It is assumed that the build folder ../build/test/ with the correct test binaries exists.28# With "--ntasks=[NUMBER]", you can provide the number of processes to use with MPI for parallel tests (default is 1).29#3031USAGE="\nUSAGE: This script executes valgrind in parallel on each test binary available. Use the syntax \n32$0 --ntasks=[NUM_TASKS]\n33Providing the number of parallel processes to use with MPI for parallel tests is optional.\n"3435# Check if a number of processes is provided. If not, set to 1.36num_procs=137for arg in "$@"; do38if [[ "$arg" == --ntasks=* ]]; then39ntasks_val="${arg#--ntasks=}"40if [[ "$ntasks_val" =~ ^[0-9]+$ ]]; then41num_procs="$ntasks_val"42else43echo "ERROR: --ntasks value '$ntasks_val' is not a valid number."44echo -e "$USAGE"45exit 146fi47fi48done4950# Script must be executed from the scripts/ folder.51if [ `basename $PWD` != scripts ]; then52if [ -d scripts ]; then53# The directory stack is automatically reset on script exit.54pushd scripts/ > /dev/null55else56echo "ERROR: scripts/ directory not found."57echo -e "$USAGE"58exit 159fi60fi6162# Find all test binary paths.63test_bin_paths=`bash ./find_all_test_binary_paths.sh`64num_paths=$(echo $test_bin_paths | wc -w)6566# This is necessary because some tests use test files specified by relative paths.67# These tests only work when run from the build/test/ directory.68if [ -d ../build/test ]; then69# The directory stack is automatically reset on script exit.70pushd ../build/test/ > /dev/null71else72echo "ERROR: Couldn't find a the directory ../build/test/."73echo -e "$USAGE"74exit 175fi7677status=078counter=079valgrind_suppressions_file=../../scripts/valgrind_suppressions_file.supp8081# First run all serial tests in parallel.82serial_count=$(echo $test_bin_paths | tr ' ' '\n' | grep -c '_serial')83echo "Running valgrind checks on $serial_count serial test binaries in parallel..."84for bin_path in $test_bin_paths; do85if [[ $bin_path == *"_serial"* ]]; then86counter=$(( $counter + 1 ))87# Run check_valgrind script for each test binary. The & at the end allows parallel execution.88bash ../../scripts/check_valgrind.sh $bin_path --supp=$valgrind_suppressions_file --ntasks=1 2>&1 &89status=$?90# If status is not 0, an error occurred.91if test $status -ne 0; then92echo "Error occurred during the valgrind check of $bin_path."93kill $(jobs -p)94exit 195fi96fi97done98# Wait until all serial valgrind checks are done.99wait100echo "Valgrind found no errors in the ${counter} serial test executables."101echo "Check remaining parallel tests."102for bin_path in $test_bin_paths; do103if [[ $bin_path == *"_parallel"* ]]; then104counter=$(( $counter + 1 ))105echo -n "[$counter/$num_paths] "106# Run check_valgrind script for each test binary.107bash ../../scripts/check_valgrind.sh $bin_path --supp=$valgrind_suppressions_file --ntasks=$num_procs 2>&1108status=$?109# If status is not 0, an error occurred.110if test $status -ne 0; then111echo "Error occurred during the valgrind check of $bin_path."112exit 1113fi114fi115done116117echo "Valgrind found no errors in the test executables."118exit 0119120