]> git.lizzy.rs Git - rust.git/blob - scripts/tests.sh
Sync from rust 2f004d2d401682e553af3984ebd9a3976885e752
[rust.git] / 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 -Zunstable-options -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 -Zunstable-options -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] issue_91827_extern_types"
39     $MY_RUSTC example/issue-91827-extern-types.rs --crate-name issue_91827_extern_types --crate-type bin --target "$TARGET_TRIPLE"
40     $RUN_WRAPPER ./target/out/issue_91827_extern_types
41
42     echo "[AOT] alloc_system"
43     $MY_RUSTC example/alloc_system.rs --crate-type lib --target "$TARGET_TRIPLE"
44
45     echo "[AOT] alloc_example"
46     $MY_RUSTC example/alloc_example.rs --crate-type bin --target "$TARGET_TRIPLE"
47     $RUN_WRAPPER ./target/out/alloc_example
48
49     if [[ "$JIT_SUPPORTED" = "1" ]]; then
50         echo "[JIT] std_example"
51         $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE"
52
53         echo "[JIT-lazy] std_example"
54         $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE"
55     else
56         echo "[JIT] std_example (skipped)"
57     fi
58
59     echo "[AOT] dst_field_align"
60     # FIXME Re-add -Zmir-opt-level=2 once rust-lang/rust#67529 is fixed.
61     $MY_RUSTC example/dst-field-align.rs --crate-name dst_field_align --crate-type bin --target "$TARGET_TRIPLE"
62     $RUN_WRAPPER ./target/out/dst_field_align || (echo $?; false)
63
64     echo "[AOT] std_example"
65     $MY_RUSTC example/std_example.rs --crate-type bin --target "$TARGET_TRIPLE"
66     $RUN_WRAPPER ./target/out/std_example arg
67
68     echo "[AOT] subslice-patterns-const-eval"
69     $MY_RUSTC example/subslice-patterns-const-eval.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
70     $RUN_WRAPPER ./target/out/subslice-patterns-const-eval
71
72     echo "[AOT] track-caller-attribute"
73     $MY_RUSTC example/track-caller-attribute.rs --crate-type bin -Cpanic=abort --target "$TARGET_TRIPLE"
74     $RUN_WRAPPER ./target/out/track-caller-attribute
75
76     echo "[AOT] mod_bench"
77     $MY_RUSTC example/mod_bench.rs --crate-type bin --target "$TARGET_TRIPLE"
78     $RUN_WRAPPER ./target/out/mod_bench
79 }
80
81 function extended_sysroot_tests() {
82     pushd rand
83     ../build/cargo-clif clean
84     if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
85         echo "[TEST] rust-random/rand"
86         ../build/cargo-clif test --workspace
87     else
88         echo "[AOT] rust-random/rand"
89         ../build/cargo-clif build --workspace --target $TARGET_TRIPLE --tests
90     fi
91     popd
92
93     pushd simple-raytracer
94     if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
95         echo "[BENCH COMPILE] ebobby/simple-raytracer"
96         hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "../build/cargo-clif clean" \
97         "RUSTC=rustc RUSTFLAGS='' cargo build" \
98         "../build/cargo-clif build"
99
100         echo "[BENCH RUN] ebobby/simple-raytracer"
101         cp ./target/debug/main ./raytracer_cg_clif
102         hyperfine --runs "${RUN_RUNS:-10}" ./raytracer_cg_llvm ./raytracer_cg_clif
103     else
104         ../build/cargo-clif clean
105         echo "[BENCH COMPILE] ebobby/simple-raytracer (skipped)"
106         echo "[COMPILE] ebobby/simple-raytracer"
107         ../build/cargo-clif build --target $TARGET_TRIPLE
108         echo "[BENCH RUN] ebobby/simple-raytracer (skipped)"
109     fi
110     popd
111
112     pushd build_sysroot/sysroot_src/library/core/tests
113     echo "[TEST] libcore"
114     ../../../../../build/cargo-clif clean
115     if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
116         ../../../../../build/cargo-clif test
117     else
118         ../../../../../build/cargo-clif build --target $TARGET_TRIPLE --tests
119     fi
120     popd
121
122     pushd regex
123     echo "[TEST] rust-lang/regex example shootout-regex-dna"
124     ../build/cargo-clif clean
125     export RUSTFLAGS="$RUSTFLAGS --cap-lints warn" # newer aho_corasick versions throw a deprecation warning
126     # Make sure `[codegen mono items] start` doesn't poison the diff
127     ../build/cargo-clif build --example shootout-regex-dna --target $TARGET_TRIPLE
128     if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
129         cat examples/regexdna-input.txt \
130             | ../build/cargo-clif run --example shootout-regex-dna --target $TARGET_TRIPLE \
131             | grep -v "Spawned thread" > res.txt
132         diff -u res.txt examples/regexdna-output.txt
133     fi
134
135     if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
136         echo "[TEST] rust-lang/regex tests"
137         ../build/cargo-clif test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q
138     else
139         echo "[AOT] rust-lang/regex tests"
140         ../build/cargo-clif build --tests --target $TARGET_TRIPLE
141     fi
142     popd
143
144     pushd portable-simd
145     echo "[TEST] rust-lang/portable-simd"
146     ../build/cargo-clif clean
147     ../build/cargo-clif build --all-targets --target $TARGET_TRIPLE
148     if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then
149         ../build/cargo-clif test -q
150     fi
151     popd
152 }
153
154 case "$1" in
155     "no_sysroot")
156         no_sysroot_tests
157         ;;
158     "base_sysroot")
159         base_sysroot_tests
160         ;;
161     "extended_sysroot")
162         extended_sysroot_tests
163         ;;
164     *)
165         echo "unknown test suite"
166         ;;
167 esac