Skip to content

Commit 4d6c7b8

Browse files
committed
libc: port freebsd to use ctest-next
1 parent 8380bad commit 4d6c7b8

File tree

1 file changed

+33
-36
lines changed

1 file changed

+33
-36
lines changed

libc-test/build.rs

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ fn ctest_cfg() -> ctest::TestGenerator {
7878
}
7979

8080
fn ctest_next_cfg() -> ctest_next::TestGenerator {
81-
ctest_next::TestGenerator::new()
81+
let mut cfg = ctest_next::TestGenerator::new();
82+
cfg.skip_private(true);
83+
cfg
8284
}
8385

8486
fn do_semver() {
@@ -2286,7 +2288,7 @@ fn test_android(target: &str) {
22862288

22872289
fn test_freebsd(target: &str) {
22882290
assert!(target.contains("freebsd"));
2289-
let mut cfg = ctest_cfg();
2291+
let mut cfg = ctest_next_cfg();
22902292

22912293
let freebsd_ver = which_freebsd();
22922294

@@ -2428,7 +2430,7 @@ fn test_freebsd(target: &str) {
24282430
"wchar.h",
24292431
}
24302432

2431-
cfg.type_name(move |ty, is_struct, is_union| {
2433+
cfg.rename_struct_ty(|ty| {
24322434
match ty {
24332435
// Just pass all these through, no need for a "struct" prefix
24342436
"FILE"
@@ -2443,24 +2445,19 @@ fn test_freebsd(target: &str) {
24432445
| "devstat_support_flags"
24442446
| "devstat_type_flags"
24452447
| "devstat_match_flags"
2446-
| "devstat_priority" => ty.to_string(),
2448+
| "devstat_priority" => Some(ty.to_string()),
24472449

24482450
// FIXME(freebsd): https://github.com/rust-lang/libc/issues/1273
2449-
"sighandler_t" => "sig_t".to_string(),
2450-
2451-
t if is_union => format!("union {t}"),
2452-
2453-
t if t.ends_with("_t") => t.to_string(),
2454-
2455-
// put `struct` in front of all structs:.
2456-
t if is_struct => format!("struct {t}"),
2451+
"sighandler_t" => Some("sig_t".to_string()),
24572452

2458-
t => t.to_string(),
2453+
t if t.ends_with("_t") => Some(t.to_string()),
2454+
_ => None,
24592455
}
24602456
});
24612457

2462-
cfg.field_name(move |struct_, field| {
2463-
match field {
2458+
cfg.rename_struct_field(|struct_, field_| {
2459+
let struct_ = struct_.ident();
2460+
let replacement = match field_.ident() {
24642461
// Our stat *_nsec fields normally don't actually exist but are part
24652462
// of a timeval struct
24662463
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
@@ -2474,12 +2471,13 @@ fn test_freebsd(target: &str) {
24742471
"type_" if struct_ == "input_event" => "type".to_string(),
24752472
// Field is named `gennum` in Rust because `gen` is a keyword
24762473
"gennum" if struct_ == "xktls_session_onedir" => "gen".to_string(),
2477-
s => s.to_string(),
2478-
}
2474+
_ => return None,
2475+
};
2476+
Some(replacement)
24792477
});
24802478

2481-
cfg.skip_const(move |name| {
2482-
match name {
2479+
cfg.skip_const(move |constant| {
2480+
match constant.ident() {
24832481
// These constants were introduced in FreeBSD 13:
24842482
"F_ADD_SEALS" | "F_GET_SEALS" | "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW"
24852483
| "F_SEAL_WRITE"
@@ -2745,8 +2743,8 @@ fn test_freebsd(target: &str) {
27452743
}
27462744
});
27472745

2748-
cfg.skip_type(move |ty| {
2749-
match ty {
2746+
cfg.skip_alias(move |ty| {
2747+
match ty.ident() {
27502748
// the struct "__kvm" is quite tricky to bind so since we only use a pointer to it
27512749
// for now, it doesn't matter too much...
27522750
"kvm_t" => true,
@@ -2757,7 +2755,9 @@ fn test_freebsd(target: &str) {
27572755
}
27582756
});
27592757

2760-
cfg.skip_struct(move |ty| {
2758+
cfg.skip_union(|u| u.ident().starts_with("__c_anonymous_"));
2759+
cfg.skip_struct(move |struct_| {
2760+
let ty = struct_.ident();
27612761
if ty.starts_with("__c_anonymous_") {
27622762
return true;
27632763
}
@@ -2802,9 +2802,9 @@ fn test_freebsd(target: &str) {
28022802
}
28032803
});
28042804

2805-
cfg.skip_fn(move |name| {
2805+
cfg.skip_fn(move |func| {
28062806
// skip those that are manually verified
2807-
match name {
2807+
match func.ident() {
28082808
// This is introduced in FreeBSD 14.1
28092809
"execvpe" => true,
28102810

@@ -2864,18 +2864,12 @@ fn test_freebsd(target: &str) {
28642864
}
28652865
});
28662866

2867-
cfg.volatile_item(|i| {
2868-
use ctest::VolatileItemKind::*;
2869-
match i {
2870-
// aio_buf is a volatile void* but since we cannot express that in
2871-
// Rust types, we have to explicitly tell the checker about it here:
2872-
StructField(ref n, ref f) if n == "aiocb" && f == "aio_buf" => true,
2873-
_ => false,
2874-
}
2875-
});
2867+
// aio_buf is a volatile void* but since we cannot express that in
2868+
// Rust types, we have to explicitly tell the checker about it here:
2869+
cfg.volatile_struct_field(|s, f| s.ident() == "aiocb" && f.ident() == "aio_buf");
28762870

2877-
cfg.skip_field(move |struct_, field| {
2878-
match (struct_, field) {
2871+
cfg.skip_struct_field(move |struct_, field| {
2872+
match (struct_.ident(), field.ident()) {
28792873
// FIXME(freebsd): `sa_sigaction` has type `sighandler_t` but that type is
28802874
// incorrect, see: https://github.com/rust-lang/libc/issues/1359
28812875
("sigaction", "sa_sigaction") => true,
@@ -2947,7 +2941,10 @@ fn test_freebsd(target: &str) {
29472941
});
29482942
}
29492943

2950-
cfg.generate(src_hotfix_dir().join("lib.rs"), "ctest_output.rs");
2944+
// FIXME(ctest): The original ctest bypassed this requirement somehow.
2945+
cfg.rename_type(move |ty| (ty == "dot3Vendors").then_some(format!("enum {ty}")));
2946+
2947+
ctest_next::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap();
29512948
}
29522949

29532950
fn test_emscripten(target: &str) {

0 commit comments

Comments
 (0)