diff --git a/.github/workflows/openbsd.yml b/.github/workflows/openbsd.yml index d062ba43826..ead9e76154a 100644 --- a/.github/workflows/openbsd.yml +++ b/.github/workflows/openbsd.yml @@ -1,11 +1,13 @@ name: OpenBSD -# spell-checker:ignore sshfs usesh vmactions taiki esac fdescfs fdesc nextest copyback logind +# spell-checker:ignore sshfs usesh vmactions taiki esac fdescfs fdesc mlugg copyback logind zigbuild env: FEATURES: "feat_Tier1,feat_require_unix" - # * style job configuration - STYLE_FAIL_ON_FAULT: true ## (bool) fail the build if a style job contains a fault (error or warning); may be overridden on a per-job basis + CARGO_INCREMENTAL: "0" + RUSTFLAGS: "-C strip=symbols" # Avoid filling disk space + RUST_BACKTRACE: "1" + RUSTC_BOOTSTRAP: "1" # use build-std on: pull_request: @@ -22,11 +24,14 @@ concurrency: cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} jobs: - style: - name: Style and Lint + clippy_test_zig: + name: clippy and test runs-on: ubuntu-latest timeout-minutes: 60 steps: + - name: Avoid no space left on device + shell: bash + run: sudo rm -rf /usr/share/dotnet /usr/local/lib/android & - uses: actions/checkout@v7.0.1 with: persist-credentials: false @@ -46,9 +51,6 @@ jobs: - uses: mlugg/setup-zig@v2.2.1 - uses: taiki-e/install-action@cargo-zigbuild - name: cargo clippy - env: - CARGO_INCREMENTAL: "0" - RUSTC_BOOTSTRAP: "1" run: | # Set linker for stdbuf. env: and -Z do not work. Override `config.toml` to avoid duplicated keys. # We don't use `aws-lc` at here. @@ -60,49 +62,82 @@ jobs: EOF UTILS=$(cargo tree --depth 1 --features ${{ env.FEATURES }} --format '{lib}' --prefix none | sed -n 's/^uu_/-p uu_/p') cargo-zigbuild clippy --target x86_64-unknown-openbsd --features ${{ env.FEATURES }} -p coreutils ${UTILS} --all-targets --tests --benches -- -D warnings + - name: prepare testing + run: | + cargo-zigbuild test --target x86_64-unknown-openbsd --no-run --features ${{ env.FEATURES }} --message-format=json \ + | jq -rs ' + [ .[] | select(.executable != null) | .executable | select(test("/coreutils$") | not) ] + | unique + | .[] + ' > tests.sh + - name: test + uses: vmactions/openbsd-vm@v1 + with: + usesh: true + sync: rsync + copyback: false + mem: 6144 + prepare: pkg_add sudo-- + run: | + ## test + set -e + # + TEST_USER=tester + REPO_NAME=${GITHUB_WORKSPACE##*/} + WORKSPACE_PARENT="/home/runner/work/${REPO_NAME}" + WORKSPACE="${WORKSPACE_PARENT}/${REPO_NAME}" + # + useradd -m -G wheel ${TEST_USER} + chown -R ${TEST_USER}:wheel /root/ "${WORKSPACE_PARENT}"/ + whoami + # Add fake host for reverse DNS lookup (needed for hostname test) + printf "10.0.2.15\topenbsd.my.domain openbsd\n" >> /etc/hosts + # + # Further work needs to be done in a sudo as we are changing users + sudo -i -u ${TEST_USER} sh << EOF + set -e + whoami + # Increase max open files (512 by default) + ulimit -n 1024 + ## Info + echo "CI='${CI}'" + echo "REPO_NAME='${REPO_NAME}'" + echo "TEST_USER='${TEST_USER}'" + echo "WORKSPACE_PARENT='${WORKSPACE_PARENT}'" + echo "WORKSPACE='${WORKSPACE}'" + env | sort + # + set +e + cd "${WORKSPACE}" + unset FAULT + cp -v target/x86_64-unknown-openbsd/debug/coreutils /tmp/coreutils + export UUTESTS_BINARY_PATH=/tmp/coreutils + while IFS= read -r bin;do + "\${bin}" || FAULT=1 # todo: retry tests (should we nextest on the VM if it failed?) + done < ./tests.sh + if (test -n "\$FAULT"); then exit 1 ; fi + EOF - test: - name: Tests + uucore_openssl: + name: uucore and openssl runs-on: ubuntu-latest timeout-minutes: 60 steps: - uses: actions/checkout@v7.0.1 with: persist-credentials: false - - name: Avoid no space left on device # shared with guest? - shell: bash - run: | - mkdir /tmp/empty - sudo rsync -a --delete /tmp/empty/ /usr/lib/jvm/ - sudo rsync -a --delete /tmp/empty/ /usr/share/dotnet/ - sudo rsync -a --delete /tmp/empty/ /usr/local/lib/android/ - - name: Prepare, build and test + - name: test uses: vmactions/openbsd-vm@v1 with: usesh: true sync: rsync copyback: false mem: 6144 - # Install rust and build dependencies - prepare: | - # Clean up disk space before installing packages - df -h - mkdir -p empty - rsync -a --delete empty/ /usr/share/relink/ - rsync -a --delete empty/ /usr/X11R6/ - rsync -a --delete empty/ /usr/share/doc/ - rsync -a --delete empty/ /usr/share/man/ - pkg_add curl gmake sudo-- rust - # Clean up package cache after installation - pkg_delete -a - df -h + prepare: pkg_add gmake sudo-- rust run: | - ## Prepare, build, and test - # implementation modelled after ref: - # * NOTE: All steps need to be run in this block, otherwise, we are operating back on the mac host + ## test set -e # - export CARGO_INCREMENTAL=0 TEST_USER=tester REPO_NAME=${GITHUB_WORKSPACE##*/} WORKSPACE_PARENT="/home/runner/work/${REPO_NAME}" @@ -120,52 +155,23 @@ jobs: whoami # Increase max open files (512 by default) ulimit -n 1024 - # todo: install nextest if official OpenBSD package was provided - # Use regular cargo test currently ## Info - echo "::group::environment" echo "CI='${CI}'" echo "REPO_NAME='${REPO_NAME}'" echo "TEST_USER='${TEST_USER}'" echo "WORKSPACE_PARENT='${WORKSPACE_PARENT}'" echo "WORKSPACE='${WORKSPACE}'" env | sort - echo "::endgroup::" - echo "::group::tooling info" - cargo -V - rustc -V - echo "::endgroup::" # - # To ensure that files are cleaned up, we don't want to exit on error set +e cd "${WORKSPACE}" unset FAULT - # openbsd is very slow. Omit duplicated cargo build and do test only - export RUST_BACKTRACE=1 - export CARGO_TERM_COLOR=always - # Avoid filling disk space - export RUSTFLAGS="-C strip=symbols" - # vendored OpenSSL takes many times to build. Use system one (LibreSSL is supported). - export OPENSSL_NO_VENDOR=1 OPENSSL_DIR=/usr - # Use cargo test since nextest might not support OpenBSD - if (test -z "\$FAULT"); then - echo "::group::cargo test (workspace)" - cargo test --features ${{ env.FEATURES }} || FAULT=1 - echo "::endgroup::" - fi - if (test -z "\$FAULT"); then - echo "::group::cargo test (uucore)" - cargo test --all-features -p uucore || FAULT=1 - echo "::endgroup::" - fi - # Test building with make - if (test -z "\$FAULT"); then - echo "::group::make MULTICALL=Y" - make MULTICALL=Y || FAULT=1 - echo "::endgroup::" - fi - # Clean to avoid to rsync back the files and free up disk space - cargo clean - # Additional cleanup to free disk space + export RUSTFLAGS="-C strip=symbols" # Avoid filling disk space + # GNUmakefile and LibreSSL cannot be covered by zig + # `--all-features` pulls `openssl` feature of uucore + export OPENSSL_NO_VENDOR=1 OPENSSL_STATIC=0 OPENSSL_DIR=/usr + cargo test --all-features -p uucore || FAULT=1 + export CARGOFLAGS="--features=openssl" + make test MULTICALL=y UTILS=cksum || FAULT=1 if (test -n "\$FAULT"); then exit 1 ; fi EOF diff --git a/tests/by-util/test_install.rs b/tests/by-util/test_install.rs index 0000e4a86d7..20767266d34 100644 --- a/tests/by-util/test_install.rs +++ b/tests/by-util/test_install.rs @@ -8,7 +8,6 @@ use rstest::rstest; use rustix::process::{getegid, geteuid}; -use std::env::current_exe; use std::fs; #[cfg(target_os = "linux")] use std::os::unix::ffi::OsStringExt; @@ -881,7 +880,7 @@ fn test_install_and_strip_with_ancestor_directories() { #[test] fn test_install_no_strip_with_program() { - let source = current_exe().unwrap(); + let source = uutests::util::get_tests_binary(); TestScenario::new(util_name!()) .ucmd() .arg("--strip-program") @@ -1007,7 +1006,7 @@ fn test_install_on_invalid_link_at_destination_and_dev_null_at_source() { fn test_install_and_strip_with_invalid_program() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; - let source = current_exe().unwrap(); + let source = uutests::util::get_tests_binary(); scene .ucmd() @@ -1044,7 +1043,7 @@ fn test_install_and_strip_with_signal_terminated_program() { fn test_install_and_strip_with_non_existent_program() { let scene = TestScenario::new(util_name!()); let at = &scene.fixtures; - let source = current_exe().unwrap(); + let source = uutests::util::get_tests_binary(); scene .ucmd() diff --git a/tests/uutests/src/lib/util.rs b/tests/uutests/src/lib/util.rs index 2d196937c1f..6fb0e06be60 100644 --- a/tests/uutests/src/lib/util.rs +++ b/tests/uutests/src/lib/util.rs @@ -99,12 +99,15 @@ fn find_tests_binary() -> Option { /// Find the binary `name` (e.g. `coreutils` or `uudoc`) the same way as /// [`get_tests_binary`], the other binaries being next to `UUTESTS_BINARY_PATH`. pub fn find_binary(name: &str) -> Option { - resolve_tests_binary( - name, - env::var_os("UUTESTS_BINARY_PATH"), - env::var_os(format!("CARGO_BIN_EXE_{name}")), - env::current_exe().ok(), - ) + let uu_bin_path = env::var_os("UUTESTS_BINARY_PATH"); + let hardcoded_exe = env::var_os(format!("CARGO_BIN_EXE_{name}")); + let cur_exe = if uu_bin_path.is_some() || hardcoded_exe.is_some() { + None + } else { + // cross built tests for openbsd panics without guarding this + env::current_exe().ok() + }; + resolve_tests_binary(name, uu_bin_path, hardcoded_exe, cur_exe) } /// Set the binary to test (default: `coreutils`), resolved by [`get_tests_binary`].