Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 77 additions & 71 deletions .github/workflows/openbsd.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -22,11 +24,14 @@
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
Expand All @@ -46,9 +51,6 @@
- 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.
Expand All @@ -60,49 +62,82 @@
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with clippy and tests in the same job, a clippy warning now skips all the tests, is it intended?

This comment was marked as outdated.

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to continue cargo test when clippy failed (and set FAULT=1)? I think it just eats CI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On freebsd.yml, separating clippy increases build time 30 sec+. openbsd.yml would increase much more due to build-std.

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:
Comment thread
oech3 marked this conversation as resolved.
Resolved
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
Comment thread
oech3 marked this conversation as resolved.
Resolved
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why copy it to /tmp instead of pointing UUTESTS_BINARY_PATH at target/ directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

direct path did not work.

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
Comment thread
oech3 marked this conversation as resolved.
Resolved
# 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: <https://github.com/rust-lang/rustup/pull/2783>
# * 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}"
Expand All @@ -120,52 +155,23 @@
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"

Check warning on line 174 in .github/workflows/openbsd.yml

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'CARGOFLAGS' (file:'.github/workflows/openbsd.yml', line:174)
make test MULTICALL=y UTILS=cksum || FAULT=1
if (test -n "\$FAULT"); then exit 1 ; fi
EOF
7 changes: 3 additions & 4 deletions tests/by-util/test_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 9 additions & 6 deletions tests/uutests/src/lib/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,15 @@ fn find_tests_binary() -> Option<PathBuf> {
/// 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<PathBuf> {
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`].
Expand Down
Loading