Skip to content

Commit 5a07879

Browse files
committed
Reduce the number of iterations on emulated aarch64 Linux
CI for aarch64 Linux is significantly slower than the others. Adjust how iteration selection is done to better handle this case, which also simplifies things. Also set the `EMULATED` environment variable in Docker to be more accurate, and reindents run-docker.sh.
1 parent 1a6a1cf commit 5a07879

File tree

3 files changed

+46
-37
lines changed

3 files changed

+46
-37
lines changed

libm/ci/run-docker.sh

+29-19
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,49 @@
55

66
set -euxo pipefail
77

8+
host_arch="$(uname -m | sed 's/arm64/aarch64/')"
9+
810
run() {
911
local target=$1
1012

1113
echo "testing target: $target"
1214

15+
target_arch="$(echo "$target" | cut -d'-' -f1)"
16+
17+
emulated=""
18+
if [ "$target_arch" != "$host_arch" ]; then
19+
emulated=1
20+
echo "target is emulated"
21+
fi
22+
1323
# This directory needs to exist before calling docker, otherwise docker will create it but it
1424
# will be owned by root
1525
mkdir -p target
1626

1727
docker build -t "$target" "ci/docker/$target"
1828
docker run \
19-
--rm \
20-
--user "$(id -u):$(id -g)" \
21-
-e RUSTFLAGS \
22-
-e CARGO_HOME=/cargo \
23-
-e CARGO_TARGET_DIR=/target \
24-
-e EMULATED=1 \
25-
-v "${HOME}/.cargo:/cargo" \
26-
-v "$(pwd)/target:/target" \
27-
-v "$(pwd):/checkout:ro" \
28-
-v "$(rustc --print sysroot):/rust:ro" \
29-
--init \
30-
-w /checkout \
31-
"$target" \
32-
sh -c "HOME=/tmp PATH=\$PATH:/rust/bin exec ci/run.sh $target"
29+
--rm \
30+
--user "$(id -u):$(id -g)" \
31+
-e RUSTFLAGS \
32+
-e CARGO_HOME=/cargo \
33+
-e CARGO_TARGET_DIR=/target \
34+
-e "EMULATED=$emulated" \
35+
-v "${HOME}/.cargo:/cargo" \
36+
-v "$(pwd)/target:/target" \
37+
-v "$(pwd):/checkout:ro" \
38+
-v "$(rustc --print sysroot):/rust:ro" \
39+
--init \
40+
-w /checkout \
41+
"$target" \
42+
sh -c "HOME=/tmp PATH=\$PATH:/rust/bin exec ci/run.sh $target"
3343
}
3444

3545
if [ -z "$1" ]; then
36-
echo "running tests for all targets"
46+
echo "running tests for all targets"
3747

38-
for d in ci/docker/*; do
39-
run $d
40-
done
48+
for d in ci/docker/*; do
49+
run $d
50+
done
4151
else
42-
run $1
52+
run $1
4353
fi

libm/crates/libm-test/src/gen/random.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,21 @@ const SEED: [u8; 32] = *b"3.141592653589793238462643383279";
1313

1414
/// Number of tests to run.
1515
const NTESTS: usize = {
16-
let ntests = if cfg!(optimizations_enabled) {
17-
if cfg!(target_arch = "x86_64") || cfg!(target_arch = "aarch64") {
18-
5_000_000
19-
} else if !cfg!(target_pointer_width = "64")
16+
if cfg!(optimizations_enabled) {
17+
if crate::emulated()
18+
|| !cfg!(target_pointer_width = "64")
2019
|| cfg!(all(target_arch = "x86_64", target_vendor = "apple"))
21-
|| option_env!("EMULATED").is_some()
22-
&& cfg!(any(target_arch = "aarch64", target_arch = "powerpc64"))
2320
{
24-
// Tests are pretty slow on:
25-
// - Non-64-bit targets
26-
// - Emulated ppc
27-
// - Emulated aarch64
28-
// - x86 MacOS
29-
// So reduce the number of iterations
21+
// Tests are pretty slow on non-64-bit targets, x86 MacOS, and targets that run
22+
// in QEMU.
3023
100_000
3124
} else {
32-
// Most everything else gets tested in docker and works okay, but we still
33-
// don't need 20 minutes of tests.
34-
1_000_000
25+
5_000_000
3526
}
3627
} else {
28+
// Without optimizations just run a quick check
3729
800
38-
};
39-
40-
ntests
30+
}
4131
};
4232

4333
/// Tested inputs.

libm/crates/libm-test/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,12 @@ pub fn canonical_name(name: &str) -> &str {
6262
.unwrap_or(name),
6363
}
6464
}
65+
66+
/// True if `EMULATED` is set and nonempty. Used to determine how many iterations to run.
67+
pub const fn emulated() -> bool {
68+
match option_env!("EMULATED") {
69+
Some(s) if s.is_empty() => false,
70+
None => false,
71+
Some(_) => true,
72+
}
73+
}

0 commit comments

Comments
 (0)