Skip to content

Commit 22b5886

Browse files
committed
ci: Merge valgrind and valgrind-cross jobs
1 parent f41ed61 commit 22b5886

4 files changed

Lines changed: 79 additions & 117 deletions

File tree

.github/workflows/ci.yml

Lines changed: 30 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,12 @@ jobs:
771771
# TODO: "unhandled instruction: 0x4508 0xD103" in atomic_sub in Arc::drop (as of Valgrind 3.26)
772772
# - target: thumbv7neon-unknown-linux-gnueabihf
773773
# os: ubuntu-24.04-arm
774+
- target: powerpc64le-unknown-linux-gnu
775+
arch: ppc64le
776+
- target: riscv64gc-unknown-linux-gnu
777+
arch: riscv64
778+
- target: s390x-unknown-linux-gnu
779+
arch: s390x
774780
runs-on: ${{ matrix.os || 'ubuntu-24.04' }}
775781
timeout-minutes: 60
776782
steps:
@@ -779,8 +785,7 @@ jobs:
779785
with:
780786
tool: rust@nightly,cargo-hack
781787
fallback: none
782-
- id: prepare
783-
run: |
788+
- run: |
784789
if [[ -z "${TARGET}" ]]; then
785790
printf 'matrix.target must be set\n'
786791
exit 1
@@ -789,143 +794,59 @@ jobs:
789794
if [[ "${host}" != "${TARGET}" ]]; then
790795
printf 'TARGET=--target=%s\n' "${TARGET}" >>"${GITHUB_ENV}"
791796
fi
797+
printf 'VALGRIND=%s\n' "${VALGRIND}" >>"${GITHUB_ENV}"
792798
env:
793799
TARGET: ${{ matrix.target }}
800+
VALGRIND: ${{ matrix.arch && 'valgrind-cross' || 'valgrind' }}
794801
# - run: apt-get -o Acquire::Retries=10 -qq update && apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends moreutils
795802
- uses: taiki-e/setup-cross-toolchain-action@3d9770ce98eb7dbcf378563182a5e8031165f75b # v1.41.0
796803
with:
797804
target: ${{ matrix.target }}
798805
runner: valgrind
799-
- run: tools/test.sh valgrind -vv ${TARGET:-}
806+
- uses: taiki-e/github-actions/setup-docker@1bb80ca038216cd1fb7b6ca6d76240b3772963ab # main # zizmor: ignore[stale-action-refs]
807+
with:
808+
buildx: false
809+
qemu: ${{ matrix.arch }}
810+
if: matrix.arch != ''
811+
- run: tools/test.sh "${VALGRIND}" -vv ${TARGET:-}
800812
# x86_64 +cmpxchg16b
801-
- run: tools/test.sh valgrind -vv ${TARGET:-}
813+
- run: tools/test.sh "${VALGRIND}" -vv ${TARGET:-}
802814
env:
803815
# outline-atomics (vmovdqa load/store) path has been tested above, disable outline-atomics and test cmpxchg16b load/store path.
804816
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-feature=+cmpxchg16b --cfg portable_atomic_no_outline_atomics
805817
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-feature=+cmpxchg16b --cfg portable_atomic_no_outline_atomics
806818
if: startsWith(matrix.target, 'x86_64')
807819
# x86_64 +cmpxchg16b,+avx
808-
- run: tools/test.sh valgrind -vv ${TARGET:-}
820+
- run: tools/test.sh "${VALGRIND}" -vv ${TARGET:-}
809821
env:
810822
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-feature=+cmpxchg16b,+avx
811823
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-feature=+cmpxchg16b,+avx
812824
if: startsWith(matrix.target, 'x86_64')
813825
# On AArch64 linux-gnu, outline-atomics is enabled by default.
814-
- run: tools/test.sh valgrind -vv ${TARGET:-}
826+
- run: tools/test.sh "${VALGRIND}" -vv ${TARGET:-}
815827
env:
816828
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} --cfg portable_atomic_no_outline_atomics
817829
RUSTFLAGS: ${{ env.RUSTFLAGS }} --cfg portable_atomic_no_outline_atomics
818830
if: (startsWith(matrix.target, 'aarch64') || startsWith(matrix.target, 'arm64'))
819831
# aarch64 +lse
820832
# As of Valgrind 3.26, Valgrind supports atomic instructions of Armv8.0, Armv8.1 (FEAT_LSE), and Armv8.3 (FEAT_LRCPC).
821-
- run: tools/test.sh valgrind -vv ${TARGET:-}
833+
- run: tools/test.sh "${VALGRIND}" -vv ${TARGET:-}
822834
env:
823835
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-feature=+lse
824836
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-feature=+lse
825837
if: (startsWith(matrix.target, 'aarch64') || startsWith(matrix.target, 'arm64'))
826-
827-
valgrind-cross:
828-
name: valgrind (${{ matrix.target }})
829-
needs: tidy
830-
strategy:
831-
fail-fast: false
832-
matrix:
833-
include:
834-
- target: powerpc64le-unknown-linux-gnu
835-
arch: ppc64le
836-
- target: riscv64gc-unknown-linux-gnu
837-
arch: riscv64
838-
- target: s390x-unknown-linux-gnu
839-
arch: s390x
840-
runs-on: ubuntu-24.04
841-
timeout-minutes: 60
842-
steps:
843-
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
844-
- uses: taiki-e/install-action@7be9fd86bd1707236395105d6e9329dd1511a7e1 # v2.79.0
845-
with:
846-
tool: rust@nightly
847-
fallback: none
848-
# - run: sudo apt-get -o Acquire::Retries=10 -qq update && apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends moreutils
849-
- uses: taiki-e/setup-cross-toolchain-action@3d9770ce98eb7dbcf378563182a5e8031165f75b # v1.41.0
850-
with:
851-
target: ${{ matrix.target }}
852-
runner: valgrind
853-
- uses: taiki-e/github-actions/setup-docker@1bb80ca038216cd1fb7b6ca6d76240b3772963ab # main # zizmor: ignore[stale-action-refs]
854-
with:
855-
buildx: false
856-
qemu: ${{ matrix.arch }}
857-
- run: |
858-
export CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS=true
859-
# Skip debug mode because it's slow.
860-
binary_path=$(
861-
./tools/test.sh build-valgrind --target "${TARGET}" --release
862-
)
863-
mv -- "${binary_path}" ./release
864-
binary_path=$(
865-
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \
866-
CARGO_PROFILE_RELEASE_LTO=fat \
867-
./tools/test.sh build-valgrind --target "${TARGET}" --release
868-
)
869-
mv -- "${binary_path}" ./release-fat-lto
870-
case "${TARGET}" in
871-
s390x*)
872-
# s390x z196 (arch9)
873-
binary_path=$(
874-
RUSTFLAGS="${RUSTFLAGS:-} -C target-cpu=z196" \
875-
./tools/test.sh build-valgrind --target "${TARGET}" --release
876-
)
877-
mv -- "${binary_path}" ./release-z196
878-
binary_path=$(
879-
RUSTFLAGS="${RUSTFLAGS:-} -C target-cpu=z196" \
880-
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \
881-
CARGO_PROFILE_RELEASE_LTO=fat \
882-
./tools/test.sh build-valgrind --target "${TARGET}" --release
883-
)
884-
mv -- "${binary_path}" ./release-z196-fat-lto
885-
# s390x z15 (arch13)
886-
binary_path=$(
887-
RUSTFLAGS="${RUSTFLAGS:-} -C target-cpu=z15" \
888-
./tools/test.sh build-valgrind --target "${TARGET}" --release
889-
)
890-
mv -- "${binary_path}" ./release-z15
891-
binary_path=$(
892-
RUSTFLAGS="${RUSTFLAGS:-} -C target-cpu=z15" \
893-
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \
894-
CARGO_PROFILE_RELEASE_LTO=fat \
895-
./tools/test.sh build-valgrind --target "${TARGET}" --release
896-
)
897-
mv -- "${binary_path}" ./release-z15-fat-lto
898-
;;
899-
esac
900-
901-
# NB: Sync with arguments in tools/test.sh.
902-
workspace_dir="${PWD}"
903-
args='-v --error-exitcode=1 --error-limit=no --leak-check=full --track-origins=yes --fair-sched=yes --gen-suppressions=all'
904-
supp="${workspace_dir}/tools/valgrind/${TARGET%%-*}.supp"
905-
if [[ -f "${supp}" ]]; then
906-
args+=" --suppressions=\"${supp}\""
907-
fi
908-
cat >run <<'EOF'
909-
#!/usr/bin/env bash
910-
set -CeEuxo pipefail
911-
EOF
912-
for bin in ./release*; do
913-
printf '%s\n' "valgrind ${args} ${bin}" >>run
914-
done
915-
cat -- ./run
916-
chmod +x ./run
917-
# https://github.com/taiki-e/setup-cross-toolchain-action#valgrind-runner
918-
valgrind_version='3.27.1'
919-
docker run --rm --init --user "$(id -u)":"$(id -g)" \
920-
--mount "type=bind,source=${workspace_dir},target=${workspace_dir}" --workdir "${workspace_dir}" \
921-
-e CI -e GITHUB_ACTIONS \
922-
-e RUST_BACKTRACE -e RUST_TEST_THREADS \
923-
-e PORTABLE_ATOMIC_DENY_WARNINGS \
924-
--platform=linux/"${ARCH}" ghcr.io/taiki-e/valgrind:"${valgrind_version}-${ARCH}"-cross \
925-
./run
838+
# s390x z196 (arch9)
839+
- run: tools/test.sh "${VALGRIND}" -vv ${TARGET:-}
926840
env:
927-
TARGET: ${{ matrix.target }}
928-
ARCH: ${{ matrix.arch }}
841+
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-cpu=z196
842+
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-cpu=z196
843+
if: startsWith(matrix.target, 's390x')
844+
# s390x z15 (arch13)
845+
- run: tools/test.sh "${VALGRIND}" -vv ${TARGET:-}
846+
env:
847+
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-cpu=z15
848+
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-cpu=z15
849+
if: startsWith(matrix.target, 's390x')
929850

930851
asm-test:
931852
needs: tidy

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [
116116
# Public APIs, considered unstable unless documented as stable in readme.
117117
'cfg(portable_atomic_no_outline_atomics,portable_atomic_outline_atomics,portable_atomic_unstable_f16,portable_atomic_unstable_f128)',
118118
# Not public API.
119-
'cfg(portable_atomic_test_detect_false,portable_atomic_test_no_std_static_assert_ffi,qemu,valgrind)',
119+
'cfg(portable_atomic_test_detect_false,portable_atomic_test_no_std_static_assert_ffi,qemu,valgrind,valgrind_cross)',
120120
] }
121121
unnameable_types = "warn"
122122
unreachable_pub = "warn"

src/tests/helper.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,7 +2790,7 @@ pub(crate) fn stress_test_config(rng: &mut fastrand::Rng) -> (usize, usize) {
27902790
} else {
27912791
25_000
27922792
};
2793-
let threads = if cfg!(debug_assertions) { 2 } else { rng.usize(2..=8) };
2793+
let threads = if cfg!(any(debug_assertions, valgrind)) { 2 } else { rng.usize(2..=8) };
27942794
eprintln!("threads={}", threads);
27952795
(iterations, threads)
27962796
}
@@ -2838,7 +2838,7 @@ macro_rules! __stress_acquire_release {
28382838
) => {
28392839
paste::paste! {
28402840
#[test]
2841-
#[cfg_attr(all(debug_assertions, not(miri)), ignore = "slow in some environments")] // debug mode is slow.
2841+
#[cfg_attr(all(any(debug_assertions, valgrind_cross), not(miri)), ignore = "slow in some environments")] // debug mode is slow.
28422842
#[allow(
28432843
clippy::cast_possible_wrap,
28442844
clippy::cast_sign_loss,
@@ -2883,7 +2883,7 @@ macro_rules! __stress_seqcst {
28832883
// of iterations are needed, but this test is slow in some environments.
28842884
// So, ignore on QEMU by default.
28852885
#[test]
2886-
#[cfg_attr(any(all(debug_assertions, not(miri)), qemu), ignore = "slow in some environments")] // debug mode is slow.
2886+
#[cfg_attr(any(all(any(debug_assertions, valgrind_cross), not(miri)), qemu), ignore = "slow in some environments")] // debug mode is slow.
28872887
#[allow(
28882888
clippy::cast_possible_wrap,
28892889
clippy::cast_sign_loss,

tools/test.sh

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cd -- "$(dirname -- "$0")"/..
88

99
# USAGE:
1010
# ./tools/test.sh [+toolchain] [cargo_options]...
11-
# ./tools/test.sh [+toolchain] build|build-valgrind|miri|valgrind [cargo_options]...
11+
# ./tools/test.sh [+toolchain] build|miri|valgrind|valgrind-cross [cargo_options]...
1212

1313
# NB: sync with:
1414
# - docs.rs metadata in Cargo.toml
@@ -75,7 +75,7 @@ if [[ "${1:-}" == "+"* ]]; then
7575
fi
7676
cmd='test'
7777
case "${1:-}" in
78-
build | build-valgrind | miri | valgrind)
78+
build | miri | valgrind | valgrind-cross)
7979
cmd="$1"
8080
shift
8181
;;
@@ -237,7 +237,7 @@ if [[ -n "${cranelift}" ]] || [[ -n "${gcc}" ]]; then
237237
fi
238238

239239
case "${cmd}" in
240-
*valgrind)
240+
*valgrind*)
241241
# TODO: always pass randomize-layout
242242
export RUSTFLAGS="${RUSTFLAGS:-} --cfg valgrind"
243243
export RUSTDOCFLAGS="${RUSTDOCFLAGS:-} --cfg valgrind"
@@ -274,7 +274,7 @@ case "${cmd}" in
274274
valgrind)
275275
# Refs: https://valgrind.org/docs/manual/mc-manual.html
276276
# See also https://wiki.wxwidgets.org/Valgrind_Suppression_File_Howto for suppression file.
277-
# NB: Sync with arguments in valgrind-other job in .github/workflows/ci.yml.
277+
# NB: Sync with valgrind-cross case.
278278
valgrind="valgrind -v --error-exitcode=1 --error-limit=no --leak-check=full --track-origins=yes --fair-sched=yes --gen-suppressions=all"
279279
supp="${workspace_dir}/tools/valgrind/${target%%-*}.supp"
280280
if [[ -f "${supp}" ]]; then
@@ -286,6 +286,47 @@ case "${cmd}" in
286286
tests=(--tests)
287287
fi
288288
;;
289+
valgrind-cross)
290+
export RUSTFLAGS="${RUSTFLAGS:-} --cfg valgrind_cross"
291+
export RUSTDOCFLAGS="${RUSTDOCFLAGS:-} --cfg valgrind_cross"
292+
# Refs: https://valgrind.org/docs/manual/mc-manual.html
293+
# See also https://wiki.wxwidgets.org/Valgrind_Suppression_File_Howto for suppression file.
294+
# NB: Sync with valgrind case.
295+
valgrind="valgrind -v --error-exitcode=1 --error-limit=no --leak-check=full --track-origins=yes --fair-sched=yes --gen-suppressions=all"
296+
supp="${workspace_dir}/tools/valgrind/${target%%-*}.supp"
297+
if [[ -f "${supp}" ]]; then
298+
valgrind+=" --suppressions=${supp}"
299+
fi
300+
# https://github.com/taiki-e/setup-cross-toolchain-action#valgrind-runner
301+
valgrind_version='3.27.1'
302+
case "${target}" in
303+
powerpc64le-*) arch=ppc64le ;;
304+
riscv64*) arch=riscv64 ;;
305+
s390x*) arch=s390x ;;
306+
*) bail "unrecognized target for valgrind-cross: ${target}" ;;
307+
esac
308+
mkdir -p -- tmp
309+
# --privileged is for better performance.
310+
cat >|tmp/valgrind-cross <<EOF
311+
#!/usr/bin/env bash
312+
set -CeEuxo pipefail
313+
docker run --rm --init --user "$(id -u):$(id -g)" \\
314+
--privileged \\
315+
--mount type=bind,source=${workspace_dir},target=${workspace_dir} --workdir ${workspace_dir} \\
316+
-e CI -e GITHUB_ACTIONS -e RUST_BACKTRACE -e RUST_TEST_THREADS \\
317+
-e PORTABLE_ATOMIC_DENY_WARNINGS \\
318+
--platform=linux/${arch} ghcr.io/taiki-e/valgrind:${valgrind_version}-${arch}-cross \\
319+
valgrind "\$@"
320+
EOF
321+
chmod +x ./tmp/valgrind-cross
322+
export "CARGO_TARGET_${target_upper}_RUNNER"="${workspace_dir}/tmp/valgrind-cross"
323+
# Skip debug mode because it's slow.
324+
release=(--release)
325+
# doctest on Valgrind is very slow
326+
if [[ ${#tests[@]} -eq 0 ]]; then
327+
tests=(--tests)
328+
fi
329+
;;
289330
test) ;;
290331
*) bail "unrecognized command '${cmd}'" ;;
291332
esac

0 commit comments

Comments
 (0)