Skip to content

Commit

Permalink
Auto merge of #2109 - Thomasdezeeuw:issue_2104-regression_tests, r=<try>
Browse files Browse the repository at this point in the history
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 Apr 1, 2021
2 parents 10d99b9 + e4b700a commit 9c8b37e
Show file tree
Hide file tree
Showing 44 changed files with 18,599 additions and 77 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Docker Linux Tier1
runs-on: ubuntu-20.04
strategy:
fail-fast: true
fail-fast: false
matrix:
target: [
i686-unknown-linux-gnu,
Expand All @@ -31,7 +31,7 @@ jobs:
name: macOS
runs-on: macos-10.15
strategy:
fail-fast: true
fail-fast: false
matrix:
target: [
x86_64-apple-darwin,
Expand All @@ -52,7 +52,7 @@ jobs:
env:
OS: windows
strategy:
fail-fast: true
fail-fast: false
matrix:
include:
- target: x86_64-pc-windows-gnu
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
name: Style check
runs-on: ubuntu-20.04
strategy:
fail-fast: true
fail-fast: false
steps:
- uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
with:
Expand All @@ -99,7 +99,7 @@ jobs:
needs: [docker_linux_tier1, style_check]
runs-on: ubuntu-20.04
strategy:
fail-fast: true
fail-fast: false
max-parallel: 12
matrix:
target: [
Expand Down Expand Up @@ -153,7 +153,7 @@ jobs:
needs: [docker_linux_tier1, style_check]
runs-on: ubuntu-20.04
strategy:
fail-fast: true
fail-fast: false
steps:
- uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
with:
Expand All @@ -171,7 +171,7 @@ jobs:
env:
OS: linux
strategy:
fail-fast: true
fail-fast: false
max-parallel: 5
matrix:
toolchain: [
Expand Down Expand Up @@ -201,7 +201,7 @@ jobs:
env:
OS: macos
strategy:
fail-fast: true
fail-fast: false
max-parallel: 4
matrix:
toolchain: [
Expand Down Expand Up @@ -230,7 +230,7 @@ jobs:
runs-on: ubuntu-20.04
continue-on-error: true
strategy:
fail-fast: true
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Setup Rust toolchain
Expand All @@ -245,7 +245,7 @@ jobs:
runs-on: macos-10.15
continue-on-error: true
strategy:
fail-fast: true
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Setup Rust toolchain
Expand All @@ -259,7 +259,7 @@ jobs:
runs-on: ubuntu-20.04
needs: docker_linux_tier2
strategy:
fail-fast: true
fail-fast: false
steps:
- uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
with:
Expand Down
65 changes: 1 addition & 64 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,74 +8,11 @@ on:
- master

jobs:
docker_linux_tier1:
name: Docker Linux Tier1
runs-on: ubuntu-20.04
strategy:
fail-fast: true
matrix:
target: [
i686-unknown-linux-gnu,
x86_64-unknown-linux-gnu,
]
steps:
- uses: actions/checkout@v2
- name: Setup Rust toolchain
run: TARGET=${{ matrix.target }} sh ./ci/install-rust.sh
- name: Execute run-docker.sh
run: LIBC_CI=1 sh ./ci/run-docker.sh ${{ matrix.target }}

macos:
name: macOS
runs-on: macos-10.15
strategy:
fail-fast: true
matrix:
target: [
x86_64-apple-darwin,
]
steps:
- uses: actions/checkout@v2
- name: Setup Rust toolchain
run: TARGET=${{ matrix.target }} sh ./ci/install-rust.sh
- name: Execute run.sh
run: LIBC_CI=1 sh ./ci/run.sh ${{ matrix.target }}

windows:
name: Windows
runs-on: windows-2019
env:
OS: windows
strategy:
fail-fast: true
matrix:
include:
- target: x86_64-pc-windows-gnu
env:
ARCH_BITS: 64
ARCH: x86_64
- target: x86_64-pc-windows-msvc
# Disabled because broken:
# https://github.com/rust-lang/libc/issues/1592
#- target: i686-pc-windows-gnu
# env:
# ARCH_BITS: 32
# ARCH: i686
- target: i686-pc-windows-msvc
steps:
- uses: actions/checkout@v2
- name: Setup Rust toolchain
run: TARGET=${{ matrix.target }} sh ./ci/install-rust.sh
shell: bash
- name: Execute run.sh
run: LIBC_CI=1 sh ./ci/run.sh ${{ matrix.target }}
shell: bash

style_check:
name: Style check
runs-on: ubuntu-20.04
strategy:
fail-fast: true
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Setup Rust toolchain
Expand Down
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

0 comments on commit 9c8b37e

Please sign in to comment.