Skip to content

Commit 5fdb940

Browse files
committed
Auto merge of #2109 - Thomasdezeeuw:issue_2104-regression_tests, r=JohnTitor
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 c5357c9 + e864628 commit 5fdb940

39 files changed

+18586
-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: 77 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,82 @@ 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+
}
102+
103+
fn process_semver_file<W: Write, P: AsRef<Path>>(
104+
output: &mut W,
105+
path: &mut PathBuf,
106+
file: P,
107+
) {
108+
// NOTE: `path` is reused between calls, so always remove the file again.
109+
path.push(file);
110+
path.set_extension("txt");
111+
112+
println!("cargo:rerun-if-changed={}", path.display());
113+
let input_file = match File::open(&*path) {
114+
Ok(file) => file,
115+
Err(ref err) if err.kind() == io::ErrorKind::NotFound => {
116+
path.pop();
117+
return;
118+
}
119+
Err(err) => panic!("unexpected error opening file: {}", err),
120+
};
121+
let input = BufReader::new(input_file);
122+
123+
write!(output, "// Source: {}.\n", path.display()).unwrap();
124+
output.write(b"use libc::{\n").unwrap();
125+
for line in input.lines() {
126+
let line = line.unwrap().into_bytes();
127+
match line.first() {
128+
// Ignore comments and empty lines.
129+
Some(b'#') | None => continue,
130+
_ => {
131+
output.write(b" ").unwrap();
132+
output.write(&line).unwrap();
133+
output.write(b",\n").unwrap();
134+
}
135+
}
136+
}
137+
output.write(b"};\n\n").unwrap();
138+
path.pop();
139+
}
140+
66141
fn main() {
67142
do_cc();
68143
do_ctest();
144+
do_semver();
69145
}
70146

71147
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/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

libc-test/semver/android-arm.txt

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
NGREG
2+
PTRACE_GETFPREGS
3+
PTRACE_GETREGS
4+
PTRACE_SETFPREGS
5+
PTRACE_SETREGS
6+
REG_R0
7+
REG_R1
8+
REG_R10
9+
REG_R11
10+
REG_R12
11+
REG_R13
12+
REG_R14
13+
REG_R15
14+
REG_R2
15+
REG_R3
16+
REG_R4
17+
REG_R5
18+
REG_R6
19+
REG_R7
20+
REG_R8
21+
REG_R9
22+
SYS_accept
23+
SYS_access
24+
SYS_arm_fadvise64_64
25+
SYS_arm_sync_file_range
26+
SYS_bdflush
27+
SYS_chmod
28+
SYS_chown
29+
SYS_chown32
30+
SYS_creat
31+
SYS_dup2
32+
SYS_epoll_create
33+
SYS_epoll_wait
34+
SYS_eventfd
35+
SYS_fchown32
36+
SYS_fcntl64
37+
SYS_fork
38+
SYS_fstat64
39+
SYS_fstatat64
40+
SYS_fstatfs64
41+
SYS_ftruncate64
42+
SYS_futimesat
43+
SYS_getdents
44+
SYS_getegid32
45+
SYS_geteuid32
46+
SYS_getgid32
47+
SYS_getgroups32
48+
SYS_getpgrp
49+
SYS_getresgid32
50+
SYS_getresuid32
51+
SYS_getuid32
52+
SYS_inotify_init
53+
SYS_lchown
54+
SYS_lchown32
55+
SYS_link
56+
SYS_lstat
57+
SYS_lstat64
58+
SYS_mkdir
59+
SYS_mknod
60+
SYS_mmap2
61+
SYS_msgctl
62+
SYS_msgget
63+
SYS_msgrcv
64+
SYS_msgsnd
65+
SYS_nice
66+
SYS_open
67+
SYS_pause
68+
SYS_pciconfig_iobase
69+
SYS_pciconfig_read
70+
SYS_pciconfig_write
71+
SYS_pipe
72+
SYS_poll
73+
SYS_readlink
74+
SYS_recv
75+
SYS_rename
76+
SYS_rmdir
77+
SYS_semctl
78+
SYS_semget
79+
SYS_semop
80+
SYS_semtimedop
81+
SYS_send
82+
SYS_sendfile
83+
SYS_sendfile64
84+
SYS_setfsgid32
85+
SYS_setfsuid32
86+
SYS_setgid32
87+
SYS_setgroups32
88+
SYS_setregid32
89+
SYS_setresgid32
90+
SYS_setresuid32
91+
SYS_setreuid32
92+
SYS_setuid32
93+
SYS_shmat
94+
SYS_shmctl
95+
SYS_shmdt
96+
SYS_shmget
97+
SYS_sigaction
98+
SYS_signalfd
99+
SYS_sigpending
100+
SYS_sigprocmask
101+
SYS_sigreturn
102+
SYS_sigsuspend
103+
SYS_stat
104+
SYS_stat64
105+
SYS_statfs64
106+
SYS_symlink
107+
SYS_sysfs
108+
SYS_truncate64
109+
SYS_ugetrlimit
110+
SYS_unlink
111+
SYS_uselib
112+
SYS_ustat
113+
SYS_utimes
114+
SYS_vfork
115+
SYS_vserver
116+
__c_anonymous_uc_sigmask
117+
__c_anonymous_uc_sigmask_with_padding
118+
greg_t
119+
sigcontext
120+
time64_t
121+
timegm64

libc-test/semver/android-i686.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__c_anonymous_uc_sigmask
2+
__c_anonymous_uc_sigmask_with_padding
3+
time64_t
4+
timegm64

libc-test/semver/android-x86_64.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
EFLAGS
2+
FS_BASE
3+
GS_BASE
4+
ORIG_RAX
5+
R10
6+
R11
7+
R12
8+
R13
9+
R14
10+
R15
11+
R8
12+
R9
13+
RAX
14+
RBP
15+
RBX
16+
RCX
17+
RDI
18+
RDX
19+
REG_CR2
20+
REG_CSGSFS
21+
REG_OLDMASK
22+
REG_R10
23+
REG_R11
24+
REG_R12
25+
REG_R13
26+
REG_R14
27+
REG_R15
28+
REG_R8
29+
REG_R9
30+
REG_RAX
31+
REG_RBP
32+
REG_RBX
33+
REG_RCX
34+
REG_RDI
35+
REG_RDX
36+
REG_RIP
37+
REG_RSI
38+
REG_RSP
39+
RIP
40+
RSI
41+
RSP
42+
SYS_accept
43+
SYS_arch_prctl
44+
SYS_epoll_ctl_old
45+
SYS_epoll_wait_old
46+
SYS_kexec_file_load
47+
SYS_msgctl
48+
SYS_msgget
49+
SYS_msgrcv
50+
SYS_msgsnd
51+
SYS_newfstatat
52+
SYS_security
53+
SYS_semctl
54+
SYS_semget
55+
SYS_semop
56+
SYS_semtimedop
57+
SYS_shmat
58+
SYS_shmctl
59+
SYS_shmdt
60+
SYS_shmget
61+
SYS_tuxcall
62+
SYS_vserver
63+
__c_anonymous_uc_sigmask
64+
_libc_fpxreg
65+
_libc_xmmreg

0 commit comments

Comments
 (0)