util,tests: Added exit code to the compiler tests
[gem5.git] / util / compiler-tests.sh
1 #!/bin/bash
2
3 # This script will run all our supported compilers (see the "images" set)
4 # against gem5. The "ubuntu-20.04_all-dependencies" and "clang-version-9"
5 # images are run against all built targets. The remainder are evaluated
6 # against a random shuffling of built targets.
7
8 dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
9 gem5_root="${dir}/.."
10 build_dir="${gem5_root}/build"
11
12 # All Docker images in the gem5 testing GCR which we want to compile with.
13 images=("gcc-version-10"
14 "gcc-version-9"
15 "gcc-version-8"
16 "gcc-version-7"
17 "gcc-version-6"
18 "gcc-version-5"
19 "clang-version-9"
20 "clang-version-8"
21 "clang-version-7"
22 "clang-version-6.0"
23 "clang-version-5.0"
24 "clang-version-4.0"
25 "clang-version-3.9" )
26
27 # A subset of the above list: these images will build against every target,
28 # ignoring builds_per_compiler.
29 comprehensive=("gcc-version-10"
30 "clang-version-9")
31
32 # All build targets in build_opt/ which we want to build using each image.
33 builds=("ARM"
34 "ARM_MESI_Three_Level"
35 "Garnet_standalone"
36 "GCN3_X86"
37 "MIPS"
38 "NULL_MESI_Two_Level"
39 "NULL_MOESI_CMP_directory"
40 "NULL_MOESI_CMP_token"
41 "NULL_MOESI_hammer"
42 "POWER"
43 "RISCV"
44 "SPARC"
45 "X86"
46 "X86_MOESI_AMD_Base")
47
48 # The optimizations to use for each build target.
49 opts=(".opt"
50 ".fast")
51
52 # The number of build targets to randomly pull from the build target list for
53 # each compiler. To perform a full comprehensive test which covers every
54 # possible pair of compiler and build target, set builds_per_compiler equal to
55 # the expression ${#builds[@]}.
56 builds_per_compiler=1
57
58 # Base URL of the gem5 testing images.
59 base_url="gcr.io/gem5-test"
60
61 # Arguments passed into scons on every build target test.
62 build_args="$@"
63
64 # Testing directory variables
65 mkdir -p "${build_dir}" # Create the build directory if it doesn't exist.
66 test_dir_final="${gem5_root}/compile-test-out"
67 test_dir="${gem5_root}/.compile-test-out"
68 exits="${test_dir}/exit-codes.csv"
69
70 # Create the testing output directory and files
71 rm -rf "${test_dir_final}"
72 rm -rf "${test_dir}"
73 mkdir "${test_dir}"
74 touch "${exits}"
75 echo "compiler,build_target,exit_code" >> "${exits}"
76
77 exit_code=0 # We return a non-zero exit code if any of the compilations fail.
78
79 for compiler in ${images[@]}; do
80 echo "Starting build tests with '${compiler}'..."
81 # Generate a randomized list of build targets
82 build_permutation=($(shuf -i 0-$((${#builds[@]} - 1)) ))
83
84 builds_count=$builds_per_compiler
85 if [[ " ${comprehensive[@]} " =~ " $compiler " ]]; then
86 echo "'$compiler' was found in the comprehensive tests. All ISAs will be built."
87 builds_count=${#builds[@]}
88 fi
89
90 # Slice the first $builds_count entries of the permutation to get our
91 # targets for this test
92 build_indices=(${build_permutation[@]:0:$builds_count})
93
94 repo_name="${base_url}/${compiler}:latest"
95
96 # Grab compiler image
97 docker pull $repo_name >/dev/null
98
99 mkdir "${test_dir}/${compiler}"
100
101 for build_index in ${build_indices[@]}; do
102 for build_opt in ${opts[@]}; do
103 build="${builds[$build_index]}"
104 build_out="build/$build/gem5$build_opt"
105 build_stdout="${test_dir}/${compiler}/${build}${build_opt}.stdout"
106 build_stderr="${test_dir}/${compiler}/${build}${build_opt}.stderr"
107
108 # Clean the build
109 rm -rf "${build_dir}"
110
111 touch "${build_stdout}"
112 touch "${build_stderr}"
113
114 echo " * Building target '${build}${build_opt}' with '${compiler}'..."
115
116 # Build with container
117 {
118 docker run --rm -v "${gem5_root}":"/gem5" -u $UID:$GID \
119 -w /gem5 $repo_name scons "${build_out}" "${build_args}"
120 }>"${build_stdout}" 2>"${build_stderr}"
121 result=$?
122
123 echo "${compiler},${build}/gem5${build_opt},${result}" >>"${exits}"
124
125 if [ ${result} -ne 0 ]; then
126 exit_code=1
127 echo " ! Failed with exit code ${result}."
128 else
129 echo " Done."
130 fi
131 done
132 done
133 done
134
135 mv "${test_dir}" "${test_dir_final}"
136
137 exit ${exit_code}