]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_gcc/test.sh
Merge commit 'e8dca3e87d164d2806098c462c6ce41301341f68' into sync_from_cg_gcc
[rust.git] / compiler / rustc_codegen_gcc / test.sh
1 #!/usr/bin/env bash
2
3 # TODO(antoyo): rewrite to cargo-make (or just) or something like that to only rebuild the sysroot when needed?
4
5 set -e
6
7 if [ -f ./gcc_path ]; then
8     export GCC_PATH=$(cat gcc_path)
9 else
10     echo 'Please put the path to your custom build of libgccjit in the file `gcc_path`, see Readme.md for details'
11     exit 1
12 fi
13
14 export LD_LIBRARY_PATH="$GCC_PATH"
15 export LIBRARY_PATH="$GCC_PATH"
16
17 flags=
18 gcc_master_branch=1
19 channel="debug"
20 func=all
21 build_only=0
22
23 while [[ $# -gt 0 ]]; do
24     case $1 in
25         --release)
26             codegen_channel=release
27             shift
28             ;;
29         --release-sysroot)
30             sysroot_channel=release
31             shift
32             ;;
33         --no-default-features)
34             gcc_master_branch=0
35             flags="$flags --no-default-features"
36             shift
37             ;;
38         --features)
39             shift
40             flags="$flags --features $1"
41             shift
42             ;;
43         --release)
44             channel="release"
45             shift
46             ;;
47         "--test-rustc")
48             func=test_rustc
49             shift
50             ;;
51
52         "--test-libcore")
53             func=test_libcore
54             shift
55             ;;
56
57         "--clean-ui-tests")
58             func=clean_ui_tests
59             shift
60             ;;
61
62         "--std-tests")
63             func=std_tests
64             shift
65             ;;
66
67         "--extended-tests")
68             func=extended_sysroot_tests
69             shift
70             ;;
71
72         "--build-sysroot")
73             func=build_sysroot
74             shift
75             ;;
76         "--build")
77             build_only=1
78             shift
79             ;;
80         *)
81             echo "Unknown option $1"
82             exit 1
83             ;;
84     esac
85 done
86
87 if [[ $channel == "release" ]]; then
88     export CHANNEL='release'
89     CARGO_INCREMENTAL=1 cargo rustc --release $flags
90     shift
91 else
92     echo $LD_LIBRARY_PATH
93     export CHANNEL='debug'
94     cargo rustc $flags
95 fi
96
97 if (( $build_only == 1 )); then
98     exit
99 fi
100
101 source config.sh
102
103 function clean() {
104     rm -r target/out || true
105     mkdir -p target/out/gccjit
106 }
107
108 function mini_tests() {
109     echo "[BUILD] mini_core"
110     $RUSTC example/mini_core.rs --crate-name mini_core --crate-type lib,dylib --target $TARGET_TRIPLE
111
112     echo "[BUILD] example"
113     $RUSTC example/example.rs --crate-type lib --target $TARGET_TRIPLE
114
115     echo "[AOT] mini_core_hello_world"
116     $RUSTC example/mini_core_hello_world.rs --crate-name mini_core_hello_world --crate-type bin -g --target $TARGET_TRIPLE
117     $RUN_WRAPPER ./target/out/mini_core_hello_world abc bcd
118 }
119
120 function build_sysroot() {
121     echo "[BUILD] sysroot"
122     time ./build_sysroot/build_sysroot.sh
123 }
124
125 function std_tests() {
126     echo "[AOT] arbitrary_self_types_pointers_and_wrappers"
127     $RUSTC example/arbitrary_self_types_pointers_and_wrappers.rs --crate-name arbitrary_self_types_pointers_and_wrappers --crate-type bin --target $TARGET_TRIPLE
128     $RUN_WRAPPER ./target/out/arbitrary_self_types_pointers_and_wrappers
129
130     echo "[AOT] alloc_system"
131     $RUSTC example/alloc_system.rs --crate-type lib --target "$TARGET_TRIPLE"
132
133     echo "[AOT] alloc_example"
134     $RUSTC example/alloc_example.rs --crate-type bin --target $TARGET_TRIPLE
135     $RUN_WRAPPER ./target/out/alloc_example
136
137     echo "[AOT] dst_field_align"
138     # FIXME(antoyo): Re-add -Zmir-opt-level=2 once rust-lang/rust#67529 is fixed.
139     $RUSTC example/dst-field-align.rs --crate-name dst_field_align --crate-type bin --target $TARGET_TRIPLE
140     $RUN_WRAPPER ./target/out/dst_field_align || (echo $?; false)
141
142     echo "[AOT] std_example"
143     std_flags="--cfg feature=\"master\""
144     if (( $gcc_master_branch == 0 )); then
145         std_flags=""
146     fi
147     $RUSTC example/std_example.rs --crate-type bin --target $TARGET_TRIPLE $std_flags
148     $RUN_WRAPPER ./target/out/std_example --target $TARGET_TRIPLE
149
150     echo "[AOT] subslice-patterns-const-eval"
151     $RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target $TARGET_TRIPLE
152     $RUN_WRAPPER ./target/out/subslice-patterns-const-eval
153
154     echo "[AOT] track-caller-attribute"
155     $RUSTC example/track-caller-attribute.rs --crate-type bin -Cpanic=abort --target $TARGET_TRIPLE
156     $RUN_WRAPPER ./target/out/track-caller-attribute
157
158     echo "[BUILD] mod_bench"
159     $RUSTC example/mod_bench.rs --crate-type bin --target $TARGET_TRIPLE
160 }
161
162 # FIXME(antoyo): linker gives multiple definitions error on Linux
163 #echo "[BUILD] sysroot in release mode"
164 #./build_sysroot/build_sysroot.sh --release
165
166 function test_libcore() {
167     pushd build_sysroot/sysroot_src/library/core/tests
168     echo "[TEST] libcore"
169     rm -r ./target || true
170     ../../../../../cargo.sh test
171     popd
172 }
173
174 #echo
175 #echo "[BENCH COMPILE] mod_bench"
176
177 #COMPILE_MOD_BENCH_INLINE="$RUSTC example/mod_bench.rs --crate-type bin -Zmir-opt-level=3 -O --crate-name mod_bench_inline"
178 #COMPILE_MOD_BENCH_LLVM_0="rustc example/mod_bench.rs --crate-type bin -Copt-level=0 -o target/out/mod_bench_llvm_0 -Cpanic=abort"
179 #COMPILE_MOD_BENCH_LLVM_1="rustc example/mod_bench.rs --crate-type bin -Copt-level=1 -o target/out/mod_bench_llvm_1 -Cpanic=abort"
180 #COMPILE_MOD_BENCH_LLVM_2="rustc example/mod_bench.rs --crate-type bin -Copt-level=2 -o target/out/mod_bench_llvm_2 -Cpanic=abort"
181 #COMPILE_MOD_BENCH_LLVM_3="rustc example/mod_bench.rs --crate-type bin -Copt-level=3 -o target/out/mod_bench_llvm_3 -Cpanic=abort"
182
183 ## Use 100 runs, because a single compilations doesn't take more than ~150ms, so it isn't very slow
184 #hyperfine --runs ${COMPILE_RUNS:-100} "$COMPILE_MOD_BENCH_INLINE" "$COMPILE_MOD_BENCH_LLVM_0" "$COMPILE_MOD_BENCH_LLVM_1" "$COMPILE_MOD_BENCH_LLVM_2" "$COMPILE_MOD_BENCH_LLVM_3"
185
186 #echo
187 #echo "[BENCH RUN] mod_bench"
188 #hyperfine --runs ${RUN_RUNS:-10} ./target/out/mod_bench{,_inline} ./target/out/mod_bench_llvm_*
189
190 function extended_sysroot_tests() {
191     if (( $gcc_master_branch == 0 )); then
192         return
193     fi
194
195     pushd rand
196     cargo clean
197     echo "[TEST] rust-random/rand"
198     ../cargo.sh test --workspace
199     popd
200
201     #pushd simple-raytracer
202     #echo "[BENCH COMPILE] ebobby/simple-raytracer"
203     #hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "cargo clean" \
204     #"RUSTC=rustc RUSTFLAGS='' cargo build" \
205     #"../cargo.sh build"
206
207     #echo "[BENCH RUN] ebobby/simple-raytracer"
208     #cp ./target/debug/main ./raytracer_cg_gcc
209     #hyperfine --runs "${RUN_RUNS:-10}" ./raytracer_cg_llvm ./raytracer_cg_gcc
210     #popd
211
212     pushd regex
213     echo "[TEST] rust-lang/regex example shootout-regex-dna"
214     cargo clean
215     export CG_RUSTFLAGS="--cap-lints warn" # newer aho_corasick versions throw a deprecation warning
216     # Make sure `[codegen mono items] start` doesn't poison the diff
217     ../cargo.sh build --example shootout-regex-dna
218     cat examples/regexdna-input.txt \
219         | ../cargo.sh run --example shootout-regex-dna \
220         | grep -v "Spawned thread" > res.txt
221     diff -u res.txt examples/regexdna-output.txt
222
223     echo "[TEST] rust-lang/regex tests"
224     ../cargo.sh test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q
225     popd
226 }
227
228 function test_rustc() {
229     echo
230     echo "[TEST] rust-lang/rust"
231
232     rust_toolchain=$(cat rust-toolchain | grep channel | sed 's/channel = "\(.*\)"/\1/')
233
234     git clone https://github.com/rust-lang/rust.git || true
235     cd rust
236     git fetch
237     git checkout $(rustc -V | cut -d' ' -f3 | tr -d '(')
238     export RUSTFLAGS=
239
240     git apply ../rustc_patches/compile_test.patch || true
241
242     rm config.toml || true
243
244     cat > config.toml <<EOF
245 [rust]
246 codegen-backends = []
247 deny-warnings = false
248
249 [build]
250 cargo = "$(which cargo)"
251 local-rebuild = true
252 rustc = "$HOME/.rustup/toolchains/$rust_toolchain-$TARGET_TRIPLE/bin/rustc"
253 EOF
254
255     rustc -V | cut -d' ' -f3 | tr -d '('
256     git checkout $(rustc -V | cut -d' ' -f3 | tr -d '(') src/test
257
258     for test in $(rg -i --files-with-matches "//(\[\w+\])?~|// error-pattern:|// build-fail|// run-fail|-Cllvm-args" src/test/ui); do
259       rm $test
260     done
261
262     git checkout -- src/test/ui/issues/auxiliary/issue-3136-a.rs # contains //~ERROR, but shouldn't be removed
263
264     rm -r src/test/ui/{abi*,extern/,panic-runtime/,panics/,unsized-locals/,proc-macro/,threads-sendsync/,thinlto/,borrowck/,test*,*lto*.rs} || true
265     for test in $(rg --files-with-matches "catch_unwind|should_panic|thread|lto" src/test/ui); do
266       rm $test
267     done
268     git checkout src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice.rs
269     git checkout src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice2.rs
270
271     RUSTC_ARGS="-Zpanic-abort-tests -Csymbol-mangling-version=v0 -Zcodegen-backend="$(pwd)"/../target/"$CHANNEL"/librustc_codegen_gcc."$dylib_ext" --sysroot "$(pwd)"/../build_sysroot/sysroot -Cpanic=abort"
272
273     echo "[TEST] rustc test suite"
274     COMPILETEST_FORCE_STAGE0=1 ./x.py test --run always --stage 0 src/test/ui/ --rustc-args "$RUSTC_ARGS"
275 }
276
277 function clean_ui_tests() {
278     find rust/build/x86_64-unknown-linux-gnu/test/ui/ -name stamp -exec rm -rf {} \;
279 }
280
281 function all() {
282     clean
283     mini_tests
284     build_sysroot
285     std_tests
286     test_libcore
287     extended_sysroot_tests
288     test_rustc
289 }
290
291 $func