From e0c4e5bbf51ebe8552cdc7551b1c02b81cee017f Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 22 Nov 2024 20:43:16 -0500 Subject: [PATCH 1/4] ci: Reduce redundancy in `run.sh` and run tests in the `libc` crate We haven't been running any tests associated with the `libc` crate, make sure we do this here. Also simplify some redundant things in the script. --- ci/run.sh | 49 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/ci/run.sh b/ci/run.sh index 22b356a6425b1..a8fdd1ed3c067 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -9,6 +9,8 @@ mirrors_url="https://ci-mirrors.rust-lang.org/libc" target="$1" +export RUST_BACKTRACE="${RUST_BACKTRACE:-1}" + # If we're going to run tests inside of a qemu image, then we don't need any of # the scripts below. Instead, download the image, prepare a filesystem which has # the current state of this repository, and then run the image. @@ -78,6 +80,14 @@ if [ -n "${QEMU:-}" ]; then exec grep -E "^(PASSED)|(test result: ok)" "${CARGO_TARGET_DIR}/out.log" fi +cmd="cargo test --target $target ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"}" + +# Run tests in the `libc` crate +$cmd + +# Everything else is in `libc-test` +cmd="$cmd --manifest-path libc-test/Cargo.toml" + if [ "$target" = "s390x-unknown-linux-gnu" ]; then # FIXME: s390x-unknown-linux-gnu often fails to test due to timeout, # so we retry this N times. @@ -86,31 +96,17 @@ if [ "$target" = "s390x-unknown-linux-gnu" ]; then passed=0 until [ $n -ge $N ]; do if [ "$passed" = "0" ]; then - if cargo test \ - --no-default-features \ - --manifest-path libc-test/Cargo.toml \ - --target "$target" \ - ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"} - then + if $cmd --no-default-features; then passed=$((passed+1)) continue fi elif [ "$passed" = "1" ]; then - if cargo test \ - --manifest-path libc-test/Cargo.toml \ - --target "$target" \ - ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"} - then + if $cmd; then passed=$((passed+1)) continue fi elif [ "$passed" = "2" ]; then - if cargo test \ - --features extra_traits \ - --manifest-path libc-test/Cargo.toml \ - --target "$target" \ - ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"} - then + if $cmd --features extra_traits; then break fi fi @@ -118,20 +114,7 @@ if [ "$target" = "s390x-unknown-linux-gnu" ]; then sleep 1 done else - cargo test \ - --no-default-features \ - --manifest-path libc-test/Cargo.toml \ - --target "$target" \ - ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"} - - cargo test \ - --manifest-path libc-test/Cargo.toml \ - --target "$target" \ - ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"} - - RUST_BACKTRACE=1 cargo test \ - --features extra_traits \ - --manifest-path libc-test/Cargo.toml \ - --target "$target" \ - ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"} + $cmd --no-default-features + $cmd + $cmd --features extra_traits fi From 0304ed535e94eb81f1ea5931c12f57ad95bb69ee Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 22 Nov 2024 20:46:20 -0500 Subject: [PATCH 2/4] Add a test that the `const extern fn` macro works By default, any functions defined in this macro (such as `CMSG_SPACE`) should be `const`. --- tests/const_fn.rs | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/const_fn.rs diff --git a/tests/const_fn.rs b/tests/const_fn.rs new file mode 100644 index 0000000000000..d9b41b8073c70 --- /dev/null +++ b/tests/const_fn.rs @@ -0,0 +1,3 @@ +#[cfg(target_os = "linux")] +const _FOO: libc::c_uint = unsafe { libc::CMSG_SPACE(1) }; +//^ if CMSG_SPACE is not const, this will fail to compile From f5fdb565fa01c7c6e3bcecf778a31011848e6246 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 22 Nov 2024 21:21:26 -0500 Subject: [PATCH 3/4] ci: Skip unit tests on some platforms For some reason, running unit tests in CI gives the following on Android: ```text 2024-11-23T02:17:49.1406378Z Running unittests src/lib.rs (target/i686-linux-android/debug/deps/libc-79430fca1af8b7ec) 2024-11-23T02:17:49.1432206Z * daemon not running; starting now at tcp:5037 2024-11-23T02:17:52.1460169Z * daemon started successfully 2024-11-23T02:18:00.1454112Z adb: error: failed to copy '/checkout/target/i686-linux-android/debug/deps/libc-79430fca1af8b7ec' to '/data/local/tmp/libc-79430fca1af8b7ec': remote secure_mkdirs failed: Read-only file system 2024-11-23T02:18:00.1457084Z /checkout/target/i686-linux-android/debug/deps/libc-79430fca1af8b7ec: 1 file pushed, 0 skipped. 19.3 MB/s (5418952 bytes in 0.267s) 2024-11-23T02:18:00.3757282Z thread 'main' panicked at /tmp/runtest.rs:26:5: 2024-11-23T02:18:00.3758028Z assertion failed: status.success() 2024-11-23T02:18:00.3758589Z stack backtrace: 2024-11-23T02:18:00.3810307Z 0: rust_begin_unwind 2024-11-23T02:18:00.3811230Z at /rustc/a47555110cf09b3ed59811d9b02235443e76a595/library/std/src/panicking.rs:665:5 2024-11-23T02:18:00.3812225Z 1: core::panicking::panic_fmt 2024-11-23T02:18:00.3813089Z at /rustc/a47555110cf09b3ed59811d9b02235443e76a595/library/core/src/panicking.rs:76:14 2024-11-23T02:18:00.3814034Z 2: core::panicking::panic 2024-11-23T02:18:00.3814860Z at /rustc/a47555110cf09b3ed59811d9b02235443e76a595/library/core/src/panicking.rs:148:5 2024-11-23T02:18:00.3815756Z 3: runtest::main 2024-11-23T02:18:00.3816545Z 4: core::ops::function::FnOnce::call_once 2024-11-23T02:18:00.3817848Z note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. 2024-11-23T02:18:00.3822763Z error: test failed, to rerun pass `--lib` ``` And on s390x: ``` + grep -Ev ^\[ KASLR disabled: CPU has no PRNG /prog: /lib/s390x-linux-gnu/libm.so.6: version `GLIBC_2.38' not found (required by /prog) + grep -E (PASSED)|(test result: ok) output /prog: /lib/s390x-linux-gnu/libc.so.6: version `GLIBC_2.39' not found (required by /prog) error: test failed, to rerun pass `--lib` ``` For now, don't run unit tests on these platforms. --- ci/run.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ci/run.sh b/ci/run.sh index a8fdd1ed3c067..5ac4070d928aa 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -83,7 +83,13 @@ fi cmd="cargo test --target $target ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"}" # Run tests in the `libc` crate -$cmd +case "$target" in + # FIXME(android): unit tests fail to start on Android + # FIXME(s390x): unit tests fail to locate glibc + *android*) ;; + *s390x*) ;; + *) $cmd +esac # Everything else is in `libc-test` cmd="$cmd --manifest-path libc-test/Cargo.toml" From 19e9e6ade3a9fe8d077ca0e2643bae7daa26005b Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 22 Nov 2024 20:46:24 -0500 Subject: [PATCH 4/4] fix: make sure the `const-extern-fn` feature is enabled This was dropped in fa554bc4f8 on `main` and 674cc1f47f on `libc-0.2` ("Drop the libc_const_extern_fn conditional"). Unfortunately, this meant that functions were incorrectly never getting marked `const`, which showed up with `CMSG_SPACE` [1]. Instead of the fix here, I attempted to just use `cfg(not(libc_ctest))` instead of a Cargo feature to enable `const` extern functions; however, this seemed extremely problematic with `ctest` for some reason [2]. Instead, leave the feature as-is and just make it enabled by default. Fixes: https://github.com/rust-lang/libc/issues/4115 [1] [2]: https://github.com/rust-lang/libc/pull/4134 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9deb2ac564e9a..107ee46ea3909 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -135,7 +135,7 @@ cargo-args = ["-Zbuild-std=core"] rustc-std-workspace-core = { version = "1.0.0", optional = true } [features] -default = ["std"] +default = ["const-extern-fn", "std"] std = [] rustc-dep-of-std = ["rustc-std-workspace-core"] extra_traits = []