Skip to content

Commit

Permalink
ci: Clean up tools/test.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jun 4, 2023
1 parent 0977ce6 commit 2c9e790
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 52 deletions.
7 changes: 3 additions & 4 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ aarch64_linux_valgrind_task:
name: valgrind ($TARGET)
env:
TARGET: aarch64-unknown-linux-gnu
VALGRIND: valgrind
arm_container:
# Valgrind support ldxp/stxp on 3.19+: https://valgrind.org/docs/manual/dist.news.html
# However, current Debian stable's Valgrind is 3.16: https://packages.debian.org/en/stable/valgrind
Expand All @@ -140,14 +139,14 @@ aarch64_linux_valgrind_task:
test_script:
- . $HOME/.cargo/env
- set -ex
- ./tools/test.sh -vv
- ./tools/test.sh valgrind -vv
# outline-atomics is enabled by default on linux-gnu and linux-musl with dynamic linking.
- RUSTFLAGS="$RUSTFLAGS --cfg portable_atomic_no_outline_atomics" RUSTDOCFLAGS="$RUSTDOCFLAGS --cfg portable_atomic_no_outline_atomics" ./tools/test.sh -vv --tests
- RUSTFLAGS="$RUSTFLAGS --cfg portable_atomic_no_outline_atomics" RUSTDOCFLAGS="$RUSTDOCFLAGS --cfg portable_atomic_no_outline_atomics" ./tools/test.sh valgrind -vv --tests
# We test doctest only once with the default build conditions because doctest is slow. Both api-test
# and src/tests have extended copies of doctest, so this will not reduce test coverage.
# +lse
# As of Valgrind 3.19, Valgrind supports atomic instructions of ARMv8.0 and ARMv8.1 (FEAT_LSE).
- RUSTFLAGS="$RUSTFLAGS -C target-feature=+lse" RUSTDOCFLAGS="$RUSTDOCFLAGS -C target-feature=+lse" ./tools/test.sh -vv --tests
- RUSTFLAGS="$RUSTFLAGS -C target-feature=+lse" RUSTDOCFLAGS="$RUSTDOCFLAGS -C target-feature=+lse" ./tools/test.sh valgrind -vv --tests
#
# aarch64_linux_bench_task:
# name: bench ($TARGET)
Expand Down
14 changes: 3 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ env:
RUSTDOCFLAGS: -D warnings
RUSTFLAGS: -D warnings
RUSTUP_MAX_RETRIES: 10
EXCLUDE: --exclude bench --exclude portable-atomic-internal-codegen

defaults:
run:
Expand Down Expand Up @@ -420,12 +419,7 @@ jobs:
echo "RUSTFLAGS=${RUSTFLAGS} ${{ matrix.flags }}" >>"${GITHUB_ENV}"
echo "RUSTDOCFLAGS=${RUSTDOCFLAGS} ${{ matrix.flags }}" >>"${GITHUB_ENV}"
if: matrix.flags != ''
- run: cargo miri test --workspace --all-features $EXCLUDE $TARGET 2>&1 | ts -i '%.s '
env:
MIRIFLAGS: -Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-retag-fields -Zmiri-disable-isolation
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -Z randomize-layout
RUSTFLAGS: ${{ env.RUSTFLAGS }} -Z randomize-layout
QUICKCHECK_TESTS: 10
- run: tools/test.sh miri $TARGET

san:
needs: tidy
Expand Down Expand Up @@ -470,8 +464,6 @@ jobs:

valgrind:
needs: tidy
env:
VALGRIND: valgrind
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
Expand All @@ -482,11 +474,11 @@ jobs:
run: rustup toolchain add nightly --no-self-update && rustup default nightly
- run: sudo apt-get -o Acquire::Retries=10 -qq update && sudo apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends moreutils
- uses: taiki-e/install-action@valgrind
- run: tools/test.sh -vv
- run: tools/test.sh valgrind -vv
# We test doctest only once with the default build conditions because doctest is slow. Both api-test
# and src/tests have extended copies of doctest, so this will not reduce test coverage.
# +cmpxchg16b
- run: tools/test.sh -vv --tests
- run: tools/test.sh valgrind -vv --tests
env:
# vmovdqa load/store path has been tested above, disable outline-atomics and test cmpxchg16b load/store path.
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-feature=+cmpxchg16b --cfg portable_atomic_no_outline_atomics
Expand Down
3 changes: 1 addition & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ Build tests for powerpc64le and get path to test binary.
# cargo's "Executable ..." output.
binary_path=$(
CARGO_TARGET_POWERPC64LE_UNKNOWN_LINUX_GNU_LINKER=powerpc64le-linux-gnu-gcc \
cargo test --no-run --all-features --target powerpc64le-unknown-linux-gnu --message-format=json --release \
| jq -r "select(.manifest_path == \"$(cargo locate-project --message-format=plain)\") | select(.executable != null) | .executable"
./tools/test.sh build --target powerpc64le-unknown-linux-gnu --release
)
```

Expand Down
8 changes: 3 additions & 5 deletions tests/avr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn main() -> ! {
test_atomic_float!(f64);
}

semihosting::exit(semihosting::EXIT_SUCCESS)
semihosting::exit(0)
}

#[inline(never)]
Expand Down Expand Up @@ -166,7 +166,7 @@ fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
println!(" (no location info)");
}

semihosting::exit(semihosting::EXIT_FAILURE)
semihosting::exit(1)
}
#[lang = "eh_personality"]
#[no_mangle]
Expand All @@ -175,12 +175,10 @@ pub extern "C" fn rust_eh_personality() {}
mod semihosting {
use core::fmt;

pub const EXIT_SUCCESS: u32 = 0;
pub const EXIT_FAILURE: u32 = 1;
pub fn exit(code: u32) -> ! {
// It seems there is no way to exit simavr with a non-zero exit code.
// https://github.com/buserror/simavr/issues/362
if code == EXIT_SUCCESS {
if code == 0 {
avr_device::interrupt::disable();
avr_device::asm::sleep();
}
Expand Down
10 changes: 3 additions & 7 deletions tools/fuchsia-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ esac
target="$1-unknown-fuchsia"
shift

cargo_options=(--no-run --all-features)
cargo_options=()
rest_cargo_options=(--test-threads=1)
while [[ $# -gt 0 ]]; do
case "$1" in
--tests | --all-targets | --doc | --target | --target=*) bail "unsupported option '$1'" ;;
--)
shift
rest_cargo_options=("$@")
rest_cargo_options+=("$@")
break
;;
*) cargo_options+=("$1") ;;
Expand Down Expand Up @@ -92,11 +92,7 @@ libstd_name=$(basename "$(ls "${target_libdir}"/libstd-*.so)")
libtest_name=$(basename "$(ls "${target_libdir}"/libtest-*.so)")

export RUSTFLAGS="${RUSTFLAGS:-} -L native=${SDK_PATH}/arch/${arch}/lib -L native=${SDK_PATH}/arch/${arch}/sysroot/lib"
cargo ${pre_args[@]+"${pre_args[@]}"} test --target "${target}" "${cargo_options[@]}"
binary_path=$(
cargo ${pre_args[@]+"${pre_args[@]}"} test --target "${target}" --message-format=json "${cargo_options[@]}" \
| jq -r "select(.manifest_path == \"$(cargo ${pre_args[@]+"${pre_args[@]}"} locate-project --message-format=plain)\") | select(.executable != null) | .executable"
)
binary_path=$(./tools/test.sh ${pre_args[@]+"${pre_args[@]}"} build --target "${target}" "${cargo_options[@]}")

package_name=t
package_dir=target/pkg
Expand Down
81 changes: 58 additions & 23 deletions tools/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ trap -- 'echo >&2 "$0: trapped SIGINT"; exit 1' SIGINT

# USAGE:
# ./tools/test.sh [+toolchain] [cargo_options]...
# ./tools/test.sh [+toolchain] build|miri|valgrind [cargo_options]...

x() {
local cmd="$1"
Expand All @@ -31,10 +32,13 @@ x_cargo() {
if [[ -n "${CARGO_PROFILE_RELEASE_LTO:-}" ]]; then
echo "+ CARGO_PROFILE_RELEASE_LTO='${CARGO_PROFILE_RELEASE_LTO}' \\"
fi
if [[ "${cmd}" == "miri" ]] && [[ -n "${MIRIFLAGS:-}" ]]; then
echo "+ MIRIFLAGS='${MIRIFLAGS}' \\"
fi
if [[ -n "${TS:-}" ]]; then
x "${cargo}" "$@" 2>&1 | "${TS}" -i '%.s '
x "${cargo}" ${pre_args[@]+"${pre_args[@]}"} "$@" 2>&1 | "${TS}" -i '%.s '
else
x "${cargo}" "$@"
x "${cargo}" ${pre_args[@]+"${pre_args[@]}"} "$@"
fi
echo
}
Expand All @@ -48,6 +52,13 @@ if [[ "${1:-}" == "+"* ]]; then
pre_args+=("$1")
shift
fi
cmd="test"
case "${1:-}" in
build | miri | valgrind)
cmd="$1"
shift
;;
esac
target=''
build_std=''
tests=()
Expand Down Expand Up @@ -125,47 +136,71 @@ if [[ -n "${target}" ]]; then
fi
fi
fi
args+=(
--all-features
--workspace --exclude bench --exclude portable-atomic-internal-codegen
)
args+=(--all-features)
case "${cmd}" in
build) ;;
*) args+=(--workspace --exclude bench --exclude portable-atomic-internal-codegen) ;;
esac
target="${target:-"${host}"}"
target_lower="${target//-/_}"
target_lower="${target_lower//./_}"
target_upper="$(tr '[:lower:]' '[:upper:]' <<<"${target_lower}")"
randomize_layout=' -Z randomize-layout'

if [[ -n "${VALGRIND:-}" ]]; then
export "CARGO_TARGET_${target_upper}_RUNNER"="${VALGRIND} -v --error-exitcode=1 --error-limit=no --leak-check=full --show-leak-kinds=all --track-origins=yes --fair-sched=yes"
export RUSTFLAGS="${RUSTFLAGS:-} --cfg valgrind"
export RUSTDOCFLAGS="${RUSTDOCFLAGS:-} --cfg valgrind"
# doctest on Valgrind is very slow
if [[ ${#tests[@]} -eq 0 ]]; then
tests=(--tests)
fi
fi
case "${cmd}" in
build)
TS=''
args+=(--no-run)
x_cargo test ${cargo_options[@]+"${cargo_options[@]}"} "${args[@]}" >&2
binary_path=$(
"${cargo}" ${pre_args[@]+"${pre_args[@]}"} test ${cargo_options[@]+"${cargo_options[@]}"} "${args[@]}" -q --message-format=json \
| jq -r "select(.manifest_path == \"$(cargo ${pre_args[@]+"${pre_args[@]}"} locate-project --message-format=plain)\") | select(.executable != null) | .executable"
)
echo "${binary_path}"
exit 0
;;
miri)
export MIRIFLAGS='-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-retag-fields -Zmiri-disable-isolation'
export RUSTFLAGS="${RUSTFLAGS:-}${randomize_layout}"
export RUSTDOCFLAGS="${RUSTDOCFLAGS:-}${randomize_layout}"
export QUICKCHECK_TESTS=10
x_cargo miri test ${cargo_options[@]+"${cargo_options[@]}"} "${args[@]}" ${rest_cargo_options[@]+"${rest_cargo_options[@]}"}
exit 0
;;
valgrind)
export "CARGO_TARGET_${target_upper}_RUNNER"="valgrind -v --error-exitcode=1 --error-limit=no --leak-check=full --show-leak-kinds=all --track-origins=yes --fair-sched=yes"
export RUSTFLAGS="${RUSTFLAGS:-} --cfg valgrind"
export RUSTDOCFLAGS="${RUSTDOCFLAGS:-} --cfg valgrind"
# doctest on Valgrind is very slow
if [[ ${#tests[@]} -eq 0 ]]; then
tests=(--tests)
fi
;;
test) ;;
*) bail "unrecognized command '${cmd}'" ;;
esac

run() {
if [[ "${RUSTFLAGS:-}" == *"-Z sanitizer="* ]] || [[ "${RUSTFLAGS:-}" == *"-Zsanitizer="* ]]; then
# doctest with debug build on Sanitizer is slow
x_cargo ${pre_args[@]+"${pre_args[@]}"} test --tests "$@"
x_cargo test --tests "$@"
else
x_cargo ${pre_args[@]+"${pre_args[@]}"} test ${tests[@]+"${tests[@]}"} "$@"
x_cargo test ${tests[@]+"${tests[@]}"} "$@"
fi

# release mode + doctests is slow on some platforms (probably related to the fact that they compile binaries for each example)
if [[ "${RUSTFLAGS:-}" == *"-Z sanitizer=memory"* ]] || [[ "${RUSTFLAGS:-}" == *"-Zsanitizer=memory"* ]]; then
# Workaround https://github.com/google/sanitizers/issues/558
CARGO_PROFILE_RELEASE_OPT_LEVEL=0 \
x_cargo ${pre_args[@]+"${pre_args[@]}"} test --release --tests "$@"
x_cargo test --release --tests "$@"
else
x_cargo ${pre_args[@]+"${pre_args[@]}"} test --release --tests "$@"
x_cargo test --release --tests "$@"
fi

# LTO + doctests is very slow on some platforms (probably related to the fact that they compile binaries for each example)
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \
CARGO_PROFILE_RELEASE_LTO=fat \
x_cargo ${pre_args[@]+"${pre_args[@]}"} test --release --tests --target-dir target/fat-lto "$@"
x_cargo test --release --tests --target-dir target/fat-lto "$@"

# cargo-careful only supports nightly. rustc-build-sysroot doesn't work on old nightly (at least on nightly-2022-08-12 - 1.65.0-nightly).
if [[ "${rustc_minor_version}" -ge 66 ]] && [[ -n "${nightly}" ]] && type -P cargo-careful &>/dev/null && [[ "${cargo}" == "cargo" ]]; then
Expand All @@ -174,9 +209,9 @@ run() {
if [[ -z "${target_flags[*]+"${target_flags[*]}"}" ]] && [[ "${target}" == *"-windows"* ]]; then
randomize_layout=''
fi
RUSTFLAGS="${RUSTFLAGS:-}${randomize_layout:-}" \
RUSTDOCFLAGS="${RUSTDOCFLAGS:-}${randomize_layout:-}" \
x_cargo ${pre_args[@]+"${pre_args[@]}"} careful test ${tests[@]+"${tests[@]}"} --target-dir target/careful "$@"
RUSTFLAGS="${RUSTFLAGS:-}${randomize_layout}" \
RUSTDOCFLAGS="${RUSTDOCFLAGS:-}${randomize_layout}" \
x_cargo careful test ${tests[@]+"${tests[@]}"} --target-dir target/careful "$@"
fi
}

Expand Down

0 comments on commit 2c9e790

Please sign in to comment.