Add more fcntl and seal constants for Android/Linux

We now create an additional binary `linux_fcntl` for testing this
since there are header conflicts when including all necessary headers.
This binary is run on all platforms even though it's empty on all non-
Android/non-Linux platforms.

Testing has been switched from a custom binary to using a runner-less
test (or pair of tests). This means that for local development a simple
`cd libc-test && cargo test` will run all the tests. CI has also been
updated here to reflect that.
This commit is contained in:
Bryant Mairs 2017-08-10 10:33:19 -07:00
parent 13478d0929
commit 2e11d9e14c
9 changed files with 100 additions and 59 deletions

View File

@ -93,7 +93,7 @@ With that in mind, the steps for adding a new API are:
We have two automated tests running on [Travis](https://travis-ci.org/rust-lang/libc):
1. [`libc-test`](https://github.com/alexcrichton/ctest)
- `cd libc-test && cargo run`
- `cd libc-test && cargo test`
- Use the `skip_*()` functions in `build.rs` if you really need a workaround.
2. Style checker
- `rustc ci/style.rs && ./style src`

View File

@ -24,7 +24,7 @@ build: false
test_script:
- cargo test --target %TARGET%
- cargo run --manifest-path libc-test/Cargo.toml --target %TARGET%
- cargo test --manifest-path libc-test/Cargo.toml --target %TARGET%
cache:
- target

View File

@ -70,12 +70,14 @@ fi
case "$TARGET" in
*-apple-ios)
cargo rustc --manifest-path libc-test/Cargo.toml --target $TARGET -- \
-C link-args=-mios-simulator-version-min=7.0
cargo rustc --manifest-path libc-test/Cargo.toml --target $TARGET \
--test main -- -C link-args=-mios-simulator-version-min=7.0
cargo rustc --manifest-path libc-test/Cargo.toml --target $TARGET \
--test linux-fcntl -- -C link-args=-mios-simulator-version-min=7.0
;;
*)
cargo build --manifest-path libc-test/Cargo.toml --target $TARGET
cargo build --manifest-path libc-test/Cargo.toml --target $TARGET --tests
;;
esac
@ -95,61 +97,81 @@ case "$TARGET" in
fi
emulator @$arch -no-window $accel &
adb wait-for-device
adb push $CARGO_TARGET_DIR/$TARGET/debug/libc-test /data/local/tmp/libc-test
adb shell /data/local/tmp/libc-test 2>&1 | tee /tmp/out
adb push $CARGO_TARGET_DIR/$TARGET/debug/main-* /data/local/tmp/main
adb shell /data/local/tmp/main 2>&1 | tee /tmp/out
grep "^PASSED .* tests" /tmp/out
adb push $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-* /data/local/tmp/linux_fcntl
adb shell /data/local/tmp/linux_fcntl 2>&1 | tee /tmp/out
grep "^PASSED .* tests" /tmp/out
;;
i386-apple-ios)
rustc -O ./ci/ios/deploy_and_run_on_ios_simulator.rs
./deploy_and_run_on_ios_simulator $CARGO_TARGET_DIR/$TARGET/debug/libc-test
./deploy_and_run_on_ios_simulator $CARGO_TARGET_DIR/$TARGET/debug/main-*
./deploy_and_run_on_ios_simulator $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
;;
x86_64-apple-ios)
rustc -O ./ci/ios/deploy_and_run_on_ios_simulator.rs
./deploy_and_run_on_ios_simulator $CARGO_TARGET_DIR/$TARGET/debug/libc-test
./deploy_and_run_on_ios_simulator $CARGO_TARGET_DIR/$TARGET/debug/main-*
./deploy_and_run_on_ios_simulator $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
;;
arm-unknown-linux-gnueabihf)
qemu-arm -L /usr/arm-linux-gnueabihf $CARGO_TARGET_DIR/$TARGET/debug/libc-test
qemu-arm -L /usr/arm-linux-gnueabihf $CARGO_TARGET_DIR/$TARGET/debug/main-*
qemu-arm -L /usr/arm-linux-gnueabihf $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
;;
mips-unknown-linux-gnu)
qemu-mips -L /usr/mips-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test
qemu-mips -L /usr/mips-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/main-*
qemu-mips -L /usr/mips-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
;;
mips64-unknown-linux-gnuabi64)
qemu-mips64 -L /usr/mips64-linux-gnuabi64 $CARGO_TARGET_DIR/$TARGET/debug/libc-test
qemu-mips64 -L /usr/mips64-linux-gnuabi64 $CARGO_TARGET_DIR/$TARGET/debug/main-*
qemu-mips64 -L /usr/mips64-linux-gnuabi64 $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
;;
mips-unknown-linux-musl)
qemu-mips -L /toolchain/staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.15 \
$CARGO_TARGET_DIR/$TARGET/debug/libc-test
$CARGO_TARGET_DIR/$TARGET/debug/main-*
qemu-mips -L /toolchain/staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.15 \
$CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
;;
mipsel-unknown-linux-musl)
qemu-mipsel -L /toolchain $CARGO_TARGET_DIR/$TARGET/debug/libc-test
qemu-mipsel -L /toolchain $CARGO_TARGET_DIR/$TARGET/debug/main-*
qemu-mipsel -L /toolchain $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
;;
powerpc-unknown-linux-gnu)
qemu-ppc -L /usr/powerpc-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test
qemu-ppc -L /usr/powerpc-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/main-*
qemu-ppc -L /usr/powerpc-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
;;
powerpc64-unknown-linux-gnu)
qemu-ppc64 -L /usr/powerpc64-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test
qemu-ppc64 -L /usr/powerpc64-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/main-*
qemu-ppc64 -L /usr/powerpc64-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
;;
aarch64-unknown-linux-gnu)
qemu-aarch64 -L /usr/aarch64-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/libc-test
qemu-aarch64 -L /usr/aarch64-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/main-*
qemu-aarch64 -L /usr/aarch64-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
;;
s390x-unknown-linux-gnu)
# TODO: in theory we should execute this, but qemu segfaults immediately :(
# qemu-s390x -L /usr/s390x-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/libc-test
# qemu-s390x -L /usr/s390x-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/main-*
# qemu-s390x -L /usr/s390x-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
;;
*-rumprun-netbsd)
rumprun-bake hw_virtio /tmp/libc-test.img $CARGO_TARGET_DIR/$TARGET/debug/libc-test
rumprun-bake hw_virtio /tmp/libc-test.img $CARGO_TARGET_DIR/$TARGET/debug/main-*
qemu-system-x86_64 -nographic -vga none -m 64 \
-kernel /tmp/libc-test.img 2>&1 | tee /tmp/out &
sleep 5
grep "^PASSED .* tests" /tmp/out
rumprun-bake hw_virtio /tmp/libc-test.img $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
qemu-system-x86_64 -nographic -vga none -m 64 \
-kernel /tmp/libc-test.img 2>&1 | tee /tmp/out &
sleep 5
@ -157,6 +179,7 @@ case "$TARGET" in
;;
*)
$CARGO_TARGET_DIR/$TARGET/debug/libc-test
$CARGO_TARGET_DIR/$TARGET/debug/main-*
$CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
;;
esac

View File

@ -9,3 +9,13 @@ libc = { path = ".." }
[build-dependencies]
ctest = "0.1"
[[test]]
name = "main"
path = "test/main.rs"
harness = false
[[test]]
name = "linux-fcntl"
path = "test/linux_fcntl.rs"
harness = false

View File

@ -468,6 +468,11 @@ fn main() {
// it's been fixed in CI.
"MADV_SOFT_OFFLINE" if mips && linux => true,
// These constants are tested in a separate test program generated below because there
// are header conflicts if we try to include the headers that define them here.
"F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => true,
"F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => true,
_ => false,
}
});
@ -641,5 +646,31 @@ fn main() {
}
});
cfg.generate("../src/lib.rs", "all.rs");
cfg.generate("../src/lib.rs", "main.rs");
// On Linux or Android also generate another script for testing linux/fcntl declarations.
// These cannot be tested normally because including both `linux/fcntl.h` and `fcntl.h`
// fails on a lot of platforms.
let mut cfg = ctest::TestGenerator::new();
cfg.skip_type(|_| true)
.skip_struct(|_| true)
.skip_fn(|_| true);
if android || linux {
// musl defines these directly in `fcntl.h`
if musl {
cfg.header("fcntl.h");
} else {
cfg.header("linux/fcntl.h");
}
cfg.skip_const(move |name| {
match name {
"F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false,
"F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => false,
_ => true,
}
});
} else {
cfg.skip_const(|_| true);
}
cfg.generate("../src/lib.rs", "linux_fcntl.rs");
}

View File

@ -0,0 +1,6 @@
#![allow(bad_style, improper_ctypes)]
extern crate libc;
use libc::*;
include!(concat!(env!("OUT_DIR"), "/linux_fcntl.rs"));

View File

@ -3,4 +3,4 @@ extern crate libc;
use libc::*;
include!(concat!(env!("OUT_DIR"), "/all.rs"));
include!(concat!(env!("OUT_DIR"), "/main.rs"));

View File

@ -69,40 +69,3 @@ macro_rules! f {
macro_rules! __item {
($i:item) => ($i)
}
#[cfg(test)]
mod tests {
cfg_if! {
if #[cfg(test)] {
use std::option::Option as Option2;
fn works1() -> Option2<u32> { Some(1) }
} else {
fn works1() -> Option<u32> { None }
}
}
cfg_if! {
if #[cfg(foo)] {
fn works2() -> bool { false }
} else if #[cfg(test)] {
fn works2() -> bool { true }
} else {
fn works2() -> bool { false }
}
}
cfg_if! {
if #[cfg(foo)] {
fn works3() -> bool { false }
} else {
fn works3() -> bool { true }
}
}
#[test]
fn it_works() {
assert!(works1().is_some());
assert!(works2());
assert!(works3());
}
}

View File

@ -212,9 +212,17 @@ pub const F_SETFL: ::c_int = 4;
pub const F_SETLEASE: ::c_int = 1024;
pub const F_GETLEASE: ::c_int = 1025;
pub const F_NOTIFY: ::c_int = 1026;
pub const F_CANCELLK: ::c_int = 1029;
pub const F_DUPFD_CLOEXEC: ::c_int = 1030;
pub const F_SETPIPE_SZ: ::c_int = 1031;
pub const F_GETPIPE_SZ: ::c_int = 1032;
pub const F_ADD_SEALS: ::c_int = 1033;
pub const F_GET_SEALS: ::c_int = 1034;
pub const F_SEAL_SEAL: ::c_int = 0x0001;
pub const F_SEAL_SHRINK: ::c_int = 0x0002;
pub const F_SEAL_GROW: ::c_int = 0x0004;
pub const F_SEAL_WRITE: ::c_int = 0x0008;
// TODO(#235): Include file sealing fcntls once we have a way to verify them.