]> Git Repo - J-linux.git/blob - tools/testing/selftests/nolibc/run-tests.sh
Merge tag 'kbuild-v6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy...
[J-linux.git] / tools / testing / selftests / nolibc / run-tests.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3
4 # Test runner for nolibc tests
5
6 set -e
7
8 trap 'echo Aborting...' 'ERR'
9
10 crosstool_version=13.2.0
11 hostarch=x86_64
12 nproc=$(( $(nproc) + 2))
13 cache_dir="${XDG_CACHE_HOME:-"$HOME"/.cache}"
14 download_location="${cache_dir}/crosstools/"
15 build_location="$(realpath "${cache_dir}"/nolibc-tests/)"
16 perform_download=0
17 test_mode=system
18 archs="i386 x86_64 arm64 arm mips32le mips32be ppc ppc64 ppc64le riscv s390 loongarch"
19
20 TEMP=$(getopt -o 'j:d:c:b:a:m:ph' -n "$0" -- "$@")
21
22 eval set -- "$TEMP"
23 unset TEMP
24
25 print_usage() {
26         cat <<EOF
27 Run nolibc testsuite for multiple architectures with crosstools
28
29 Usage:
30  $0 [options] <architectures>
31
32 Known architectures:
33  ${archs}
34
35 Options:
36  -j [N]         Allow N jobs at once (default: ${nproc})
37  -p             Allow download of toolchains
38  -d [DIR]       Download location for toolchains (default: ${download_location})
39  -c [VERSION]   Version of toolchains to use (default: ${crosstool_version})
40  -a [ARCH]      Host architecture of toolchains to use (default: ${hostarch})
41  -b [DIR]       Build location (default: ${build_location})
42  -m [MODE]      Test mode user/system (default: ${test_mode})
43 EOF
44 }
45
46 while true; do
47         case "$1" in
48                 '-j')
49                         nproc="$2"
50                         shift 2; continue ;;
51                 '-p')
52                         perform_download=1
53                         shift; continue ;;
54                 '-d')
55                         download_location="$2"
56                         shift 2; continue ;;
57                 '-c')
58                         crosstool_version="$2"
59                         shift 2; continue ;;
60                 '-a')
61                         hostarch="$2"
62                         shift 2; continue ;;
63                 '-b')
64                         build_location="$(realpath "$2")"
65                         shift 2; continue ;;
66                 '-m')
67                         test_mode="$2"
68                         shift 2; continue ;;
69                 '-h')
70                         print_usage
71                         exit 0
72                         ;;
73                 '--')
74                         shift; break ;;
75                 *)
76                         echo 'Internal error!' >&2; exit 1 ;;
77         esac
78 done
79
80 if [[ -n "$*" ]]; then
81         archs="$*"
82 fi
83
84 crosstool_arch() {
85         case "$1" in
86         arm64) echo aarch64;;
87         ppc) echo powerpc;;
88         ppc64) echo powerpc64;;
89         ppc64le) echo powerpc64;;
90         riscv) echo riscv64;;
91         loongarch) echo loongarch64;;
92         mips*) echo mips;;
93         *) echo "$1";;
94         esac
95 }
96
97 crosstool_abi() {
98         case "$1" in
99         arm) echo linux-gnueabi;;
100         *) echo linux;;
101         esac
102 }
103
104 download_crosstool() {
105         arch="$(crosstool_arch "$1")"
106         abi="$(crosstool_abi "$1")"
107
108         archive_name="${hostarch}-gcc-${crosstool_version}-nolibc-${arch}-${abi}.tar.gz"
109         url="https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/${hostarch}/${crosstool_version}/${archive_name}"
110         archive="${download_location}${archive_name}"
111         stamp="${archive}.stamp"
112
113         [ -f "${stamp}" ] && return
114
115         echo "Downloading crosstools ${arch} ${crosstool_version}"
116         mkdir -p "${download_location}"
117         curl -o "${archive}" --fail --continue-at - "${url}"
118         tar -C "${download_location}" -xf "${archive}"
119         touch "${stamp}"
120 }
121
122 # capture command output, print it on failure
123 # mimics chronic(1) from moreutils
124 function swallow_output() {
125         if ! OUTPUT="$("$@" 2>&1)"; then
126                 echo "$OUTPUT"
127                 return 1
128         fi
129         return 0
130 }
131
132 test_arch() {
133         arch=$1
134         ct_arch=$(crosstool_arch "$arch")
135         ct_abi=$(crosstool_abi "$1")
136         cross_compile=$(realpath "${download_location}gcc-${crosstool_version}-nolibc/${ct_arch}-${ct_abi}/bin/${ct_arch}-${ct_abi}-")
137         build_dir="${build_location}/${arch}"
138         MAKE=(make -j"${nproc}" XARCH="${arch}" CROSS_COMPILE="${cross_compile}" O="${build_dir}")
139
140         mkdir -p "$build_dir"
141         if [ "$test_mode" = "system" ] && [ ! -f "${build_dir}/.config" ]; then
142                 swallow_output "${MAKE[@]}" defconfig
143         fi
144         case "$test_mode" in
145                 'system')
146                         test_target=run
147                         ;;
148                 'user')
149                         test_target=run-user
150                         ;;
151                 *)
152                         echo "Unknown mode $test_mode"
153                         exit 1
154         esac
155         printf '%-15s' "$arch:"
156         swallow_output "${MAKE[@]}" "$test_target" V=1
157         cp run.out run.out."${arch}"
158         "${MAKE[@]}" report | grep passed
159 }
160
161 if [ "$perform_download" -ne 0 ]; then
162         for arch in $archs; do
163                 download_crosstool "$arch"
164         done
165 fi
166
167 for arch in $archs; do
168         test_arch "$arch"
169 done
This page took 0.037789 seconds and 4 git commands to generate.