util: Add a unit test for the m5 utility's "readfile" command.
[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 num_cores=`nproc`
12
13 # All Docker images in the gem5 testing GCR which we want to compile with.
14 images=("gcc-version-10"
15 "gcc-version-9"
16 "gcc-version-8"
17 "gcc-version-7"
18 "gcc-version-6"
19 "gcc-version-5"
20 "gcc-version-4.8"
21 "clang-version-9"
22 "clang-version-8"
23 "clang-version-7"
24 "clang-version-6.0"
25 "clang-version-5.0"
26 "clang-version-4.0"
27 "clang-version-3.9" )
28
29 # A subset of the above list: these images will build against every target,
30 # ignoring builds_per_compiler.
31 comprehensive=("gcc-version-10"
32 "clang-version-9")
33
34 # All build targets in build_opt/ which we want to build using each image.
35 builds=("ARM"
36 "ARM_MESI_Three_Level"
37 "Garnet_standalone"
38 "GCN3_X86"
39 "MIPS"
40 "NULL_MESI_Two_Level"
41 "NULL_MOESI_CMP_directory"
42 "NULL_MOESI_CMP_token"
43 "NULL_MOESI_hammer"
44 "POWER"
45 "RISCV"
46 "SPARC"
47 "X86"
48 "X86_MOESI_AMD_Base")
49
50 # The optimizations to use for each build target.
51 opts=(".opt"
52 ".fast")
53
54 # The number of build targets to randomly pull from the build target list for
55 # each compiler. To perform a full comprehensive test which covers every
56 # possible pair of compiler and build target, set builds_per_compiler equal to
57 # the expression ${#builds[@]}.
58 builds_per_compiler=1
59
60 # Base URL of the gem5 testing images.
61 base_url="gcr.io/gem5-test"
62
63 # Arguments passed into scons on every build target test.
64 build_args="-j ${num_cores}"
65
66 # Testing directory variables
67 mkdir -p "${build_dir}" # Create the build directory if it doesn't exist.
68 test_dir_final="${gem5_root}/compile-test-out"
69 test_dir="${gem5_root}/.compile-test-out"
70 exits="${test_dir}/exit-codes.csv"
71
72 # Create the testing output directory and files
73 rm -rf "${test_dir_final}"
74 rm -rf "${test_dir}"
75 mkdir "${test_dir}"
76 touch "${exits}"
77 echo "compiler,build_target,exit_code" >> "${exits}"
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 echo " ! Failed with exit code ${result}."
127 else
128 echo " Done."
129 fi
130 done
131 done
132 done
133
134 mv "${test_dir}" "${test_dir_final}"