2 # SPDX-License-Identifier: GPL-2.0
4 # Test runner for nolibc tests
8 trap 'echo Aborting...' 'ERR'
10 crosstool_version
=13.2.0
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/)"
20 archs
="i386 x86_64 arm64 arm mips32le mips32be ppc ppc64 ppc64le riscv32 riscv64 s390 loongarch"
22 TEMP
=$
(getopt
-o 'j:d:c:b:a:m:pelh' -n "$0" -- "$@")
29 Run nolibc testsuite for multiple architectures with crosstools
32 $0 [options] <architectures>
38 -j [N] Allow N jobs at once (default: ${nproc})
39 -p Allow download of toolchains
40 -d [DIR] Download location for toolchains (default: ${download_location})
41 -c [VERSION] Version of toolchains to use (default: ${crosstool_version})
42 -a [ARCH] Host architecture of toolchains to use (default: ${hostarch})
43 -b [DIR] Build location (default: ${build_location})
44 -m [MODE] Test mode user/system (default: ${test_mode})
46 -l Build with LLVM/clang
59 download_location
="$2"
62 crosstool_version
="$2"
68 build_location
="$(realpath "$2")"
86 echo 'Internal error!' >&2; exit 1 ;;
90 if [[ -n "$*" ]]; then
98 ppc64
) echo powerpc64
;;
99 ppc64le
) echo powerpc64
;;
100 riscv
) echo riscv64
;;
101 loongarch
) echo loongarch64
;;
109 arm
) echo linux-gnueabi
;;
114 download_crosstool
() {
115 arch
="$(crosstool_arch "$1")"
116 abi
="$(crosstool_abi "$1")"
118 archive_name
="${hostarch}-gcc-${crosstool_version}-nolibc-${arch}-${abi}.tar.gz"
119 url
="https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/${hostarch}/${crosstool_version}/${archive_name}"
120 archive
="${download_location}${archive_name}"
121 stamp
="${archive}.stamp"
123 [ -f "${stamp}" ] && return
125 echo "Downloading crosstools ${arch} ${crosstool_version}"
126 mkdir
-p "${download_location}"
127 curl
-o "${archive}" --fail --continue-at - "${url}"
128 tar -C "${download_location}" -xf "${archive}"
132 # capture command output, print it on failure
133 # mimics chronic(1) from moreutils
134 function swallow_output
() {
135 if ! OUTPUT
="$("$@
" 2>&1)"; then
144 ct_arch
=$
(crosstool_arch
"$arch")
145 ct_abi
=$
(crosstool_abi
"$1")
147 if [ ! -d "${download_location}gcc-${crosstool_version}-nolibc/${ct_arch}-${ct_abi}/bin/." ]; then
148 echo "No toolchain found in ${download_location}gcc-${crosstool_version}-nolibc/${ct_arch}-${ct_abi}."
149 echo "Did you install the toolchains or set the correct arch ? Rerun with -h for help."
153 cross_compile
=$
(realpath
"${download_location}gcc-${crosstool_version}-nolibc/${ct_arch}-${ct_abi}/bin/${ct_arch}-${ct_abi}-")
154 build_dir
="${build_location}/${arch}"
155 if [ "$werror" -ne 0 ]; then
156 CFLAGS_EXTRA
="$CFLAGS_EXTRA -Werror"
158 MAKE
=(make -j"${nproc}" XARCH="${arch}" CROSS_COMPILE="${cross_compile}" LLVM="${llvm}" O="${build_dir}")
160 mkdir
-p "$build_dir"
161 if [ "$test_mode" = "system" ] && [ ! -f "${build_dir}/.config" ]; then
162 swallow_output
"${MAKE[@]}" defconfig
172 echo "Unknown mode $test_mode"
175 printf '%-15s' "$arch:"
176 swallow_output
"${MAKE[@]}" CFLAGS_EXTRA
="$CFLAGS_EXTRA" "$test_target" V
=1
177 cp run.out run.out.
"${arch}"
178 "${MAKE[@]}" report |
grep passed
181 if [ "$perform_download" -ne 0 ]; then
182 for arch
in $archs; do
183 download_crosstool
"$arch"
187 for arch
in $archs; do