Skip to content

Commit ed37f58

Browse files
committed
Auto merge of #2109 - Thomasdezeeuw:issue_2104-regression_tests, r=<try>
Add regression test infrastructure Please the commit messages for details. I still need to add lists for the following targets, but I got the major ones I think. TODO: * aarch64-unknown-hermit * x86_64-unknown-hermit * x86_64-pc-solaris * x86_64-sun-solaris * sparcv9-sun-solaris * x86_64-fortanix-unknown-sgx * x86_64-unknown-illumos * asmjs-unknown-emscripten * wasm32-unknown-emscripten * wasm32-unknown-unknown * wasm32-wasi * Check symbols added after commit ed45c26. TODO: add a bit to the contributing guide about adding to these lists. Closes #2104.
2 parents 10d99b9 + 418c481 commit ed37f58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+18560
-2
lines changed

CONTRIBUTING.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,24 @@ at, fear not! This crate has CI support which tests any binding against all
2828
platforms supported, so you'll see failures if an API is added at the wrong
2929
level or has different signatures across platforms.
3030

31+
New symbol(s) (i.e. functions, constants etc.) should also be added to the
32+
symbols list(s) found in the `libc-test/semver` directory. These lists keep
33+
track of what symbols are public in the libc crate and ensures they remain
34+
available between changes to the crate. If the new symbol(s) are available on
35+
all supported Unixes it should be added to `unix.txt` list<sup>1</sup>,
36+
otherwise they should be added to the OS specific list(s).
37+
3138
With that in mind, the steps for adding a new API are:
3239

3340
1. Determine where in the module hierarchy your API should be added.
34-
2. Add the API.
41+
2. Add the API, including adding new symbol(s) to the semver lists.
3542
3. Send a PR to this repo.
3643
4. Wait for CI to pass, fixing errors.
3744
5. Wait for a merge!
3845

46+
<sup>1</sup>: Note that this list has nothing to do with any Unix or Posix
47+
standard, it's just a list shared between all OSs that declare `#[cfg(unix)]`.
48+
3949
## Test before you commit
4050

4151
We have two automated tests running on [GitHub Actions](https://github.com/rust-lang/libc/actions):

libc-test/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ harness = true
6565
name = "errqueue"
6666
path = "test/errqueue.rs"
6767
harness = true
68+
69+
[[test]]
70+
name = "semver"
71+
path = "test/semver.rs"
72+
harness = false

libc-test/build.rs

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
extern crate cc;
44
extern crate ctest2 as ctest;
55

6-
use std::env;
6+
use std::fs::File;
7+
use std::io::{BufRead, BufReader, BufWriter, Write};
8+
use std::path::{Path, PathBuf};
9+
use std::{env, io};
710

811
fn do_cc() {
912
let target = env::var("TARGET").unwrap();
@@ -63,9 +66,85 @@ fn ctest_cfg() -> ctest::TestGenerator {
6366
cfg
6467
}
6568

69+
fn do_semver() {
70+
let mut out = PathBuf::from(env::var("OUT_DIR").unwrap());
71+
out.push("semver.rs");
72+
let mut output = BufWriter::new(File::create(&out).unwrap());
73+
74+
let family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap();
75+
let vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
76+
let os = env::var("CARGO_CFG_TARGET_OS").unwrap();
77+
let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
78+
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
79+
80+
// `libc-test/semver` dir.
81+
let mut semver_root =
82+
PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
83+
semver_root.push("semver");
84+
85+
// NOTE: Windows has the same `family` as `os`, no point in including it
86+
// twice.
87+
// NOTE: Android doesn't include the unix file (or the Linux file) because
88+
// there are some many definitions missing it's actually easier just to
89+
// maintain a file for Android.
90+
if family != os && os != "android" {
91+
process_semver_file(&mut output, &mut semver_root, &family);
92+
}
93+
process_semver_file(&mut output, &mut semver_root, &vendor);
94+
process_semver_file(&mut output, &mut semver_root, &os);
95+
let os_arch = format!("{}-{}", os, arch);
96+
process_semver_file(&mut output, &mut semver_root, &os_arch);
97+
if target_env != "" {
98+
let os_env = format!("{}-{}", os, target_env);
99+
process_semver_file(&mut output, &mut semver_root, &os_env);
100+
101+
let os_env_arch = format!("{}-{}-{}", os, target_env, arch);
102+
process_semver_file(&mut output, &mut semver_root, &os_env_arch);
103+
}
104+
}
105+
106+
fn process_semver_file<W: Write, P: AsRef<Path>>(
107+
output: &mut W,
108+
path: &mut PathBuf,
109+
file: P,
110+
) {
111+
// NOTE: `path` is reused between calls, so always remove the file again.
112+
path.push(file);
113+
path.set_extension("txt");
114+
115+
println!("cargo:rerun-if-changed={}", path.display());
116+
let input_file = match File::open(&*path) {
117+
Ok(file) => file,
118+
Err(ref err) if err.kind() == io::ErrorKind::NotFound => {
119+
path.pop();
120+
return;
121+
}
122+
Err(err) => panic!("unexpected error opening file: {}", err),
123+
};
124+
let input = BufReader::new(input_file);
125+
126+
write!(output, "// Source: {}.\n", path.display()).unwrap();
127+
output.write(b"use libc::{\n").unwrap();
128+
for line in input.lines() {
129+
let line = line.unwrap().into_bytes();
130+
match line.first() {
131+
// Ignore comments and empty lines.
132+
Some(b'#') | None => continue,
133+
_ => {
134+
output.write(b" ").unwrap();
135+
output.write(&line).unwrap();
136+
output.write(b",\n").unwrap();
137+
}
138+
}
139+
}
140+
output.write(b"};\n\n").unwrap();
141+
path.pop();
142+
}
143+
66144
fn main() {
67145
do_cc();
68146
do_ctest();
147+
do_semver();
69148
}
70149

71150
macro_rules! headers {

libc-test/semver/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Supported API by libc
2+
3+
These files are read by [`build.rs`](../build.rs) and turned into tests to
4+
ensure that APIs aren't removed between libc releases.
5+
6+
## File order
7+
8+
Files are including in the following order:
9+
* Family, e.g. `unix.txt`. NOTE: Windows is skipped here and includes as OS
10+
name below.
11+
* Vendor, e.g. `apple.txt`. This allows us to have a single file with system
12+
calls shared between multiple OSs, e.g. `ios.txt`, `macos.txt` share the same
13+
kernel.
14+
* OS, e.g `linux.txt`, `macos.txt`, `windows.txt`.
15+
* Architecture specific system calls, e.g. `linux-x86_64.txt` or
16+
`linux-aarch64.txt`.
17+
* Target environment, e.g. `windows-mscv.txt` or `windows-gnu.txt`.

libc-test/semver/TODO-linux.txt

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# The following symbols are not not available in some combinations of
2+
# musl/gnu/android and/or architecture.
3+
BOTHER
4+
HWCAP_AES
5+
HWCAP_ASIMD
6+
HWCAP_ASIMDDP
7+
HWCAP_ASIMDFHM
8+
HWCAP_ASIMDHP
9+
HWCAP_ASIMDRDM
10+
HWCAP_ATOMICS
11+
HWCAP_CPUID
12+
HWCAP_CRC32
13+
HWCAP_DCPOP
14+
HWCAP_DIT
15+
HWCAP_EVTSTRM
16+
HWCAP_FCMA
17+
HWCAP_FLAGM
18+
HWCAP_FP
19+
HWCAP_FPHP
20+
HWCAP_ILRCPC
21+
HWCAP_JSCVT
22+
HWCAP_LRCPC
23+
HWCAP_PACA
24+
HWCAP_PACG
25+
HWCAP_PMULL
26+
HWCAP_SB
27+
HWCAP_SHA1
28+
HWCAP_SHA2
29+
HWCAP_SHA3
30+
HWCAP_SHA512
31+
HWCAP_SM3
32+
HWCAP_SM4
33+
HWCAP_SSBS
34+
HWCAP_SVE
35+
HWCAP_USCAT
36+
KEYCTL_CAPABILITIES
37+
KEYCTL_CAPS0_BIG_KEY
38+
KEYCTL_CAPS0_CAPABILITIES
39+
KEYCTL_CAPS0_DIFFIE_HELLMAN
40+
KEYCTL_CAPS0_INVALIDATE
41+
KEYCTL_CAPS0_MOVE
42+
KEYCTL_CAPS0_PERSISTENT_KEYRINGS
43+
KEYCTL_CAPS0_PUBLIC_KEY
44+
KEYCTL_CAPS0_RESTRICT_KEYRING
45+
KEYCTL_CAPS1_NS_KEYRING_NAME
46+
KEYCTL_CAPS1_NS_KEY_TAG
47+
KEYCTL_MOVE
48+
NFT_MSG_DELOBJ
49+
NFT_MSG_GETOBJ
50+
NFT_MSG_GETOBJ_RESET
51+
NFT_MSG_NEWOBJ
52+
PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
53+
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
54+
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
55+
SCM_TIMESTAMPING_OPT_STATS
56+
SCM_TIMESTAMPING_PKTINFO
57+
SCM_TIMESTAMPNS
58+
SCM_TXTIME
59+
SCM_WIFI_STATUS
60+
SO_ATTACH_BPF
61+
SO_ATTACH_FILTER
62+
SO_ATTACH_REUSEPORT_CBPF
63+
SO_ATTACH_REUSEPORT_EBPF
64+
SO_BINDTOIFINDEX
65+
SO_BPF_EXTENSIONS
66+
SO_BSDCOMPAT
67+
SO_CNX_ADVICE
68+
SO_COOKIE
69+
SO_DETACH_BPF
70+
SO_DETACH_FILTER
71+
SO_DETACH_REUSEPORT_BPF
72+
SO_GET_FILTER
73+
SO_INCOMING_CPU
74+
SO_INCOMING_NAPI_ID
75+
SO_LOCK_FILTER
76+
SO_MAX_PACING_RATE
77+
SO_MEMINFO
78+
SO_NOFCS
79+
SO_NO_CHECK
80+
SO_PEERGROUPS
81+
SO_PEERNAME
82+
SO_RCVTIMEO_NEW
83+
SO_SECURITY_AUTHENTICATION
84+
SO_SECURITY_ENCRYPTION_NETWORK
85+
SO_SECURITY_ENCRYPTION_TRANSPORT
86+
SO_SELECT_ERR_QUEUE
87+
SO_SNDTIMEO_NEW
88+
SO_STYLE
89+
SO_TIMESTAMPING_NEW
90+
SO_TIMESTAMPNS
91+
SO_TIMESTAMPNS_NEW
92+
SO_TIMESTAMP_NEW
93+
SO_TXTIME
94+
SO_WIFI_STATUS
95+
SO_ZEROCOPY
96+
SYS__llseek
97+
SYS__newselect
98+
SYS__sysctl
99+
SYS_create_module
100+
SYS_fadvise64
101+
SYS_fstatat64
102+
SYS_get_kernel_syms
103+
SYS_get_thread_area
104+
SYS_getrlimit
105+
SYS_migrate_pages
106+
SYS_mmap
107+
SYS_nfsservctl
108+
SYS_pread64
109+
SYS_pwrite64
110+
SYS_query_module
111+
SYS_set_thread_area
112+
SYS_uselib
113+
fsblkcnt64_t
114+
fsfilcnt64_t
115+
getrandom
116+
sysctl
117+
termios2

libc-test/semver/TODO-unix.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# These symbols are missing for the targets:
2+
# * asmjs-unknown-emscripten
3+
getpwuid_r
4+
pthread_atfork
5+
pthread_sigmask

libc-test/semver/android-aarch64.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
HWCAP2_DCPODP
2+
HWCAP2_FLAGM2
3+
HWCAP2_FRINT
4+
HWCAP2_SVE2
5+
HWCAP2_SVEAES
6+
HWCAP2_SVEBITPERM
7+
HWCAP2_SVEPMULL
8+
HWCAP2_SVESHA3
9+
HWCAP2_SVESM4
10+
SYS_arch_specific_syscall
11+
SYS_syscalls

0 commit comments

Comments
 (0)