summaryrefslogtreecommitdiff
path: root/gdb/testsuite/make-check-all.sh
blob: 7d8adb58e878ac65a3c3e8c758e3bf89dde5a1ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/bin/bash

# Copyright (C) 2023 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Run make check with all boards from gdb/testsuite/boards.

# It is recommended to create users on the local system that will act as
#  "remote host" and "remote target", for the boards that use them.
#  Pass their usernames to --host-user and --target-user.  This helps
#  because:
#
#    - remote host/target boards will use $HOME and leave (potentially
#      lots of) files behind,
#    - it enables more strict checking of build/host/target file
#      manipulations,
#    - it prevents a command running on one "machine" to kill or send a
#      signal to a process on another machine.
#
# Recommended usage example:
#
# bash$ cd $objdir/gdb/testsuite
# bash$ $srcdir/testsuite/gdb/make-check-all.sh \
#           --host-user remote-host \
#           --target-user remote-target \
#           gdb.base/advance.exp

set -e

# Boards that run the host tools (compiler, gdb) on a remote host.
remote_host_boards=(
    local-remote-host
    local-remote-host-notty
)

# Boards that use gdbserver to launch target executables on local target.
gdbserver_boards=(
    native-extended-gdbserver
    native-gdbserver
    native-stdio-gdbserver
)

# Boards that use gdbserver to launch target executables on a remote target.
remote_gdbserver_boards=(
    remote-gdbserver-on-localhost
    remote-stdio-gdbserver
)

# Boards that run compiler, gdb and target executables on a remote machine
# that serves both as host and target.
host_target_boards=(
    local-remote-host-native
)

# Boards that run everything on local target and local host.
target_boards=(
    cc-with-gdb-index
    cc-with-debug-names
    cc-with-dwz
    cc-with-dwz-m
    cc-with-gnu-debuglink
    debug-types
    dwarf4-gdb-index
    dwarf64
    fission
    fission-dwp
    gold
    gold-gdb-index
    readnow
    stabs
)

# Get RUNTESTFLAGS needed for specific boards.
rtf_for_board ()
{
    local b
    b="$1"

    case $b in
	local-remote-host-native)
	    mkdir -p "$tmpdir/$b"
	    rtf=(
		"${rtf[@]}"
		"HOST_DIR=$tmpdir/$b"
	    )
	    ;;
	remote-stdio-gdbserver)
	    rtf=(
		"${rtf[@]}"
		"REMOTE_HOSTNAME=localhost"
	    )
	    if [ "$target_user" != "" ]; then
		rtf=(
		    "${rtf[@]}"
		    "REMOTE_USERNAME=$target_user"
		)
	    else
		rtf=(
		    "${rtf[@]}"
		    "REMOTE_USERNAME=$USER"
		)
	    fi
	    ;;
	remote-gdbserver-on-localhost)
	    if [ "$target_user" != "" ]; then
		rtf=(
		    "${rtf[@]}"
		    "REMOTE_TARGET_USERNAME=$target_user"
		)
	    fi
	    ;;
	local-remote-host|local-remote-host-notty)
	    if [ "$host_user" != "" ]; then
		rtf=(
		    "${rtf[@]}"
		    "REMOTE_HOST_USERNAME=$host_user"
		)
	    else
		rtf=(
		    "${rtf[@]}"
		    "REMOTE_HOST_USERNAME=$USER"
		)
	    fi
	    ;;
	*)
	    ;;
    esac
}

# Summarize make check output.
summary ()
{
    if $verbose; then
	cat
    else
	# We need the sort -u, because some items, for instance "# of expected
	# passes" are output twice.
	grep -E "^(#|FAIL:|ERROR:|WARNING:)" \
	    | sort -u
    fi
}

# Run make check, and possibly save test results.
do_tests ()
{
    if $debug; then
	echo "RTF: ${rtf[*]}"
    fi

    if $dry_run; then
	return
    fi

    # Run make check.
    make check \
	 RUNTESTFLAGS="${rtf[*]} ${tests[*]}" \
	 2>&1 \
	| summary

    # Save test results.
    if $keep_results; then
	# Set cfg to identifier unique to host/target board combination.
	if [ "$h" = "" ]; then
	    if [ "$b" = "" ]; then
		cfg=local
	    else
		cfg=$b
	    fi
	else
	    cfg=$h-$b
	fi

	local dir
	dir="check-all/$cfg"

	mkdir -p "$dir"
	cp gdb.sum gdb.log "$dir"
    fi
}

# Set default values for global vars and modify according to command line
# arguments.
parse_args ()
{
    # Default values.
    debug=false
    keep_results=false
    keep_tmp=false
    verbose=false
    dry_run=false

    host_user=""
    target_user=""

    # Parse command line arguments.
    while [ $# -gt 0 ]; do
	case "$1" in
	    --debug)
		debug=true
		;;
	    --keep-results)
		keep_results=true
		;;
	    --keep-tmp)
		keep_tmp=true
		;;
	    --verbose)
		verbose=true
		;;
	    --dry-run)
		dry_run=true
		;;
	    --host-user)
		shift
		host_user="$1"
		;;
	    --target-user)
		shift
		target_user="$1"
		;;
	    *)
		break
		;;
	esac
	shift
    done

    tests=("$@")
}

# Cleanup function, scheduled to run on exit.
cleanup ()
{
    if [ "$tmpdir" != "" ]; then
	if $keep_tmp; then
	    echo "keeping tmp dir $tmpdir"
	else
	    rm -Rf "$tmpdir"
	fi
    fi
}

# Top-level function, called with command line arguments of the script.
main ()
{
    # Parse command line arguments.
    parse_args "$@"

    # Create tmpdir and schedule cleanup.
    tmpdir=""
    trap cleanup EXIT
    tmpdir=$(mktemp -d)

    if $debug; then
	echo "TESTS: ${tests[*]}"
    fi

    # Variables that point to current host (h) and target board (b) when
    # executing do_tests.
    h=""
    b=""

    # For reference, run the tests without any explicit host or target board.
    echo "LOCAL:"
    rtf=()
    do_tests

    # Run the boards for local host and local target.
    for b in "${target_boards[@]}"; do
	echo "TARGET BOARD: $b"
	rtf=(
	    --target_board="$b"
	)
	rtf_for_board "$b"
	do_tests
    done

    # Run the boards that use gdbserver, for local host, and for both local and
    # remote target.
    for b in "${gdbserver_boards[@]}" "${remote_gdbserver_boards[@]}"; do
	echo "TARGET BOARD: $b"
	rtf=(
	    --target_board="$b"
	)
	rtf_for_board "$b"
	do_tests
    done

    # Run the boards that use remote host, in combination with boards that use
    # gdbserver on remote target.
    for h in "${remote_host_boards[@]}"; do
	for b in "${remote_gdbserver_boards[@]}"; do
	    echo "HOST BOARD: $h, TARGET BOARD: $b"
	    rtf=(
		--host_board="$h"
		--target_board="$b"
	    )
	    rtf_for_board "$h"
	    rtf_for_board "$b"
	    do_tests
	done
    done
    h=""

    # Run the boards that function as both remote host and remote target.
    for b in "${host_target_boards[@]}"; do
	echo "HOST/TARGET BOARD: $b"
	rtf=(
	    --host_board="$b"
	    --target_board="$b"
	)
	rtf_for_board "$b"
	do_tests
    done
}

# Call top-level function with command line arguments.
main "$@"