Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/scripts/check_all_test_binaries_valgrind.sh
901 views
1
#!/bin/bash
2
3
# This file is part of t8code.
4
# t8code is a C library to manage a collection (a forest) of multiple
5
# connected adaptive space-trees of general element classes in parallel.
6
#
7
# Copyright (C) 2025 the developers
8
#
9
# t8code is free software; you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation; either version 2 of the License, or
12
# (at your option) any later version.
13
#
14
# t8code is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
18
#
19
# You should have received a copy of the GNU General Public License
20
# along with t8code; if not, write to the Free Software Foundation, Inc.,
21
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23
#
24
# This script performs a valgrind check on each test binary given by find_all_test_binary_paths.sh.
25
# The valgrind check is done by the check_valgrind.sh script.
26
# The script returns 1 if an error is found and 0 otherwise.
27
# This script must be executed from the scripts/ folder.
28
# It is assumed that the build folder ../build/test/ with the correct test binaries exists.
29
# With "--ntasks=[NUMBER]", you can provide the number of processes to use with MPI for parallel tests (default is 1).
30
#
31
32
USAGE="\nUSAGE: This script executes valgrind in parallel on each test binary available. Use the syntax \n
33
$0 --ntasks=[NUM_TASKS]\n
34
Providing the number of parallel processes to use with MPI for parallel tests is optional.\n"
35
36
# Check if a number of processes is provided. If not, set to 1.
37
num_procs=1
38
for arg in "$@"; do
39
if [[ "$arg" == --ntasks=* ]]; then
40
ntasks_val="${arg#--ntasks=}"
41
if [[ "$ntasks_val" =~ ^[0-9]+$ ]]; then
42
num_procs="$ntasks_val"
43
else
44
echo "ERROR: --ntasks value '$ntasks_val' is not a valid number."
45
echo -e "$USAGE"
46
exit 1
47
fi
48
fi
49
done
50
51
# Script must be executed from the scripts/ folder.
52
if [ `basename $PWD` != scripts ]; then
53
if [ -d scripts ]; then
54
# The directory stack is automatically reset on script exit.
55
pushd scripts/ > /dev/null
56
else
57
echo "ERROR: scripts/ directory not found."
58
echo -e "$USAGE"
59
exit 1
60
fi
61
fi
62
63
# Find all test binary paths.
64
test_bin_paths=`bash ./find_all_test_binary_paths.sh`
65
num_paths=$(echo $test_bin_paths | wc -w)
66
67
# This is necessary because some tests use test files specified by relative paths.
68
# These tests only work when run from the build/test/ directory.
69
if [ -d ../build/test ]; then
70
# The directory stack is automatically reset on script exit.
71
pushd ../build/test/ > /dev/null
72
else
73
echo "ERROR: Couldn't find a the directory ../build/test/."
74
echo -e "$USAGE"
75
exit 1
76
fi
77
78
status=0
79
counter=0
80
valgrind_suppressions_file=../../scripts/valgrind_suppressions_file.supp
81
82
# First run all serial tests in parallel.
83
serial_count=$(echo $test_bin_paths | tr ' ' '\n' | grep -c '_serial')
84
echo "Running valgrind checks on $serial_count serial test binaries in parallel..."
85
for bin_path in $test_bin_paths; do
86
if [[ $bin_path == *"_serial"* ]]; then
87
counter=$(( $counter + 1 ))
88
# Run check_valgrind script for each test binary. The & at the end allows parallel execution.
89
bash ../../scripts/check_valgrind.sh $bin_path --supp=$valgrind_suppressions_file --ntasks=1 2>&1 &
90
status=$?
91
# If status is not 0, an error occurred.
92
if test $status -ne 0; then
93
echo "Error occurred during the valgrind check of $bin_path."
94
kill $(jobs -p)
95
exit 1
96
fi
97
fi
98
done
99
# Wait until all serial valgrind checks are done.
100
wait
101
echo "Valgrind found no errors in the ${counter} serial test executables."
102
echo "Check remaining parallel tests."
103
for bin_path in $test_bin_paths; do
104
if [[ $bin_path == *"_parallel"* ]]; then
105
counter=$(( $counter + 1 ))
106
echo -n "[$counter/$num_paths] "
107
# Run check_valgrind script for each test binary.
108
bash ../../scripts/check_valgrind.sh $bin_path --supp=$valgrind_suppressions_file --ntasks=$num_procs 2>&1
109
status=$?
110
# If status is not 0, an error occurred.
111
if test $status -ne 0; then
112
echo "Error occurred during the valgrind check of $bin_path."
113
exit 1
114
fi
115
fi
116
done
117
118
echo "Valgrind found no errors in the test executables."
119
exit 0
120