Skip to content

Commit 524bc52

Browse files
feat: run intrinsic-test on a separate CI process
1 parent e11a9ea commit 524bc52

File tree

4 files changed

+275
-71
lines changed

4 files changed

+275
-71
lines changed

.github/workflows/main.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,80 @@ jobs:
248248
if: matrix.target.os == 'ubuntu-latest' && !startsWith(matrix.target.tuple, 'thumb')
249249
env:
250250
TARGET: ${{ matrix.target.tuple }}
251+
252+
intrinsic-test:
253+
needs: [style]
254+
name: Intrinsic Test
255+
runs-on: ${{ matrix.target.os }}
256+
strategy:
257+
matrix:
258+
profile:
259+
- dev
260+
- release
261+
target:
262+
# Dockers that are run through docker on linux
263+
- tuple: x86_64-unknown-linux-gnu
264+
os: ubuntu-latest
265+
- tuple: arm-unknown-linux-gnueabihf
266+
os: ubuntu-latest
267+
- tuple: armv7-unknown-linux-gnueabihf
268+
os: ubuntu-latest
269+
- tuple: aarch64-unknown-linux-gnu
270+
os: ubuntu-latest
271+
- tuple: aarch64_be-unknown-linux-gnu
272+
os: ubuntu-latest
273+
274+
# Add additional variables to the matrix variations generated above using `include`:
275+
include:
276+
# `TEST_EVERYTHING` setups - there should be at least 1 for each architecture
277+
- target:
278+
tuple: aarch64-unknown-linux-gnu
279+
os: ubuntu-latest
280+
test_everything: true
281+
- target:
282+
tuple: aarch64_be-unknown-linux-gnu
283+
os: ubuntu-latest
284+
test_everything: true
285+
build_std: true
286+
- target:
287+
tuple: armv7-unknown-linux-gnueabihf
288+
os: ubuntu-latest
289+
test_everything: true
290+
- target:
291+
tuple: x86_64-unknown-linux-gnu
292+
os: ubuntu-latest
293+
test_everything: true
294+
295+
steps:
296+
- uses: actions/checkout@v4
297+
- name: Install Rust
298+
run: |
299+
rustup update nightly --no-self-update
300+
rustup default nightly
301+
shell: bash
302+
- run: rustup target add ${{ matrix.target.tuple }}
303+
shell: bash
304+
if: matrix.build_std == ''
305+
- run: |
306+
rustup component add rust-src
307+
echo "CARGO_UNSTABLE_BUILD_STD=std" >> $GITHUB_ENV
308+
shell: bash
309+
if: matrix.build_std != ''
310+
311+
# Configure some env vars based on matrix configuration
312+
- run: echo "PROFILE=--profile=${{matrix.profile}}" >> $GITHUB_ENV
313+
shell: bash
314+
- run: echo "STDARCH_TEST_EVERYTHING=1" >> $GITHUB_ENV
315+
shell: bash
316+
if: matrix.test_everything != ''
317+
- run: echo "STDARCH_DISABLE_ASSERT_INSTR=1" >> $GITHUB_ENV
318+
shell: bash
319+
if: matrix.disable_assert_instr != ''
320+
- run: ./ci/intrinsic-test-docker.sh ${{ matrix.target.tuple }}
321+
shell: bash
322+
if: matrix.target.os == 'ubuntu-latest' && !startsWith(matrix.target.tuple, 'thumb')
323+
env:
324+
TARGET: ${{ matrix.target.tuple }}
251325

252326
# Check that the generated files agree with the checked-in versions.
253327
check-stdarch-gen:
@@ -276,6 +350,7 @@ jobs:
276350
- docs
277351
- verify
278352
- test
353+
- intrinsic-test
279354
- check-stdarch-gen
280355
runs-on: ubuntu-latest
281356
# We need to ensure this job does *not* get skipped if its dependencies fail,

ci/intrinsic-test-docker.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env sh
2+
3+
# Small script to run tests for a target (or all targets) inside all the
4+
# respective docker images.
5+
6+
set -ex
7+
8+
if [ $# -lt 1 ]; then
9+
>&2 echo "Usage: $0 <TARGET>"
10+
exit 1
11+
fi
12+
13+
run() {
14+
# Set the linker that is used for the host (e.g. when compiling a build.rs)
15+
# This overrides any configuration in e.g. `.cargo/config.toml`, which will
16+
# probably not work within the docker container.
17+
HOST_LINKER="CARGO_TARGET_$(rustc --print host-tuple | tr '[:lower:]-' '[:upper:]_')_LINKER"
18+
19+
# Prevent `Read-only file system (os error 30)`.
20+
cargo generate-lockfile
21+
22+
echo "Building docker container for TARGET=${1}"
23+
docker build -t stdarch -f "ci/docker/${1}/Dockerfile" ci/
24+
mkdir -p target c_programs rust_programs
25+
echo "Running docker"
26+
# shellcheck disable=SC2016
27+
docker run \
28+
--rm \
29+
--user "$(id -u)":"$(id -g)" \
30+
--env CARGO_HOME=/cargo \
31+
--env CARGO_TARGET_DIR=/checkout/target \
32+
--env TARGET="${1}" \
33+
--env "${HOST_LINKER}"="cc" \
34+
--env STDARCH_TEST_EVERYTHING \
35+
--env STDARCH_DISABLE_ASSERT_INSTR \
36+
--env NOSTD \
37+
--env NORUN \
38+
--env RUSTFLAGS \
39+
--env CARGO_UNSTABLE_BUILD_STD \
40+
--volume "${HOME}/.cargo":/cargo \
41+
--volume "$(rustc --print sysroot)":/rust:ro \
42+
--volume "$(pwd)":/checkout:ro \
43+
--volume "$(pwd)"/target:/checkout/target \
44+
--volume "$(pwd)"/c_programs:/checkout/c_programs \
45+
--volume "$(pwd)"/rust_programs:/checkout/rust_programs \
46+
--init \
47+
--workdir /checkout \
48+
--privileged \
49+
stdarch \
50+
sh -c "HOME=/tmp PATH=\$PATH:/rust/bin exec ci/intrinsic-test.sh ${1}"
51+
}
52+
53+
if [ -z "$1" ]; then
54+
>&2 echo "No target specified!"
55+
exit 1
56+
else
57+
run "${1}"
58+
fi

ci/intrinsic-test.sh

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/env sh
2+
3+
set -ex
4+
5+
: "${TARGET?The TARGET environment variable must be set.}"
6+
7+
# Tests are all super fast anyway, and they fault often enough on travis that
8+
# having only one thread increases debuggability to be worth it.
9+
#export RUST_BACKTRACE=full
10+
#export RUST_TEST_NOCAPTURE=1
11+
#export RUST_TEST_THREADS=1
12+
13+
export RUSTFLAGS="${RUSTFLAGS} -D warnings -Z merge-functions=disabled -Z verify-llvm-ir"
14+
export HOST_RUSTFLAGS="${RUSTFLAGS}"
15+
export PROFILE="${PROFILE:="--profile=release"}"
16+
17+
case ${TARGET} in
18+
# On 32-bit use a static relocation model which avoids some extra
19+
# instructions when dealing with static data, notably allowing some
20+
# instruction assertion checks to pass below the 20 instruction limit. If
21+
# this is the default, dynamic, then too many instructions are generated
22+
# when we assert the instruction for a function and it causes tests to fail.
23+
i686-* | i586-*)
24+
export RUSTFLAGS="${RUSTFLAGS} -C relocation-model=static"
25+
;;
26+
# Some x86_64 targets enable by default more features beyond SSE2,
27+
# which cause some instruction assertion checks to fail.
28+
x86_64-*)
29+
export RUSTFLAGS="${RUSTFLAGS} -C target-feature=-sse3"
30+
;;
31+
#Unoptimized build uses fast-isel which breaks with msa
32+
mips-* | mipsel-*)
33+
export RUSTFLAGS="${RUSTFLAGS} -C llvm-args=-fast-isel=false"
34+
;;
35+
armv7-*eabihf | thumbv7-*eabihf)
36+
export RUSTFLAGS="${RUSTFLAGS} -Ctarget-feature=+neon"
37+
;;
38+
# Some of our test dependencies use the deprecated `gcc` crates which
39+
# doesn't detect RISC-V compilers automatically, so do it manually here.
40+
riscv*)
41+
export RUSTFLAGS="${RUSTFLAGS} -Ctarget-feature=+zk,+zks,+zbb,+zbc"
42+
;;
43+
esac
44+
45+
echo "RUSTFLAGS=${RUSTFLAGS}"
46+
echo "OBJDUMP=${OBJDUMP}"
47+
echo "STDARCH_DISABLE_ASSERT_INSTR=${STDARCH_DISABLE_ASSERT_INSTR}"
48+
echo "STDARCH_TEST_EVERYTHING=${STDARCH_TEST_EVERYTHING}"
49+
echo "STDARCH_TEST_SKIP_FEATURE=${STDARCH_TEST_SKIP_FEATURE}"
50+
echo "STDARCH_TEST_SKIP_FUNCTION=${STDARCH_TEST_SKIP_FUNCTION}"
51+
echo "PROFILE=${PROFILE}"
52+
53+
CORE_ARCH="--manifest-path=crates/core_arch/Cargo.toml"
54+
STDARCH_EXAMPLES="--manifest-path=examples/Cargo.toml"
55+
INTRINSIC_TEST="--manifest-path=crates/intrinsic-test/Cargo.toml"
56+
57+
# Test targets compiled with extra features.
58+
case ${TARGET} in
59+
x86_64-unknown-linux-gnu)
60+
TEST_CPPFLAGS="-fuse-ld=lld -I/usr/include/x86_64-linux-gnu/"
61+
TEST_CXX_COMPILER="clang++"
62+
TEST_RUNNER="${CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER}"
63+
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_x86.txt
64+
TEST_SAMPLE_INTRINSICS_PERCENTAGE=5
65+
export STDARCH_DISABLE_ASSERT_INSTR=1
66+
PATH="$PATH":"$(pwd)"/c_programs
67+
export PATH
68+
;;
69+
x86_64* | i686*)
70+
export STDARCH_DISABLE_ASSERT_INSTR=1
71+
72+
;;
73+
74+
# Setup aarch64 & armv7 specific variables, the runner, along with some
75+
# tests to skip
76+
aarch64-unknown-linux-gnu*)
77+
TEST_CPPFLAGS="-fuse-ld=lld -I/usr/aarch64-linux-gnu/include/ -I/usr/aarch64-linux-gnu/include/c++/9/aarch64-linux-gnu/"
78+
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_aarch64.txt
79+
TEST_CXX_COMPILER="clang++"
80+
TEST_RUNNER="${CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER}"
81+
;;
82+
83+
aarch64_be-unknown-linux-gnu*)
84+
TEST_CPPFLAGS="-fuse-ld=lld"
85+
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_aarch64.txt
86+
TEST_CXX_COMPILER="clang++"
87+
TEST_RUNNER="${CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_RUNNER}"
88+
;;
89+
90+
armv7-unknown-linux-gnueabihf*)
91+
TEST_CPPFLAGS="-fuse-ld=lld -I/usr/arm-linux-gnueabihf/include/ -I/usr/arm-linux-gnueabihf/include/c++/9/arm-linux-gnueabihf/"
92+
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_arm.txt
93+
TEST_CXX_COMPILER="clang++"
94+
TEST_RUNNER="${CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER}"
95+
;;
96+
*)
97+
;;
98+
99+
esac
100+
101+
# Arm specific
102+
case "${TARGET}" in
103+
aarch64-unknown-linux-gnu*|armv7-unknown-linux-gnueabihf*)
104+
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=warn \
105+
cargo run "${INTRINSIC_TEST}" "${PROFILE}" \
106+
--bin intrinsic-test -- intrinsics_data/arm_intrinsics.json \
107+
--runner "${TEST_RUNNER}" \
108+
--cppcompiler "${TEST_CXX_COMPILER}" \
109+
--skip "${TEST_SKIP_INTRINSICS}" \
110+
--target "${TARGET}"
111+
;;
112+
113+
aarch64_be-unknown-linux-gnu*)
114+
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=warn \
115+
cargo run "${INTRINSIC_TEST}" "${PROFILE}" \
116+
--bin intrinsic-test -- intrinsics_data/arm_intrinsics.json \
117+
--runner "${TEST_RUNNER}" \
118+
--cppcompiler "${TEST_CXX_COMPILER}" \
119+
--skip "${TEST_SKIP_INTRINSICS}" \
120+
--target "${TARGET}" \
121+
--linker "${CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_LINKER}" \
122+
--cxx-toolchain-dir "${AARCH64_BE_TOOLCHAIN}"
123+
;;
124+
125+
x86_64-unknown-linux-gnu*)
126+
# `CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER` is not necessary for `intrinsic-test`
127+
# because the binary needs to run directly on the host.
128+
# Hence the use of `env -u`.
129+
env -u CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER \
130+
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" \
131+
RUST_LOG=warn RUST_BACKTRACE=1 \
132+
cargo run "${INTRINSIC_TEST}" "${PROFILE}" \
133+
--bin intrinsic-test -- intrinsics_data/x86-intel.xml \
134+
--runner "${TEST_RUNNER}" \
135+
--skip "${TEST_SKIP_INTRINSICS}" \
136+
--cppcompiler "${TEST_CXX_COMPILER}" \
137+
--target "${TARGET}" \
138+
--sample-percentage "${TEST_SAMPLE_INTRINSICS_PERCENTAGE}"
139+
;;
140+
*)
141+
;;
142+
esac

ci/run.sh

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ fi
9191
# Test targets compiled with extra features.
9292
case ${TARGET} in
9393
x86_64-unknown-linux-gnu)
94-
TEST_CPPFLAGS="-fuse-ld=lld -I/usr/include/x86_64-linux-gnu/"
95-
TEST_CXX_COMPILER="clang++"
96-
TEST_RUNNER="${CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER}"
97-
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_x86.txt
98-
TEST_SAMPLE_INTRINSICS_PERCENTAGE=5
9994
export STDARCH_DISABLE_ASSERT_INSTR=1
10095
PATH="$PATH":"$(pwd)"/c_programs
10196
export PATH
@@ -137,77 +132,11 @@ case ${TARGET} in
137132
export RUSTFLAGS="${RUSTFLAGS} -C target-feature=+altivec"
138133
cargo_test "${PROFILE}"
139134
;;
140-
141-
# Setup aarch64 & armv7 specific variables, the runner, along with some
142-
# tests to skip
143-
aarch64-unknown-linux-gnu*)
144-
TEST_CPPFLAGS="-fuse-ld=lld -I/usr/aarch64-linux-gnu/include/ -I/usr/aarch64-linux-gnu/include/c++/9/aarch64-linux-gnu/"
145-
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_aarch64.txt
146-
TEST_CXX_COMPILER="clang++"
147-
TEST_RUNNER="${CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER}"
148-
;;
149-
150-
aarch64_be-unknown-linux-gnu*)
151-
TEST_CPPFLAGS="-fuse-ld=lld"
152-
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_aarch64.txt
153-
TEST_CXX_COMPILER="clang++"
154-
TEST_RUNNER="${CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_RUNNER}"
155-
;;
156-
157-
armv7-unknown-linux-gnueabihf*)
158-
TEST_CPPFLAGS="-fuse-ld=lld -I/usr/arm-linux-gnueabihf/include/ -I/usr/arm-linux-gnueabihf/include/c++/9/arm-linux-gnueabihf/"
159-
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_arm.txt
160-
TEST_CXX_COMPILER="clang++"
161-
TEST_RUNNER="${CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER}"
162-
;;
163135
*)
164136
;;
165137

166138
esac
167139

168-
# Arm specific
169-
case "${TARGET}" in
170-
aarch64-unknown-linux-gnu*|armv7-unknown-linux-gnueabihf*)
171-
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=warn \
172-
cargo run "${INTRINSIC_TEST}" "${PROFILE}" \
173-
--bin intrinsic-test -- intrinsics_data/arm_intrinsics.json \
174-
--runner "${TEST_RUNNER}" \
175-
--cppcompiler "${TEST_CXX_COMPILER}" \
176-
--skip "${TEST_SKIP_INTRINSICS}" \
177-
--target "${TARGET}"
178-
;;
179-
180-
aarch64_be-unknown-linux-gnu*)
181-
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=warn \
182-
cargo run "${INTRINSIC_TEST}" "${PROFILE}" \
183-
--bin intrinsic-test -- intrinsics_data/arm_intrinsics.json \
184-
--runner "${TEST_RUNNER}" \
185-
--cppcompiler "${TEST_CXX_COMPILER}" \
186-
--skip "${TEST_SKIP_INTRINSICS}" \
187-
--target "${TARGET}" \
188-
--linker "${CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_LINKER}" \
189-
--cxx-toolchain-dir "${AARCH64_BE_TOOLCHAIN}"
190-
;;
191-
192-
x86_64-unknown-linux-gnu*)
193-
# `CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER` is not necessary for `intrinsic-test`
194-
# because the binary needs to run directly on the host.
195-
# Hence the use of `env -u`.
196-
env -u CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER \
197-
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" \
198-
RUST_LOG=warn RUST_BACKTRACE=1 \
199-
cargo run "${INTRINSIC_TEST}" "${PROFILE}" \
200-
--bin intrinsic-test -- intrinsics_data/x86-intel.xml \
201-
--runner "${TEST_RUNNER}" \
202-
--skip "${TEST_SKIP_INTRINSICS}" \
203-
--cppcompiler "${TEST_CXX_COMPILER}" \
204-
--target "${TARGET}" \
205-
--sample-percentage "${TEST_SAMPLE_INTRINSICS_PERCENTAGE}"
206-
;;
207-
*)
208-
;;
209-
esac
210-
211140
if [ "$NORUN" != "1" ] && [ "$NOSTD" != 1 ]; then
212141
# Test examples
213142
(

0 commit comments

Comments
 (0)