diff --git a/.github/workflows/ci-miri.yaml b/.github/workflows/ci-miri.yaml new file mode 100644 index 0000000..c09a79b --- /dev/null +++ b/.github/workflows/ci-miri.yaml @@ -0,0 +1,82 @@ +name: Miri CI + +on: + push: + branches: + - 'master' + pull_request: + branches: + - 'master' + schedule: + - cron: '00 2 * * *' # At 02:00 UTC every day (like rustup-components-history). + +jobs: + # test-core: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-miri-setup.sh + # - name: Test + # run: bash ./ci-miri-test.sh core + + # test-alloc: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-miri-setup.sh + # - name: Test + # run: bash ./ci-miri-test.sh alloc + + # test-std: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-miri-setup.sh + # - name: Test + # run: bash ./ci-miri-test.sh std + + # test-simd: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-miri-setup.sh + # - name: Test + # run: bash ./ci-miri-test.sh simd + + # test-stdarch: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup environment + # run: bash ./ci-miri-setup.sh + # - name: Test + # run: bash ./ci-miri-test.sh stdarch + + # # Send a Zulip notification when a cron job fails + # cron-fail-notify: + # name: cronjob failure notification + # runs-on: ubuntu-latest + # needs: [test-core, test-alloc, test-std, test-simd] + # if: github.event_name == 'schedule' && (failure() || cancelled()) + # steps: + # - name: Install zulip-send + # run: pip3 install zulip + # - name: Send Zulip notification + # shell: bash + # env: + # ZULIP_BOT_EMAIL: ${{ secrets.ZULIP_BOT_EMAIL }} + # ZULIP_API_TOKEN: ${{ secrets.ZULIP_API_TOKEN }} + # run: | + # ~/.local/bin/zulip-send --stream miri --subject "Cron Job Failure (miri-test-libstd, $(date -u +%Y-%m))" \ + # --message 'Dear @*T-miri*, + + # The standard library test suite is [failing under Miri]('"https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"'). Would you mind investigating this issue? + + # Thanks in advance! + # Sincerely, + # The Miri Cronjobs Bot' \ + # --user $ZULIP_BOT_EMAIL --api-key $ZULIP_API_TOKEN --site https://rust-lang.zulipchat.com diff --git a/.github/workflows/ci-sanitizers.yaml b/.github/workflows/ci-sanitizers.yaml new file mode 100644 index 0000000..0d7e016 --- /dev/null +++ b/.github/workflows/ci-sanitizers.yaml @@ -0,0 +1,76 @@ +name: Sanitizers CI + +on: + push: + branches: + - 'master' + pull_request: + branches: + - 'master' + schedule: + - cron: '00 2 * * *' # At 02:00 UTC every day (like rustup-components-history). + +# only one target for now +env: + TARGET: x86_64-unknown-linux-gnu + RUST_BACKTRACE: full + +jobs: + enable_matrix: + strategy: + max-parallel: 10 # 30 jobs to run... + matrix: + crate: [core, alloc, std, simd, stdarch] + sanitizer: [address, memory, thread, cfi, safestack, leak] + # exclude: + # FIXME: cfi is a mix of lto, bitcode, 1-cgu, and it doesn't seem to + # even compile + # - sanitizer: cfi + # FIXME: we get some failures pretty early here + # - sanitizer: memory + # - sanitizer: leak + name: Test ${{ matrix.crate }} with ${{ matrix.sanitizer }} sanitizer + runs-on: ubuntu-latest + # continue running if other tests fail. Disable this once we get out of the + # prototype phase + if: always() + timeout-minutes: 60 + steps: + - uses: actions/checkout@v3 + - name: Setup environment + run: bash ./ci-sanitizers-setup.sh + - name: Run ${{ matrix.sanitizer }} sanitizer + # Mark everything as pass just so GH doesn't cancel on us as soon as there is a failure + run: > + ./ci-sanitizers-test.sh ${{ matrix.crate }} ${{ matrix.sanitizer }} && + echo 'good!' || + printf "::endgroup::\nfail!\n"; + mark_failure: + runs-on: ubuntu-latest + steps: + - run: sleep 2000 && echo 'that is enough time!'; exit 1 + + # Send a Zulip notification when a cron job fails + # cron-fail-notify: + # name: cronjob failure notification + # runs-on: ubuntu-latest + # needs: [test-core, test-alloc, test-std, test-simd] + # if: github.event_name == 'schedule' && (failure() || cancelled()) + # steps: + # - name: Install zulip-send + # run: pip3 install zulip + # - name: Send Zulip notification + # shell: bash + # env: + # ZULIP_BOT_EMAIL: ${{ secrets.ZULIP_BOT_EMAIL }} + # ZULIP_API_TOKEN: ${{ secrets.ZULIP_API_TOKEN }} + # run: | + # ~/.local/bin/zulip-send --stream miri --subject "Cron Job Failure (miri-test-libstd, $(date -u +%Y-%m))" \ + # --message 'Dear @*T-miri*, + + # The standard library test suite is [failing under Miri]('"https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"'). Would you mind investigating this issue? + + # Thanks in advance! + # Sincerely, + # The Miri Cronjobs Bot' \ + # --user $ZULIP_BOT_EMAIL --api-key $ZULIP_API_TOKEN --site https://rust-lang.zulipchat.com diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 0d5c3a8..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: CI - -on: - push: - branches: - - 'master' - pull_request: - branches: - - 'master' - schedule: - - cron: '00 2 * * *' # At 02:00 UTC every day (like rustup-components-history). - -jobs: - test-core: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup environment - run: bash ./ci-setup.sh - - name: Test - run: bash ./ci-test.sh core - - test-alloc: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup environment - run: bash ./ci-setup.sh - - name: Test - run: bash ./ci-test.sh alloc - - test-std: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup environment - run: bash ./ci-setup.sh - - name: Test - run: bash ./ci-test.sh std - - test-simd: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup environment - run: bash ./ci-setup.sh - - name: Test - run: bash ./ci-test.sh simd - - test-stdarch: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup environment - run: bash ./ci-setup.sh - - name: Test - run: bash ./ci-test.sh stdarch - - # Send a Zulip notification when a cron job fails - cron-fail-notify: - name: cronjob failure notification - runs-on: ubuntu-latest - needs: [test-core, test-alloc, test-std, test-simd] - if: github.event_name == 'schedule' && (failure() || cancelled()) - steps: - - name: Install zulip-send - run: pip3 install zulip - - name: Send Zulip notification - shell: bash - env: - ZULIP_BOT_EMAIL: ${{ secrets.ZULIP_BOT_EMAIL }} - ZULIP_API_TOKEN: ${{ secrets.ZULIP_API_TOKEN }} - run: | - ~/.local/bin/zulip-send --stream miri --subject "Cron Job Failure (miri-test-libstd, $(date -u +%Y-%m))" \ - --message 'Dear @*T-miri*, - - The standard library test suite is [failing under Miri]('"https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"'). Would you mind investigating this issue? - - Thanks in advance! - Sincerely, - The Miri Cronjobs Bot' \ - --user $ZULIP_BOT_EMAIL --api-key $ZULIP_API_TOKEN --site https://rust-lang.zulipchat.com diff --git a/.gitignore b/.gitignore index c6696cc..6308e1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ target Cargo.lock -rust-src-patched +rust-src-patched* library diff --git a/Cargo.toml b/Cargo.toml index acaab28..a1a21b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,15 @@ [workspace] +resolver = "2" + members = [ - "core_miri_test", - "alloc_miri_test", - "std_miri_test", + "core_run_test", + "alloc_run_test", + "std_run_test", ] exclude = [ # stdarch has its own Cargo workspace "library/stdarch", "rust-src-patched/library/stdarch", + "rust-src-patched-san/library/stdarch", ] diff --git a/alloc_miri_test/Cargo.toml b/alloc_run_test/Cargo.toml similarity index 92% rename from alloc_miri_test/Cargo.toml rename to alloc_run_test/Cargo.toml index ac870d2..6c9084a 100644 --- a/alloc_miri_test/Cargo.toml +++ b/alloc_run_test/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "alloc_miri_test" +name = "alloc_run_test" version = "0.0.0" autotests = false autobenches = false edition = "2021" [lib] -name = "alloc_miri_test" +name = "alloc_run_test" path = "../library/alloc/src/lib.rs" [features] diff --git a/ci-setup.sh b/ci-miri-setup.sh similarity index 100% rename from ci-setup.sh rename to ci-miri-setup.sh diff --git a/ci-test.sh b/ci-miri-test.sh similarity index 94% rename from ci-test.sh rename to ci-miri-test.sh index 4cc514a..6c2b64f 100644 --- a/ci-test.sh +++ b/ci-miri-test.sh @@ -5,9 +5,10 @@ DEFAULTFLAGS="-Zmiri-retag-fields -Zrandomize-layout -Zmiri-strict-provenance" # apply our patch rm -rf rust-src-patched -cp -a $(rustc --print sysroot)/lib/rustlib/src/rust/ rust-src-patched +cp -a "$(rustc --print sysroot)/lib/rustlib/src/rust/" rust-src-patched ( cd rust-src-patched && patch -f -p1 < ../rust-src.diff >/dev/null ) || ( echo "Applying rust-src.diff failed!" && exit 1 ) -export MIRI_LIB_SRC=$(pwd)/rust-src-patched/library +MIRI_LIB_SRC="$(pwd)/rust-src-patched/library" +export MIRI_LIB_SRC # run the tests (some also without validation, to exercise those code paths in Miri) case "$1" in @@ -60,13 +61,13 @@ std) echo "::group::Testing std core ($CORE on $TARGET)" MIRIFLAGS="$DEFAULTFLAGS -Zmiri-disable-isolation" \ ./run-test.sh std --target $TARGET --lib --tests \ - -- $CORE \ + -- "$CORE" \ 2>&1 | ts -i '%.s ' echo "::endgroup::" echo "::group::Testing std core docs ($CORE on $TARGET, ignore leaks)" MIRIFLAGS="$DEFAULTFLAGS -Zmiri-ignore-leaks -Zmiri-disable-isolation" \ ./run-test.sh std --target $TARGET --doc \ - -- $CORE \ + -- "$CORE" \ 2>&1 | ts -i '%.s ' echo "::endgroup::" done @@ -85,7 +86,7 @@ std) echo "::endgroup::" ;; simd) - cd $MIRI_LIB_SRC/portable-simd + cd "$MIRI_LIB_SRC/portable-simd" export RUSTFLAGS="-Ainternal_features ${RUSTFLAGS:-}" export RUSTDOCFLAGS="-Ainternal_features ${RUSTDOCFLAGS:-}" @@ -108,7 +109,7 @@ stdarch) for TARGET in x86_64-unknown-linux-gnu i686-unknown-linux-gnu; do echo "::group::Testing stdarch ($TARGET)" MIRIFLAGS="$DEFAULTFLAGS" \ - ./run-stdarch-test.sh $TARGET \ + ./miri-run-stdarch-test.sh $TARGET \ 2>&1 | ts -i '%.s ' echo "::endgroup::" done diff --git a/ci-sanitizers-setup.sh b/ci-sanitizers-setup.sh new file mode 100755 index 0000000..5fabcf0 --- /dev/null +++ b/ci-sanitizers-setup.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -eauxo pipefail + +## Shared setup code for CI jobs + +# We need 'ts' and 'llvm-symbolizer' +sudo apt-get -y install moreutils llvm +echo + +# And of course we need Rust +if [[ "$GITHUB_EVENT_NAME" == 'schedule' ]]; then + RUST_TOOLCHAIN=nightly +else + RUST_TOOLCHAIN=$(cat rust-version) +fi + +echo "Installing Rust version: $RUST_TOOLCHAIN" +rustup toolchain install "$RUST_TOOLCHAIN" --component rust-src +rustup override set "$RUST_TOOLCHAIN" diff --git a/ci-sanitizers-test.sh b/ci-sanitizers-test.sh new file mode 100755 index 0000000..68728a3 --- /dev/null +++ b/ci-sanitizers-test.sh @@ -0,0 +1,181 @@ +#!/bin/bash +set -eauxo pipefail + +# llvm-symbolizer supports v0 mangling +RUSTFLAGS="-Zrandomize-layout -Cdebuginfo=full -Csymbol-mangling-version=v0 \ + --cfg skip_slow_tests" + +# see https://github.com/google/sanitizers/wiki/AddressSanitizerFlags +# and https://github.com/google/sanitizers/wiki/SanitizerCommonFlags +asan_opts_arr=( + # catch bad global dependencies + check_initialization_order=true + # additional global checks + strict_init_order=true + detect_stack_use_after_return=true + # we don't use cstrings much but it could be easy to miss the null + strict_string_checks=true + # give a bit of a hand tracing segfaults + dump_instruction_bytes=true + # detect operations on pointers to different objects + detect_invalid_pointer_pairs=2 + # allow the allocator to return 0 (which we should generally handle well) + # rather than crashing on OOM + allocator_may_return_null=true +) + +export ASAN_OPTIONS="${ASAN_OPTIONS:-} ${asan_opts_arr[*]}" + + +if [ -z "${TARGET+x}" ]; then + echo "Env TARGET must be set" + exit 1 +fi + +if [ "$#" -ne 2 ]; then + echo "usage: TARGET=target ./this-script.sh lib-name sanitizer-name" + exit 1 +fi + +# apply our patch +rm -rf rust-src-patched-san +cp -a "$(rustc --print sysroot)/lib/rustlib/src/rust/" rust-src-patched-san +( cd rust-src-patched-san && patch -f -p1 < ../rust-src-san.diff ) || + ( echo "Applying rust-src-san.diff failed!" && exit 1 ) +LIB_SRC="$(pwd)/rust-src-patched-san/library" +export LIB_SRC + +# make sure we have symbolizer so we get useful traces +echo which llvm-symbolizer + +case "$2" in +address) + # ASAN poisons regions around allocated memory and memory that has been + # freed, then tracks all pointer use to see whether poisoned regions are + # accessed + + # FIXME: if on aarch64-{unknown}-linux-{android, gnu}, we can use `hwaddress` + # instead of `address` which should be faster. Unfortunately we probably + # don't have that in CI + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=address --cfg sanitizer=\"address\"" + ;; +hwaddress) + # see above + echo "we don't have a CI target for this yet" + exit 1 + ;; +kasan) + echo "we aren't a kernel, can't use kasan" + exit 1 + ;; +memory) + # MSAN tracks memory initialization and gives an error if it is read before + # being written. It is somewhat more fragile than other sanitizers + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=memory --cfg sanitizer=\"memory\"" + ;; +memtag) + # FIXME: alternative to MSAN with the same target restrictions as hwaddress + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=memtag --cfg sanitizer=\"memory\"" + ecbo "we don't have a CI target for this yet" + exit 1 + ;; +cfi) + # CFI needs LTO and 1CGU, seems like randomize-layout enables `embed-bitcode=no` + # which conflicts + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=cfi --cfg sanitizer=\"cfi\" \ + -Cembed-bitcode=yes -Clto -Ccodegen-units=1" + ;; +kcfi) + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=kcfi --cfg sanitizer=\"cfi\"" + ;; +safestack) + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=safestack --cfg sanitizer=\"safestack\"" + ;; +shadow-call-stack) + # FIXME: aarch64-linux-android only + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=shadow-call-stack \ + --cfg sanitizer=\"shadow-call-stack\"" + echo "we don't have a CI target for this yet" + exit 1 + ;; +leak) + # LeakSanitizer looks for memory leaks at the end. It is actually part of + # ASAN so we don't really need to run it on its own. Integration test I guess? + # https://clang.llvm.org/docs/AddressSanitizer.html#id8 + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=leak --cfg sanitizer=\"leak\"" + ;; +thread) + RUSTFLAGS="${RUSTFLAGS} -Zsanitizer=thread --cfg sanitizer=\"thread\"" + ;; +*) + echo "unknown sanitizer $2" + exit 1 +esac + +echo "Running tests with on target $TARGET with flags '$RUSTFLAGS'" + +# run the tests (some also without validation, to exercise those code paths in Miri) +case "$1" in +core) + echo "::group::Testing core" + ./sanitizers-run-test.sh core --target "$TARGET" --lib --tests \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + + echo "::group::Testing core docs" && echo + ./sanitizers-run-test.sh core --target "$TARGET" --doc \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + ;; +alloc) + echo "::group::Testing alloc" + ./sanitizers-run-test.sh alloc --target "$TARGET" --lib --tests \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + + echo "::group::Testing alloc docs" + ./sanitizers-run-test.sh alloc --target "$TARGET" --doc \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + ;; +std) + # Modules that we skip entirely, because they need a lot of shims we don't support. + # SKIP="fs:: net:: process:: sys:: sys_common::net::" + # Core modules, that we are testing on a bunch of targets. + # These are the most OS-specific (among the modules we do not skip). + # CORE="time:: sync:: thread:: env::" + + echo "::group::Testing std" + ./sanitizers-run-test.sh std --target "$TARGET" --lib --tests -- \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + + echo "::group::Testing std docs" + ./sanitizers-run-test.sh std --target "$TARGET" --doc -- \ + 2>&1 | ts -i '%.s ' + echo "::endgroup::" + + # "sleep" has a thread leak that we have to ignore + ;; +simd) + cd "$LIB_SRC/portable-simd" + export RUSTFLAGS="-Ainternal_features ${RUSTFLAGS}" + export RUSTDOCFLAGS="-Ainternal_features ${RUSTDOCFLAGS:-}" + + echo "::group::Testing portable-simd" + cargo test --lib --target "$TARGET" --tests -- 2>&1 | ts -i '%.s ' + echo "::endgroup::" + + echo "::group::Testing portable-simd docs" + cargo test --doc --target "$TARGET" 2>&1 | ts -i '%.s ' + echo "::endgroup::" + ;; +stdarch) + echo "::group::Testing stdarch" + ./sanitizers-run-stdarch-test.sh "$TARGET" 2>&1 | ts -i '%.s ' + echo "::endgroup::" + ;; +*) + echo "Unknown command" + exit 1 +esac diff --git a/core_miri_test/Cargo.toml b/core_run_test/Cargo.toml similarity index 93% rename from core_miri_test/Cargo.toml rename to core_run_test/Cargo.toml index 3188dea..aeadb7b 100644 --- a/core_miri_test/Cargo.toml +++ b/core_run_test/Cargo.toml @@ -1,13 +1,13 @@ [package] authors = ["The Rust Project Developers"] -name = "core_miri_test" +name = "core_run_test" version = "0.0.0" autotests = false autobenches = false edition = "2021" [lib] -name = "core_miri_test" +name = "core_run_test" path = "../library/core/src/lib.rs" test = false bench = false diff --git a/run-stdarch-test.sh b/miri-run-stdarch-test.sh similarity index 98% rename from run-stdarch-test.sh rename to miri-run-stdarch-test.sh index f978302..a22f913 100755 --- a/run-stdarch-test.sh +++ b/miri-run-stdarch-test.sh @@ -58,7 +58,7 @@ export STDARCH_TEST_EVERYTHING=1 # Needed to pass the STDARCH_TEST_EVERYTHING environment variable export MIRIFLAGS="${MIRIFLAGS:-} -Zmiri-disable-isolation" -cd $MIRI_LIB_SRC/stdarch +cd "$MIRI_LIB_SRC/stdarch" cargo miri test \ --target "$TARGET" \ --manifest-path=crates/core_arch/Cargo.toml \ diff --git a/run-test.sh b/miri-run-test.sh similarity index 100% rename from run-test.sh rename to miri-run-test.sh diff --git a/rust-src-san.diff b/rust-src-san.diff new file mode 100644 index 0000000..68960ea --- /dev/null +++ b/rust-src-san.diff @@ -0,0 +1,71 @@ +diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs +index cd3648214a4..c16d3451da5 100644 +--- a/library/alloc/src/lib.rs ++++ b/library/alloc/src/lib.rs +@@ -138,6 +138,7 @@ + #![feature(maybe_uninit_slice)] + #![feature(maybe_uninit_uninit_array)] + #![feature(maybe_uninit_uninit_array_transpose)] ++#![feature(no_sanitize)] + #![feature(pattern)] + #![feature(pointer_byte_offsets)] + #![feature(ptr_addr_eq)] +diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs +index d44dcfbf673..af08cb46ea9 100644 +--- a/library/alloc/tests/vec.rs ++++ b/library/alloc/tests/vec.rs +@@ -1636,6 +1636,8 @@ fn test_reserve_exact() { + } + + #[test] ++// ASAN throws an error for requesting max allocation size ++#[no_sanitize(address, memory)] + #[cfg_attr(miri, ignore)] // Miri does not support signalling OOM + #[cfg_attr(target_os = "android", ignore)] // Android used in CI has a broken dlmalloc + fn test_try_reserve() { +diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs +index 865e702b5c2..7e4eb6d524e 100644 +--- a/library/core/tests/slice.rs ++++ b/library/core/tests/slice.rs +@@ -1877,7 +1877,7 @@ fn sort_unstable() { + + #[test] + #[cfg(not(target_arch = "wasm32"))] +-#[cfg_attr(miri, ignore)] // Miri is too slow ++#[cfg_attr(any(miri, skip_slow_tests), ignore)] // Miri is too slow + fn select_nth_unstable() { + use core::cmp::Ordering::{Equal, Greater, Less}; + use rand::seq::SliceRandom; +@@ -2562,18 +2562,19 @@ fn $test_name() { + (take_last_mut_empty, (), None, &mut []), + } + +-#[cfg(not(miri))] // unused in Miri ++#[cfg(not(any(miri, skip_slow_tests)))] // not used if the below test macro is disabled + const EMPTY_MAX: &'static [()] = &[(); usize::MAX]; + + // can't be a constant due to const mutability rules +-#[cfg(not(miri))] // unused in Miri ++#[cfg(not(any(miri, skip_slow_tests)))] // not used if the below test macro is disabled + macro_rules! empty_max_mut { + () => { + &mut [(); usize::MAX] as _ + }; + } + +-#[cfg(not(miri))] // Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) ++// Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) ++#[cfg(not(any(miri, skip_slow_tests)))] + take_tests! { + slice: &[(); usize::MAX], method: take, + (take_in_bounds_max_range_to, (..usize::MAX), Some(EMPTY_MAX), &[(); 0]), +@@ -2581,7 +2582,8 @@ macro_rules! empty_max_mut { + (take_in_bounds_max_range_from, (usize::MAX..), Some(&[] as _), EMPTY_MAX), + } + +-#[cfg(not(miri))] // Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) ++// Comparing usize::MAX many elements takes forever in Miri (and in rustc without optimizations) ++#[cfg(not(any(miri, skip_slow_tests)))] + take_tests! { + slice: &mut [(); usize::MAX], method: take_mut, + (take_mut_in_bounds_max_range_to, (..usize::MAX), Some(empty_max_mut!()), &mut [(); 0]), diff --git a/sanitizers-run-stdarch-test.sh b/sanitizers-run-stdarch-test.sh new file mode 100755 index 0000000..8777d7a --- /dev/null +++ b/sanitizers-run-stdarch-test.sh @@ -0,0 +1,63 @@ +#!/bin/bash +set -eauxo pipefail + +## Run stdarch test suite with sanitizers. +## Usage: +## ./run-test.sh TARGET +## Environment variables: +## LIB_SRC: The path to the Rust library directory (`library`). +## RUSTFLAGS: rustc flags (optional) +## MIRIFLAGS: Miri flags (optional) + +if [ $# -ne 1 ]; then + echo "Usage: $0 TARGET" + exit 1 +fi + +export TARGET="$1" + +case "$TARGET" in +i586-*|i686-*|x86_64-*) + RUSTFLAGS="$RUSTFLAGS -C target-feature=+ssse3" + # TEST_ARGS=( + # core_arch::x86::{sse,sse2,sse3,ssse3}:: + # core_arch::x86_64::{sse,sse2}:: + # # FIXME add `#[cfg_attr(miri, ignore)]` to those tests in stdarch + # # These are nontemporal stores, fences, and CSR (FP env status register) accesses + # --skip test_mm_comieq_ss_vs_ucomieq_ss + # --skip test_mm_getcsr_setcsr_1 + # --skip test_mm_getcsr_setcsr_2 + # --skip test_mm_getcsr_setcsr_underflow + # --skip test_mm_sfence + # --skip test_mm_stream_ps + # --skip test_mm_clflush + # --skip test_mm_lfence + # --skip test_mm_maskmoveu_si128 + # --skip test_mm_mfence + # --skip test_mm_stream_pd + # --skip test_mm_stream_si128 + # --skip test_mm_stream_si32 + # --skip test_mm_stream_si64 + # # FIXME fix those in stdarch + # --skip test_mm_rcp_ss # __m128(0.24997461, 13.0, 16.0, 100.0) != __m128(0.24993896, 13.0, 16.0, 100.0) + # --skip test_mm_store1_ps # attempt to subtract with overflow + # --skip test_mm_store_ps # attempt to subtract with overflow + # --skip test_mm_storer_ps # attempt to subtract with overflow + # ) + ;; +*) + echo "Unknown target $TARGET" + exit 1 +esac + +export RUSTFLAGS="$RUSTFLAGS -Ainternal_features" + +# Make sure all tested target features are enabled +export STDARCH_TEST_EVERYTHING=1 +# Needed to pass the STDARCH_TEST_EVERYTHING environment variable + +cd "$LIB_SRC/stdarch" +cargo test \ + --target "$TARGET" \ + --manifest-path=crates/core_arch/Cargo.toml \ + -- "${TEST_ARGS[@]}" diff --git a/sanitizers-run-test.sh b/sanitizers-run-test.sh new file mode 100755 index 0000000..61450c9 --- /dev/null +++ b/sanitizers-run-test.sh @@ -0,0 +1,40 @@ +#!/bin/bash +set -eauxo pipefail + +## Run a Rust libstd test suite with Miri. +## Usage: +## ./run-test.sh CRATE_NAME CARGO_TEST_ARGS +## Environment variables: +## LIB_SRC: The path to the Rust library directory (`library`). +## Defaults to `$(rustc --print sysroot)/lib/rustlib/src/rust/library`. + +CRATE=${1:-} +if [[ -z "$CRATE" ]]; then + echo "Usage: $0 CRATE_NAME" + exit 1 +fi +shift + +# compute the library directory +LIB_SRC=${LIB_SRC:-$(rustc --print sysroot)/lib/rustlib/src/rust/library} +if ! test -d "$LIB_SRC/core"; then + echo "Rust source dir ($LIB_SRC) does not contain a 'core' subdirectory." + echo "Set LIB_SRC to the Rust source directory, or install the rust-src component." + exit 1 +fi +# macOS does not have a useful readlink/realpath so we have to use Python instead... +LIB_SRC=$(python3 -c 'import os, sys; print(os.path.realpath(sys.argv[1]))' "$LIB_SRC") +export LIB_SRC + +# update symlink +rm -f library +ln -s "$LIB_SRC" library + +# use the rust-src lockfile +cp "$LIB_SRC/../Cargo.lock" Cargo.lock + +echo "running test with RUSTFLAGS ${RUSTFLAGS}" + +# run test +cd "./${CRATE}_run_test" +cargo test -vvv "$@" diff --git a/std_miri_test/Cargo.toml b/std_run_test/Cargo.toml similarity index 96% rename from std_miri_test/Cargo.toml rename to std_run_test/Cargo.toml index 2240c34..c45eb7e 100644 --- a/std_miri_test/Cargo.toml +++ b/std_run_test/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "std_miri_test" +name = "std_run_test" version = "0.0.0" license = "MIT OR Apache-2.0" repository = "https://github.com/rust-lang/rust.git" @@ -10,7 +10,7 @@ edition = "2021" build = "../library/std/build.rs" [lib] -name = "std_miri_test" +name = "std_run_test" path = "../library/std/src/lib.rs" [dependencies]