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