Skip to content

Commit c22bf18

Browse files
committed
test: Commonize shared configuration
Every platform needs the `__c_anonymous` config and most need to skip `__uint128`, so just do these in a common place.
1 parent eab4196 commit c22bf18

File tree

1 file changed

+16
-87
lines changed

1 file changed

+16
-87
lines changed

libc-test/build.rs

Lines changed: 16 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ fn do_ctest() {
7272
fn ctest_cfg() -> ctest::TestGenerator {
7373
let mut cfg = ctest::TestGenerator::new();
7474
cfg.skip_private(true);
75+
76+
// Skip anonymous unions/structs.
77+
cfg.skip_union(|u| u.ident().starts_with("__c_anonymous_"));
78+
cfg.skip_struct(|s| s.ident().starts_with("__c_anonymous_"));
79+
cfg.skip_alias(|ty| ty.ident().starts_with("__c_anonymous_"));
80+
81+
// __uint128 is not declared in C, but is an alias we export.
82+
// FIXME(1.0): These aliases will eventually be removed.
83+
cfg.skip_alias(|ty| ty.ident() == "__uint128");
84+
7585
cfg
7686
}
7787

@@ -299,10 +309,6 @@ fn test_apple(target: &str) {
299309
(x86_64, "crt_externs.h"),
300310
);
301311

302-
// Skip anonymous unions/structs.
303-
cfg.skip_union(|u| u.ident().starts_with("__c_anonymous_"));
304-
cfg.skip_struct(|s| s.ident().starts_with("__c_anonymous_"));
305-
306312
cfg.skip_struct(|s| {
307313
match s.ident() {
308314
// FIXME(macos): The size is changed in recent macOSes.
@@ -314,15 +320,6 @@ fn test_apple(target: &str) {
314320
}
315321
});
316322

317-
cfg.skip_alias(|ty| ty.ident().starts_with("__c_anonymous_"));
318-
cfg.skip_alias(|ty| {
319-
match ty.ident() {
320-
// FIXME(macos): "'__uint128' undeclared" in C
321-
"__uint128" => true,
322-
_ => false,
323-
}
324-
});
325-
326323
cfg.skip_const(move |constant| {
327324
match constant.ident() {
328325
// FIXME(deprecated): These OSX constants are removed in Sierra.
@@ -535,10 +532,6 @@ fn test_openbsd(target: &str) {
535532
}
536533
});
537534

538-
// Skip anonymous unions/structs.
539-
cfg.skip_union(|u| u.ident().starts_with("__c_anonymous_"));
540-
cfg.skip_struct(|s| s.ident().starts_with("__c_anonymous_"));
541-
542535
cfg.rename_struct_ty(|ty| ty.ends_with("_t").then_some(ty.to_string()));
543536
cfg.rename_union_ty(|ty| ty.ends_with("_t").then_some(ty.to_string()));
544537

@@ -661,14 +654,6 @@ fn test_cygwin(target: &str) {
661654
_ => false,
662655
});
663656

664-
cfg.skip_struct(move |struct_| {
665-
if struct_.ident().starts_with("__c_anonymous_") {
666-
return true;
667-
}
668-
669-
false
670-
});
671-
672657
cfg.rename_struct_field(move |struct_, field| {
673658
match field.ident() {
674659
// Our stat *_nsec fields normally don't actually exist but are part
@@ -801,17 +786,12 @@ fn test_windows(target: &str) {
801786
});
802787

803788
cfg.skip_struct(move |struct_| {
804-
let ty = struct_.ident();
805-
if ty.starts_with("__c_anonymous_") {
806-
return true;
807-
}
808-
match ty {
789+
match struct_.ident() {
809790
// FIXME(windows): The size and alignment of this struct are incorrect
810791
"timespec" if gnu && i686 => true,
811792
_ => false,
812793
}
813794
});
814-
cfg.skip_union(move |union_| union_.ident().starts_with("__c_anonymous_"));
815795

816796
cfg.skip_const(move |constant| {
817797
match constant.ident() {
@@ -1064,15 +1044,12 @@ fn test_solarish(target: &str) {
10641044

10651045
cfg.skip_union(|union_| {
10661046
// the union handling is a mess
1067-
if union_.ident().starts_with("__c_anonymous_") || union_.ident().contains("door_desc_t_") {
1047+
if union_.ident().contains("door_desc_t_") {
10681048
return true;
10691049
}
10701050
false
10711051
});
10721052
cfg.skip_struct(move |struct_| {
1073-
if struct_.ident().starts_with("__c_anonymous_") {
1074-
return true;
1075-
}
10761053
// the union handling is a mess
10771054
if struct_.ident().contains("door_desc_t_") {
10781055
return true;
@@ -1307,13 +1284,7 @@ fn test_netbsd(target: &str) {
13071284
}
13081285
});
13091286

1310-
cfg.skip_struct(|ty| ty.ident().starts_with("__c_anonymous_"));
1311-
cfg.skip_union(|ty| ty.ident().starts_with("__c_anonymous_"));
1312-
13131287
cfg.skip_alias(move |ty| {
1314-
if ty.ident().starts_with("__c_anonymous_") {
1315-
return true;
1316-
}
13171288
match ty.ident() {
13181289
// FIXME(netbsd): sighandler_t is crazy across platforms
13191290
"sighandler_t" => true,
@@ -1531,9 +1502,6 @@ fn test_dragonflybsd(target: &str) {
15311502
});
15321503

15331504
cfg.skip_struct(move |struct_| {
1534-
if struct_.ident().starts_with("__c_anonymous_") {
1535-
return true;
1536-
}
15371505
match struct_.ident() {
15381506
// FIXME(dragonflybsd): These are tested as part of the linux_fcntl tests since
15391507
// there are header conflicts when including them with all the other
@@ -1903,21 +1871,14 @@ fn test_android(target: &str) {
19031871
"posix_spawn_file_actions_t" => true,
19041872
"posix_spawnattr_t" => true,
19051873

1906-
// FIXME(android): "'__uint128' undeclared" in C
1907-
"__uint128" => true,
19081874
// Added in API level 24
19091875
"if_nameindex" => true,
19101876

19111877
_ => false,
19121878
}
19131879
});
19141880

1915-
cfg.skip_union(move |union_| union_.ident().starts_with("__c_anonymous_"));
1916-
19171881
cfg.skip_struct(move |struct_| {
1918-
if struct_.ident().starts_with("__c_anonymous_") {
1919-
return true;
1920-
}
19211882
match struct_.ident() {
19221883
// These are tested as part of the linux_fcntl tests since there are
19231884
// header conflicts when including them with all the other structs.
@@ -2685,13 +2646,8 @@ fn test_freebsd(target: &str) {
26852646
}
26862647
});
26872648

2688-
cfg.skip_union(|u| u.ident().starts_with("__c_anonymous_"));
26892649
cfg.skip_struct(move |struct_| {
2690-
let ty = struct_.ident();
2691-
if ty.starts_with("__c_anonymous_") {
2692-
return true;
2693-
}
2694-
match ty {
2650+
match struct_.ident() {
26952651
// `procstat` is a private struct
26962652
"procstat" => true,
26972653

@@ -2998,10 +2954,6 @@ fn test_emscripten(target: &str) {
29982954
});
29992955

30002956
cfg.skip_union(|union_| {
3001-
if union_.ident().starts_with("__c_anonymous_") {
3002-
return true;
3003-
}
3004-
30052957
match union_.ident() {
30062958
// FIXME(emscripten): Investigate why the test fails.
30072959
// Skip for now to unblock CI.
@@ -3024,9 +2976,6 @@ fn test_emscripten(target: &str) {
30242976
});
30252977

30262978
cfg.skip_struct(move |struct_| {
3027-
if struct_.ident().starts_with("__c_anonymous_") {
3028-
return true;
3029-
}
30302979
match struct_.ident() {
30312980
// FIXME(emscripten): Investigate why the test fails.
30322981
// Skip for now to unblock CI.
@@ -3297,17 +3246,11 @@ fn test_neutrino(target: &str) {
32973246
// Does not exist in Neutrino
32983247
"locale_t" => true,
32993248

3300-
// FIXME: "'__uint128' undeclared" in C
3301-
"__uint128" => true,
3302-
33033249
_ => false,
33043250
}
33053251
});
33063252

33073253
cfg.skip_struct(move |struct_| {
3308-
if struct_.ident().starts_with("__c_anonymous_") {
3309-
return true;
3310-
}
33113254
match struct_.ident() {
33123255
"Elf64_Phdr" | "Elf32_Phdr" => true,
33133256

@@ -3869,9 +3812,6 @@ fn test_linux(target: &str) {
38693812
// specific type.
38703813
"Ioctl" => true,
38713814

3872-
// FIXME: "'__uint128' undeclared" in C
3873-
"__uint128" => true,
3874-
38753815
t => {
38763816
if musl {
38773817
// LFS64 types have been removed in musl 1.2.4+
@@ -3883,10 +3823,6 @@ fn test_linux(target: &str) {
38833823
}
38843824
});
38853825

3886-
// Skip structs and enums that are unnamed in C.
3887-
cfg.skip_union(move |union_| union_.ident().starts_with("__c_anonymous_"));
3888-
cfg.skip_struct(move |struct_| struct_.ident().starts_with("__c_anonymous_"));
3889-
38903826
cfg.skip_struct(move |struct_| {
38913827
let ty = struct_.ident();
38923828

@@ -3965,10 +3901,7 @@ fn test_linux(target: &str) {
39653901
"xdp_umem_reg" => true,
39663902

39673903
// FIXME(linux): Requires >= 6.8 kernel headers.
3968-
"xsk_tx_metadata"
3969-
| "__c_anonymous_xsk_tx_metadata_union"
3970-
| "xsk_tx_metadata_request"
3971-
| "xsk_tx_metadata_completion" => true,
3904+
"xsk_tx_metadata" | "xsk_tx_metadata_request" | "xsk_tx_metadata_completion" => true,
39723905

39733906
// A new field was added in kernel 5.4, this is the old version for backwards compatibility.
39743907
// https://github.com/torvalds/linux/commit/77cd0d7b3f257fd0e3096b4fdcff1a7d38e99e10
@@ -4637,9 +4570,9 @@ fn test_linux_like_apis(target: &str) {
46374570
if linux || android || emscripten {
46384571
// test strerror_r from the `string.h` header
46394572
config_gnu_bits(target, &mut cfg);
4640-
headers!(cfg, "string.h",);
46414573

4642-
cfg.skip_alias(|_| true)
4574+
cfg.header("string.h")
4575+
.skip_alias(|_| true)
46434576
.skip_static(|_| true)
46444577
.skip_const(|_| true)
46454578
.skip_struct(|_| true)
@@ -4938,11 +4871,7 @@ fn test_haiku(target: &str) {
49384871
"support/TypeConstants.h",
49394872
);
49404873

4941-
cfg.skip_union(|union_| union_.ident().starts_with("__c_anonymous_"));
49424874
cfg.skip_struct(move |struct_| {
4943-
if struct_.ident().starts_with("__c_anonymous_") {
4944-
return true;
4945-
}
49464875
match struct_.ident() {
49474876
// FIXME(haiku): locale_t does not exist on Haiku
49484877
"locale_t" => true,

0 commit comments

Comments
 (0)