]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_codegen_cranelift/scripts/tests.sh
New upstream version 1.55.0+dfsg1
[rustc.git] / compiler / rustc_codegen_cranelift / scripts / tests.sh
1 #!/usr/bin/env bash
2
3 set -e
4
5 source scripts/config.sh
6 source scripts/ext_config.sh
7 export RUSTC=false # ensure that cg_llvm isn't accidentally used
8 MY_RUSTC="$(pwd)/build/bin/cg_clif $RUSTFLAGS -L crate=target/out --out-dir target/out -Cdebuginfo=2"
9
10 function no_sysroot_tests() {
11 echo "[BUILD] mini_core"
12 $MY_RUSTC example/mini_core.rs --crate-name mini_core --crate-type lib,dylib --target "$TARGET_TRIPLE"
13
14 echo "[BUILD] example"
15 $MY_RUSTC example/example.rs --crate-type lib --target "$TARGET_TRIPLE"
16
17 if [[ "$JIT_SUPPORTED" = "1" ]]; then
18 echo "[JIT] mini_core_hello_world"
19 CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC -Cllvm-args=mode=jit -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit --target "$HOST_TRIPLE"
20
21 echo "[JIT-lazy] mini_core_hello_world"
22 CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit --target "$HOST_TRIPLE"
23 else
24 echo "[JIT] mini_core_hello_world (skipped)"
25 fi
26
27 echo "[AOT] mini_core_hello_world"
28 $MY_RUSTC example/mini_core_hello_world.rs --crate-name mini_core_hello_world --crate-type bin -g --target "$TARGET_TRIPLE"
29 $RUN_WRAPPER ./target/out/mini_core_hello_world abc bcd
30 # (echo "break set -n main"; echo "run"; sleep 1; echo "si -c 10"; sleep 1; echo "frame variable") | lldb -- ./target/out/mini_core_hello_world abc bcd
31 }
32
33 function base_sysroot_tests() {
34 echo "[AOT] arbitrary_self_types_pointers_and_wrappers"
35 $MY_RUSTC example/arbitrary_self_types_pointers_and_wrappers.rs --crate-name arbitrary_self_types_pointers_and_wrappers --crate-type bin --target "$TARGET_TRIPLE"
36 $RUN_WRAPPER ./target/out/arbitrary_self_types_pointers_and_wrappers
37
38 echo "[AOT] alloc_system"
39 $MY_RUSTC example/alloc_system.rs --crate-type lib --target "$TARGET_TRIPLE"
40
41 echo "[AOT] alloc_example"
42 $MY_RUSTC example/alloc_example.rs --crate-type bin --target "$TARGET_TRIPLE"
43 $RUN_WRAPPER ./target/out/alloc_example
44
45 if [[ "$JIT_SUPPORTED" = "1" ]]; then
46 echo "[JIT] std_example"
47 $MY_RUSTC -Cllvm-args=mode=jit -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE"
48
49 echo "[JIT-lazy] std_example"
50 $MY_RUSTC -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE"
51 else
52 echo "[JIT] std_example (skipped)"
53 fi
54
55 echo "[AOT] dst_field_align"
56 # FIXME Re-add -Zmir-opt-level=2 once rust-lang/rust#67529 is fixed.
57 $MY_RUSTC example/dst-field-align.rs --crate-name dst_field_align --crate-type bin --target "$TARGET_TRIPLE"
58 $RUN_WRAPPER ./target/out/dst_field_align || (echo $?; false)
59
60 echo "[AOT] std_example"
61 $MY_RUSTC example/std_example.rs --crate-type bin --target "$TARGET_TRIPLE"
62 $RUN_WRAPPER ./target/out/std_example arg
63
64 echo "[AOT] subslice-patterns-const-eval"
65 $MY_RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
66 $RUN_WRAPPER ./target/out/subslice-patterns-const-eval
67
68 echo "[AOT] track-caller-attribute"
69 $MY_RUSTC example/track-caller-attribute.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
70 $RUN_WRAPPER ./target/out/track-caller-attribute
71
72 echo "[AOT] mod_bench"
73 $MY_RUSTC example/mod_bench.rs --crate-type bin --target "$TARGET_TRIPLE"
74 $RUN_WRAPPER ./target/out/mod_bench
75 }
76
77 function extended_sysroot_tests() {
78 pushd rand
79 ../build/cargo clean
80 if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
81 echo "[TEST] rust-random/rand"
82 ../build/cargo test --workspace
83 else
84 echo "[AOT] rust-random/rand"
85 ../build/cargo build --workspace --target $TARGET_TRIPLE --tests
86 fi
87 popd
88
89 pushd simple-raytracer
90 if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
91 echo "[BENCH COMPILE] ebobby/simple-raytracer"
92 hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "../build/cargo clean" \
93 "RUSTC=rustc RUSTFLAGS='' cargo build" \
94 "../build/cargo build"
95
96 echo "[BENCH RUN] ebobby/simple-raytracer"
97 cp ./target/debug/main ./raytracer_cg_clif
98 hyperfine --runs "${RUN_RUNS:-10}" ./raytracer_cg_llvm ./raytracer_cg_clif
99 else
100 ../build/cargo clean
101 echo "[BENCH COMPILE] ebobby/simple-raytracer (skipped)"
102 echo "[COMPILE] ebobby/simple-raytracer"
103 ../build/cargo build --target $TARGET_TRIPLE
104 echo "[BENCH RUN] ebobby/simple-raytracer (skipped)"
105 fi
106 popd
107
108 pushd build_sysroot/sysroot_src/library/core/tests
109 echo "[TEST] libcore"
110 ../../../../../build/cargo clean
111 if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
112 ../../../../../build/cargo test
113 else
114 ../../../../../build/cargo build --target $TARGET_TRIPLE --tests
115 fi
116 popd
117
118 pushd regex
119 echo "[TEST] rust-lang/regex example shootout-regex-dna"
120 ../build/cargo clean
121 export RUSTFLAGS="$RUSTFLAGS --cap-lints warn" # newer aho_corasick versions throw a deprecation warning
122 # Make sure `[codegen mono items] start` doesn't poison the diff
123 ../build/cargo build --example shootout-regex-dna --target $TARGET_TRIPLE
124 if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
125 cat examples/regexdna-input.txt \
126 | ../build/cargo run --example shootout-regex-dna --target $TARGET_TRIPLE \
127 | grep -v "Spawned thread" > res.txt
128 diff -u res.txt examples/regexdna-output.txt
129 fi
130
131 if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
132 echo "[TEST] rust-lang/regex tests"
133 ../build/cargo test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q
134 else
135 echo "[AOT] rust-lang/regex tests"
136 ../build/cargo build --tests --target $TARGET_TRIPLE
137 fi
138 popd
139 }
140
141 case "$1" in
142 "no_sysroot")
143 no_sysroot_tests
144 ;;
145 "base_sysroot")
146 base_sysroot_tests
147 ;;
148 "extended_sysroot")
149 extended_sysroot_tests
150 ;;
151 *)
152 echo "unknown test suite"
153 ;;
154 esac