From f02eaf9153f55f31ca93b77d35f009075873d7e7 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 10 Aug 2024 14:58:13 +0200 Subject: [PATCH] add QEMU CI support --- .github/workflows/checks.yaml | 55 ++++++++++++++++++++++++++++++++- qemu-cargo-config.toml | 8 +++++ test-libz-rs-sys/src/deflate.rs | 18 +++++++++-- zlib-rs/src/deflate.rs | 14 ++++----- 4 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 qemu-cargo-config.toml diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index cd8e40d7..99867b6b 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -84,7 +84,7 @@ jobs: with: shared-key: "${{matrix.rust}}-${{matrix.target}}" - name: cargo build - run: cargo build ${{ matrix.features }} + run: cargo build --target ${{matrix.target}} ${{ matrix.features }} - name: cargo nextest # reports segfaults in a helpful way run: cargo nextest run --target ${{matrix.target}} ${{ matrix.features }} --no-fail-fast env: @@ -101,6 +101,59 @@ jobs: files: lcov.info fail_ci_if_error: false + build-qemu: + name: QEMU build & test + runs-on: "${{ matrix.os }}" + strategy: + matrix: + include: + - rust: stable + os: ubuntu-latest + features: "" + target: "s390x-unknown-linux-gnu" + gcc: "s390x-linux-gnu-gcc" + - rust: stable + os: ubuntu-latest + features: "" + target: "i686-unknown-linux-gnu" + gcc: "i686-linux-gnu-gcc" + steps: + - uses: actions/checkout@v2 + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: qemu qemu-user qemu-user-static qemu-system-s390x gcc-s390x-linux-gnu gcc-i686-linux-gnu + version: 1.0 + - name: Checkout sources + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + with: + persist-credentials: false + - name: Copy QEMU Cargo Config + run: | + mkdir -p .cargo + cp qemu-cargo-config.toml .cargo/config.toml + - name: Install toolchain + uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248 + with: + toolchain: "stable" + targets: "${{ matrix.target }}" + - name: target + run: "rustc -vV | sed -n 's|host: ||p'" + - name: Rust cache + uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 + with: + shared-key: "${{matrix.rust}}-${{matrix.target}}" + - name: Install cargo-nextest + uses: taiki-e/install-action@56ab7930c591507f833cbaed864d201386d518a8 + with: + tool: cargo-nextest + - name: cargo build + run: cargo build --target ${{matrix.target}} ${{ matrix.features }} + - name: cargo nextest # reports segfaults in a helpful way + run: cargo nextest run -p zlib-rs --target ${{matrix.target}} ${{ matrix.features }} + env: + RUST_BACKTRACE: 1 + CC: ${{matrix.gcc}} + clippy: name: Clippy strategy: diff --git a/qemu-cargo-config.toml b/qemu-cargo-config.toml new file mode 100644 index 00000000..dde46803 --- /dev/null +++ b/qemu-cargo-config.toml @@ -0,0 +1,8 @@ +# gets copied to .cargo/config.toml on CI, meant to run tests under qemu + +[target.s390x-unknown-linux-gnu] +runner = "qemu-s390x -L /usr/s390x-linux-gnu" +linker = "s390x-linux-gnu-gcc" + +[target.i686-unknown-linux-gnu] +linker = "i686-linux-gnu-gcc" diff --git a/test-libz-rs-sys/src/deflate.rs b/test-libz-rs-sys/src/deflate.rs index b15e4bee..1a4039bf 100644 --- a/test-libz-rs-sys/src/deflate.rs +++ b/test-libz-rs-sys/src/deflate.rs @@ -716,6 +716,10 @@ fn deflate_bound_gzip_header() { } #[test] +#[cfg_attr( + target_endian = "big", + ignore = "we don't support DFLTCC, which changes the bounds in zlib-ng" +)] fn test_compress_bound_windows() { let source_len = 4294967289 as core::ffi::c_ulong; @@ -726,6 +730,10 @@ fn test_compress_bound_windows() { } #[test] +#[cfg_attr( + target_endian = "big", + ignore = "we don't support DFLTCC, which changes the bounds in zlib-ng" +)] fn test_compress_bound() { ::quickcheck::quickcheck(test as fn(_) -> _); @@ -1965,17 +1973,21 @@ mod fuzz_based_tests { const LCET10: &str = include_str!("test-data/lcet10.txt"); #[test] - #[cfg_attr(miri, ignore)] + #[cfg_attr( + not(any(target_arch = "x86_64", target_arch = "aarch64")), + ignore = "https://github.com/memorysafety/zlib-rs/issues/91" + )] + #[cfg_attr(miri, ignore = "too slow")] fn compress_lcet10() { fuzz_based_test(LCET10.as_bytes(), DeflateConfig::default(), &[]) } #[test] #[cfg_attr( - target_arch = "aarch64", + not(target_arch = "x86_64"), ignore = "https://github.com/memorysafety/zlib-rs/issues/91" )] - #[cfg_attr(miri, ignore)] + #[cfg_attr(miri, ignore = "too slow")] fn compress_paper_100k() { let mut config = DeflateConfig::default(); diff --git a/zlib-rs/src/deflate.rs b/zlib-rs/src/deflate.rs index 16af1b56..18b92b73 100644 --- a/zlib-rs/src/deflate.rs +++ b/zlib-rs/src/deflate.rs @@ -4059,24 +4059,24 @@ mod test { strategy: Strategy::Default, }; - let _x86_64 = [ + let x86 = [ 24, 149, 99, 96, 96, 96, 96, 208, 6, 17, 112, 138, 129, 193, 128, 1, 29, 24, 50, 208, 1, 200, 146, 169, 79, 24, 74, 59, 96, 147, 52, 71, 22, 70, 246, 88, 26, 94, 80, 128, 83, 6, 162, 219, 144, 76, 183, 210, 5, 8, 67, 105, 7, 108, 146, 230, 216, 133, 145, 129, 22, 3, 3, 131, 17, 3, 0, 3, 228, 25, 128, ]; - let _aarch64 = [ + let other = [ 24, 149, 99, 96, 96, 96, 96, 208, 6, 17, 112, 138, 129, 193, 128, 1, 29, 24, 50, 208, 1, 200, 146, 169, 79, 24, 74, 59, 96, 147, 52, 71, 22, 70, 246, 88, 26, 94, 80, 128, 83, 6, 162, 219, 144, 76, 183, 210, 5, 8, 67, 105, 36, 159, 35, 128, 57, 118, 97, 100, 160, 197, 192, 192, 96, 196, 0, 0, 3, 228, 25, 128, ]; - #[cfg(target_arch = "x86_64")] - fuzz_based_test(&input, config, &_x86_64); - - #[cfg(target_arch = "aarch64")] - fuzz_based_test(&input, config, &_aarch64); + if cfg!(any(target_arch = "x86_64", target_arch = "x86")) { + fuzz_based_test(&input, config, &x86); + } else { + fuzz_based_test(&input, config, &other); + } } }