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