Skip to content

Commit

Permalink
Auto merge of #2109 - Thomasdezeeuw:issue_2104-regression_tests, r=Jo…
Browse files Browse the repository at this point in the history
…hnTitor

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.
  • Loading branch information
bors committed Mar 27, 2021
2 parents a309e91 + 8fb63e8 commit e1db690
Show file tree
Hide file tree
Showing 42 changed files with 18,587 additions and 2 deletions.
12 changes: 11 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,24 @@ at, fear not! This crate has CI support which tests any binding against all
platforms supported, so you'll see failures if an API is added at the wrong
level or has different signatures across platforms.

New symbol(s) (i.e. functions, constants etc.) should also be added to the
symbols list(s) found in the `libc-test/semver` directory. These lists keep
track of what symbols are public in the libc crate and ensures they remain
available between changes to the crate. If the new symbol(s) are available on
all supported Unixes it should be added to `unix.txt` list<sup>1</sup>,
otherwise they should be added to the OS specific list(s).

With that in mind, the steps for adding a new API are:

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

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

## Test before you commit

We have two automated tests running on [GitHub Actions](https://github.com/rust-lang/libc/actions):
Expand Down
5 changes: 5 additions & 0 deletions libc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ harness = true
name = "errqueue"
path = "test/errqueue.rs"
harness = true

[[test]]
name = "semver"
path = "test/semver.rs"
harness = false
81 changes: 80 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
extern crate cc;
extern crate ctest2 as ctest;

use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::{env, io};

fn do_cc() {
let target = env::var("TARGET").unwrap();
Expand Down Expand Up @@ -63,9 +66,85 @@ fn ctest_cfg() -> ctest::TestGenerator {
cfg
}

fn do_semver() {
let mut out = PathBuf::from(env::var("OUT_DIR").unwrap());
out.push("semver.rs");
let mut output = BufWriter::new(File::create(&out).unwrap());

let family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap();
let vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
let os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();

// `libc-test/semver` dir.
let mut semver_root =
PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
semver_root.push("semver");

// NOTE: Windows has the same `family` as `os`, no point in including it
// twice.
// NOTE: Android doesn't include the unix file (or the Linux file) because
// there are some many definitions missing it's actually easier just to
// maintain a file for Android.
if family != os && os != "android" {
process_semver_file(&mut output, &mut semver_root, &family);
}
process_semver_file(&mut output, &mut semver_root, &vendor);
process_semver_file(&mut output, &mut semver_root, &os);
let os_arch = format!("{}-{}", os, arch);
process_semver_file(&mut output, &mut semver_root, &os_arch);
if target_env != "" {
let os_env = format!("{}-{}", os, target_env);
process_semver_file(&mut output, &mut semver_root, &os_env);

let os_env_arch = format!("{}-{}-{}", os, target_env, arch);
process_semver_file(&mut output, &mut semver_root, &os_env_arch);
}
}

fn process_semver_file<W: Write, P: AsRef<Path>>(
output: &mut W,
path: &mut PathBuf,
file: P,
) {
// NOTE: `path` is reused between calls, so always remove the file again.
path.push(file);
path.set_extension("txt");

println!("cargo:rerun-if-changed={}", path.display());
let input_file = match File::open(&*path) {
Ok(file) => file,
Err(ref err) if err.kind() == io::ErrorKind::NotFound => {
path.pop();
return;
}
Err(err) => panic!("unexpected error opening file: {}", err),
};
let input = BufReader::new(input_file);

write!(output, "// Source: {}.\n", path.display()).unwrap();
output.write(b"use libc::{\n").unwrap();
for line in input.lines() {
let line = line.unwrap().into_bytes();
match line.first() {
// Ignore comments and empty lines.
Some(b'#') | None => continue,
_ => {
output.write(b" ").unwrap();
output.write(&line).unwrap();
output.write(b",\n").unwrap();
}
}
}
output.write(b"};\n\n").unwrap();
path.pop();
}

fn main() {
do_cc();
do_ctest();
do_semver();
}

macro_rules! headers {
Expand Down
17 changes: 17 additions & 0 deletions libc-test/semver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Supported API by libc

These files are read by [`build.rs`](../build.rs) and turned into tests to
ensure that APIs aren't removed between libc releases.

## File order

Files are including in the following order:
* Family, e.g. `unix.txt`. NOTE: Windows is skipped here and includes as OS
name below.
* Vendor, e.g. `apple.txt`. This allows us to have a single file with system
calls shared between multiple OSs, e.g. `ios.txt`, `macos.txt` share the same
kernel.
* OS, e.g `linux.txt`, `macos.txt`, `windows.txt`.
* Architecture specific system calls, e.g. `linux-x86_64.txt` or
`linux-aarch64.txt`.
* Target environment, e.g. `windows-mscv.txt` or `windows-gnu.txt`.
11 changes: 11 additions & 0 deletions libc-test/semver/android-aarch64.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
HWCAP2_DCPODP
HWCAP2_FLAGM2
HWCAP2_FRINT
HWCAP2_SVE2
HWCAP2_SVEAES
HWCAP2_SVEBITPERM
HWCAP2_SVEPMULL
HWCAP2_SVESHA3
HWCAP2_SVESM4
SYS_arch_specific_syscall
SYS_syscalls
121 changes: 121 additions & 0 deletions libc-test/semver/android-arm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
NGREG
PTRACE_GETFPREGS
PTRACE_GETREGS
PTRACE_SETFPREGS
PTRACE_SETREGS
REG_R0
REG_R1
REG_R10
REG_R11
REG_R12
REG_R13
REG_R14
REG_R15
REG_R2
REG_R3
REG_R4
REG_R5
REG_R6
REG_R7
REG_R8
REG_R9
SYS_accept
SYS_access
SYS_arm_fadvise64_64
SYS_arm_sync_file_range
SYS_bdflush
SYS_chmod
SYS_chown
SYS_chown32
SYS_creat
SYS_dup2
SYS_epoll_create
SYS_epoll_wait
SYS_eventfd
SYS_fchown32
SYS_fcntl64
SYS_fork
SYS_fstat64
SYS_fstatat64
SYS_fstatfs64
SYS_ftruncate64
SYS_futimesat
SYS_getdents
SYS_getegid32
SYS_geteuid32
SYS_getgid32
SYS_getgroups32
SYS_getpgrp
SYS_getresgid32
SYS_getresuid32
SYS_getuid32
SYS_inotify_init
SYS_lchown
SYS_lchown32
SYS_link
SYS_lstat
SYS_lstat64
SYS_mkdir
SYS_mknod
SYS_mmap2
SYS_msgctl
SYS_msgget
SYS_msgrcv
SYS_msgsnd
SYS_nice
SYS_open
SYS_pause
SYS_pciconfig_iobase
SYS_pciconfig_read
SYS_pciconfig_write
SYS_pipe
SYS_poll
SYS_readlink
SYS_recv
SYS_rename
SYS_rmdir
SYS_semctl
SYS_semget
SYS_semop
SYS_semtimedop
SYS_send
SYS_sendfile
SYS_sendfile64
SYS_setfsgid32
SYS_setfsuid32
SYS_setgid32
SYS_setgroups32
SYS_setregid32
SYS_setresgid32
SYS_setresuid32
SYS_setreuid32
SYS_setuid32
SYS_shmat
SYS_shmctl
SYS_shmdt
SYS_shmget
SYS_sigaction
SYS_signalfd
SYS_sigpending
SYS_sigprocmask
SYS_sigreturn
SYS_sigsuspend
SYS_stat
SYS_stat64
SYS_statfs64
SYS_symlink
SYS_sysfs
SYS_truncate64
SYS_ugetrlimit
SYS_unlink
SYS_uselib
SYS_ustat
SYS_utimes
SYS_vfork
SYS_vserver
__c_anonymous_uc_sigmask
__c_anonymous_uc_sigmask_with_padding
greg_t
sigcontext
time64_t
timegm64
4 changes: 4 additions & 0 deletions libc-test/semver/android-i686.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__c_anonymous_uc_sigmask
__c_anonymous_uc_sigmask_with_padding
time64_t
timegm64
65 changes: 65 additions & 0 deletions libc-test/semver/android-x86_64.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
EFLAGS
FS_BASE
GS_BASE
ORIG_RAX
R10
R11
R12
R13
R14
R15
R8
R9
RAX
RBP
RBX
RCX
RDI
RDX
REG_CR2
REG_CSGSFS
REG_OLDMASK
REG_R10
REG_R11
REG_R12
REG_R13
REG_R14
REG_R15
REG_R8
REG_R9
REG_RAX
REG_RBP
REG_RBX
REG_RCX
REG_RDI
REG_RDX
REG_RIP
REG_RSI
REG_RSP
RIP
RSI
RSP
SYS_accept
SYS_arch_prctl
SYS_epoll_ctl_old
SYS_epoll_wait_old
SYS_kexec_file_load
SYS_msgctl
SYS_msgget
SYS_msgrcv
SYS_msgsnd
SYS_newfstatat
SYS_security
SYS_semctl
SYS_semget
SYS_semop
SYS_semtimedop
SYS_shmat
SYS_shmctl
SYS_shmdt
SYS_shmget
SYS_tuxcall
SYS_vserver
__c_anonymous_uc_sigmask
_libc_fpxreg
_libc_xmmreg

0 comments on commit e1db690

Please sign in to comment.