Skip to content

Commit 3a650df

Browse files
mbyxtgross35
authored andcommitted
libc: port freebsd to use ctest-next
(backport <#4648>) (cherry picked from commit 673b10e)
1 parent 80b11d6 commit 3a650df

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

libc-test/build.rs

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ fn ctest_cfg() -> ctest::TestGenerator {
8585
}
8686

8787
fn ctest_next_cfg() -> ctest_next::TestGenerator {
88-
ctest_next::TestGenerator::new()
88+
let mut cfg = ctest_next::TestGenerator::new();
89+
cfg.skip_private(true);
90+
cfg
8991
}
9092

9193
fn do_semver() {
@@ -2397,7 +2399,7 @@ fn test_android(target: &str) {
23972399

23982400
fn test_freebsd(target: &str) {
23992401
assert!(target.contains("freebsd"));
2400-
let mut cfg = ctest_cfg();
2402+
let mut cfg = ctest_next_cfg();
24012403

24022404
let freebsd_ver = which_freebsd();
24032405

@@ -2539,7 +2541,13 @@ fn test_freebsd(target: &str) {
25392541
"wchar.h",
25402542
}
25412543

2542-
cfg.type_name(move |ty, is_struct, is_union| {
2544+
cfg.rename_type(|ty| match ty {
2545+
// FIXME(freebsd): https://github.com/rust-lang/libc/issues/1273
2546+
"sighandler_t" => Some("sig_t".to_string()),
2547+
_ => None,
2548+
});
2549+
2550+
cfg.rename_struct_ty(|ty| {
25432551
match ty {
25442552
// Just pass all these through, no need for a "struct" prefix
25452553
"FILE"
@@ -2554,27 +2562,20 @@ fn test_freebsd(target: &str) {
25542562
| "devstat_support_flags"
25552563
| "devstat_type_flags"
25562564
| "devstat_match_flags"
2557-
| "devstat_priority" => ty.to_string(),
2558-
2559-
// FIXME(freebsd): https://github.com/rust-lang/libc/issues/1273
2560-
"sighandler_t" => "sig_t".to_string(),
2561-
2562-
t if is_union => format!("union {t}"),
2563-
2564-
t if t.ends_with("_t") => t.to_string(),
2565+
| "devstat_priority" => Some(ty.to_string()),
25652566

25662567
// sigval is a struct in Rust, but a union in C:
2567-
"sigval" => "union sigval".to_string(),
2568+
"sigval" => Some("union sigval".to_string()),
25682569

2569-
// put `struct` in front of all structs:.
2570-
t if is_struct => format!("struct {t}"),
2570+
t if t.ends_with("_t") => Some(t.to_string()),
25712571

2572-
t => t.to_string(),
2572+
_ => None,
25732573
}
25742574
});
25752575

2576-
cfg.field_name(move |struct_, field| {
2577-
match field {
2576+
cfg.rename_struct_field(|struct_, field_| {
2577+
let struct_ = struct_.ident();
2578+
let replacement = match field_.ident() {
25782579
// Our stat *_nsec fields normally don't actually exist but are part
25792580
// of a timeval struct
25802581
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
@@ -2588,12 +2589,13 @@ fn test_freebsd(target: &str) {
25882589
"type_" if struct_ == "input_event" => "type".to_string(),
25892590
// Field is named `gennum` in Rust because `gen` is a keyword
25902591
"gennum" if struct_ == "xktls_session_onedir" => "gen".to_string(),
2591-
s => s.to_string(),
2592-
}
2592+
_ => return None,
2593+
};
2594+
Some(replacement)
25932595
});
25942596

2595-
cfg.skip_const(move |name| {
2596-
match name {
2597+
cfg.skip_const(move |constant| {
2598+
match constant.ident() {
25972599
// These constants were introduced in FreeBSD 13:
25982600
"F_ADD_SEALS" | "F_GET_SEALS" | "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW"
25992601
| "F_SEAL_WRITE"
@@ -2873,8 +2875,8 @@ fn test_freebsd(target: &str) {
28732875
}
28742876
});
28752877

2876-
cfg.skip_type(move |ty| {
2877-
match ty {
2878+
cfg.skip_alias(move |ty| {
2879+
match ty.ident() {
28782880
// the struct "__kvm" is quite tricky to bind so since we only use a pointer to it
28792881
// for now, it doesn't matter too much...
28802882
"kvm_t" => true,
@@ -2885,7 +2887,9 @@ fn test_freebsd(target: &str) {
28852887
}
28862888
});
28872889

2888-
cfg.skip_struct(move |ty| {
2890+
cfg.skip_union(|u| u.ident().starts_with("__c_anonymous_"));
2891+
cfg.skip_struct(move |struct_| {
2892+
let ty = struct_.ident();
28892893
if ty.starts_with("__c_anonymous_") {
28902894
return true;
28912895
}
@@ -2930,9 +2934,9 @@ fn test_freebsd(target: &str) {
29302934
}
29312935
});
29322936

2933-
cfg.skip_fn(move |name| {
2937+
cfg.skip_fn(move |func| {
29342938
// skip those that are manually verified
2935-
match name {
2939+
match func.ident() {
29362940
// FIXME: https://github.com/rust-lang/libc/issues/1272
29372941
// Also, `execvpe` is introduced in FreeBSD 14.1
29382942
"execv" | "execve" | "execvp" | "execvpe" | "fexecve" => true,
@@ -2993,18 +2997,12 @@ fn test_freebsd(target: &str) {
29932997
}
29942998
});
29952999

2996-
cfg.volatile_item(|i| {
2997-
use ctest::VolatileItemKind::*;
2998-
match i {
2999-
// aio_buf is a volatile void** but since we cannot express that in
3000-
// Rust types, we have to explicitly tell the checker about it here:
3001-
StructField(ref n, ref f) if n == "aiocb" && f == "aio_buf" => true,
3002-
_ => false,
3003-
}
3004-
});
3000+
// aio_buf is a volatile void* but since we cannot express that in
3001+
// Rust types, we have to explicitly tell the checker about it here:
3002+
cfg.volatile_struct_field(|s, f| s.ident() == "aiocb" && f.ident() == "aio_buf");
30053003

3006-
cfg.skip_field(move |struct_, field| {
3007-
match (struct_, field) {
3004+
cfg.skip_struct_field(move |struct_, field| {
3005+
match (struct_.ident(), field.ident()) {
30083006
// FIXME(freebsd): `sa_sigaction` has type `sighandler_t` but that type is
30093007
// incorrect, see: https://github.com/rust-lang/libc/issues/1359
30103008
("sigaction", "sa_sigaction") => true,
@@ -3079,7 +3077,10 @@ fn test_freebsd(target: &str) {
30793077
});
30803078
}
30813079

3082-
cfg.generate(src_hotfix_dir().join("lib.rs"), "ctest_output.rs");
3080+
// FIXME(ctest): The original ctest bypassed this requirement somehow.
3081+
cfg.rename_type(move |ty| (ty == "dot3Vendors").then_some(format!("enum {ty}")));
3082+
3083+
ctest_next::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap();
30833084
}
30843085

30853086
fn test_emscripten(target: &str) {

0 commit comments

Comments
 (0)