Skip to content

Commit 1807196

Browse files
committed
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. This also means a change to running the test suite locally in that the test binary to run must now be specified.
1 parent 09d9209 commit 1807196

File tree

9 files changed

+72
-17
lines changed

9 files changed

+72
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ With that in mind, the steps for adding a new API are:
9393
We have two automated tests running on [Travis](https://travis-ci.org/rust-lang/libc):
9494

9595
1. [`libc-test`](https://github.com/alexcrichton/ctest)
96-
- `cd libc-test && cargo run`
96+
- `cd libc-test && cargo run --bin main && cargo run --bin linux_fcntl`
9797
- Use the `skip_*()` functions in `build.rs` if you really need a workaround.
9898
2. Style checker
9999
- `rustc ci/style.rs && ./style src`

appveyor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ build: false
2424

2525
test_script:
2626
- cargo test --target %TARGET%
27-
- cargo run --manifest-path libc-test/Cargo.toml --target %TARGET%
27+
- cargo run --manifest-path libc-test/Cargo.toml --target %TARGET% --bin main
28+
- cargo run --manifest-path libc-test/Cargo.toml --target %TARGET% --bin linux_fcntl
2829

2930
cache:
3031
- target

ci/run.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ fi
9595

9696
case "$TARGET" in
9797
*-apple-ios)
98-
cargo rustc --manifest-path libc-test/Cargo.toml --target $TARGET -- \
99-
-C link-args=-mios-simulator-version-min=7.0
98+
cargo rustc --manifest-path libc-test/Cargo.toml --target $TARGET \
99+
--bin main -- -C link-args=-mios-simulator-version-min=7.0
100+
cargo rustc --manifest-path libc-test/Cargo.toml --target $TARGET \
101+
--bin linux_fcntl -- -C link-args=-mios-simulator-version-min=7.0
100102
;;
101103

102104
*)
@@ -123,54 +125,69 @@ case "$TARGET" in
123125
adb push $CARGO_TARGET_DIR/$TARGET/debug/libc-test /data/local/tmp/libc-test
124126
adb shell /data/local/tmp/libc-test 2>&1 | tee /tmp/out
125127
grep "^PASSED .* tests" /tmp/out
128+
adb push $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl /data/local/tmp/linux_fcntl
129+
adb shell /data/local/tmp/linux_fcntl 2>&1 | tee /tmp/out
130+
grep "^PASSED .* tests" /tmp/out
126131
;;
127132

128133
i386-apple-ios)
129134
rustc -O ./ci/ios/deploy_and_run_on_ios_simulator.rs
130135
./deploy_and_run_on_ios_simulator $CARGO_TARGET_DIR/$TARGET/debug/libc-test
136+
./deploy_and_run_on_ios_simulator $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
131137
;;
132138

133139
x86_64-apple-ios)
134140
rustc -O ./ci/ios/deploy_and_run_on_ios_simulator.rs
135141
./deploy_and_run_on_ios_simulator $CARGO_TARGET_DIR/$TARGET/debug/libc-test
142+
./deploy_and_run_on_ios_simulator $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
136143
;;
137144

138145
arm-unknown-linux-gnueabihf)
139146
qemu-arm -L /usr/arm-linux-gnueabihf $CARGO_TARGET_DIR/$TARGET/debug/libc-test
147+
qemu-arm -L /usr/arm-linux-gnueabihf $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
140148
;;
141149

142150
mips-unknown-linux-gnu)
143151
qemu-mips -L /usr/mips-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test
152+
qemu-mips -L /usr/mips-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
144153
;;
145154

146155
mips64-unknown-linux-gnuabi64)
147156
qemu-mips64 -L /usr/mips64-linux-gnuabi64 $CARGO_TARGET_DIR/$TARGET/debug/libc-test
157+
qemu-mips64 -L /usr/mips64-linux-gnuabi64 $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
148158
;;
149159

150160
mips-unknown-linux-musl)
151161
qemu-mips -L /toolchain/staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.15 \
152162
$CARGO_TARGET_DIR/$TARGET/debug/libc-test
163+
qemu-mips -L /toolchain/staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.15 \
164+
$CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
153165
;;
154166

155167
mipsel-unknown-linux-musl)
156168
qemu-mipsel -L /toolchain $CARGO_TARGET_DIR/$TARGET/debug/libc-test
169+
qemu-mipsel -L /toolchain $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
157170
;;
158171

159172
powerpc-unknown-linux-gnu)
160173
qemu-ppc -L /usr/powerpc-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test
174+
qemu-ppc -L /usr/powerpc-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
161175
;;
162176

163177
powerpc64-unknown-linux-gnu)
164178
qemu-ppc64 -L /usr/powerpc64-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test
179+
qemu-ppc64 -L /usr/powerpc64-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
165180
;;
166181

167182
aarch64-unknown-linux-gnu)
168183
qemu-aarch64 -L /usr/aarch64-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/libc-test
184+
qemu-aarch64 -L /usr/aarch64-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
169185
;;
170186

171187
s390x-unknown-linux-gnu)
172188
# TODO: in theory we should execute this, but qemu segfaults immediately :(
173189
# qemu-s390x -L /usr/s390x-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/libc-test
190+
# qemu-s390x -L /usr/s390x-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
174191
;;
175192

176193
*-rumprun-netbsd)
@@ -179,9 +196,15 @@ case "$TARGET" in
179196
-kernel /tmp/libc-test.img 2>&1 | tee /tmp/out &
180197
sleep 5
181198
grep "^PASSED .* tests" /tmp/out
199+
rumprun-bake hw_virtio /tmp/libc-test.img $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
200+
qemu-system-x86_64 -nographic -vga none -m 64 \
201+
-kernel /tmp/libc-test.img 2>&1 | tee /tmp/out &
202+
sleep 5
203+
grep "^PASSED .* tests" /tmp/out
182204
;;
183205

184206
*)
185207
$CARGO_TARGET_DIR/$TARGET/debug/libc-test
208+
$CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl
186209
;;
187210
esac

libc-test/build.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,11 @@ fn main() {
465465
// it's been fixed in CI.
466466
"MADV_SOFT_OFFLINE" if mips && linux => true,
467467

468+
// These constants are tested in a separate test program generated below because there
469+
// are header conflicts if we try to include the headers that define them here.
470+
"F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => true,
471+
"F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => true,
472+
468473
_ => false,
469474
}
470475
});
@@ -641,4 +646,29 @@ fn main() {
641646
} else {
642647
cfg.generate("../src/lib.rs", "all.rs");
643648
}
649+
650+
// On Linux or Android also generate another script for testing linux/fcntl declarations.
651+
// These cannot be tested normally because including both `linux/fcntl.h` and `fcntl.h`
652+
// fails on a lot of platforms.
653+
let mut cfg = ctest::TestGenerator::new();
654+
cfg.skip_type(|_| true)
655+
.skip_struct(|_| true)
656+
.skip_fn(|_| true);
657+
if android || linux {
658+
// Avoid struct definition conflicts when including both fcntl headers on non-musl targets
659+
if musl {
660+
cfg.header("fcntl.h");
661+
}
662+
cfg.header("linux/fcntl.h");
663+
cfg.skip_const(move |name| {
664+
match name {
665+
"F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false,
666+
"F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => false,
667+
_ => true,
668+
}
669+
});
670+
} else {
671+
cfg.skip_const(|_| true);
672+
}
673+
cfg.generate("../src/lib.rs", "linux_fcntl.rs");
644674
}

libc-test/run-generated-Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,5 @@ build = "build-generated.rs"
1111
[dependencies]
1212
libc = { path = ".." }
1313

14-
[[bin]]
15-
name = "libc-test"
16-
path = "src/main-generated.rs"
17-
1814
[build-dependencies]
1915
gcc = "0.3"

libc-test/src/bin/linux_fcntl.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![allow(bad_style, improper_ctypes)]
2+
extern crate libc;
3+
4+
use libc::*;
5+
6+
include!(concat!(env!("OUT_DIR"), "/linux_fcntl.rs"));
File renamed without changes.

libc-test/src/main-generated.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/unix/notbsd/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,17 @@ pub const F_SETFL: ::c_int = 4;
212212
pub const F_SETLEASE: ::c_int = 1024;
213213
pub const F_GETLEASE: ::c_int = 1025;
214214
pub const F_NOTIFY: ::c_int = 1026;
215+
pub const F_CANCELLK: ::c_int = 1029;
215216
pub const F_DUPFD_CLOEXEC: ::c_int = 1030;
216217
pub const F_SETPIPE_SZ: ::c_int = 1031;
217218
pub const F_GETPIPE_SZ: ::c_int = 1032;
219+
pub const F_ADD_SEALS: ::c_int = 1033;
220+
pub const F_GET_SEALS: ::c_int = 1034;
221+
222+
pub const F_SEAL_SEAL: ::c_int = 0x0001;
223+
pub const F_SEAL_SHRINK: ::c_int = 0x0002;
224+
pub const F_SEAL_GROW: ::c_int = 0x0004;
225+
pub const F_SEAL_WRITE: ::c_int = 0x0008;
218226

219227
// TODO(#235): Include file sealing fcntls once we have a way to verify them.
220228

0 commit comments

Comments
 (0)