diff --git a/Cargo.toml b/Cargo.toml index 58135637e3f659281cbcca5a8e80c206fb8d27e5..12f3c5a26570095d63a904deb38d00e2f273dc09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["staticlib"] [workspace] members = ["src/crt0", "src/crti", "src/crtn", "src/ld_so"] -exclude = ["core_io", "ralloc"] +exclude = ["core_io", "ralloc", "tests"] [build-dependencies] cbindgen = "0.13.2" diff --git a/redoxer.sh b/redoxer.sh index fcb352c742b3f9740a918b134c503489215be81f..0c28c8039a454c92f9a180d546cb598f2daaabc7 100755 --- a/redoxer.sh +++ b/redoxer.sh @@ -13,5 +13,5 @@ then fi export CARGO_TEST="redoxer" -export TEST_RUNNER="redoxer exec --folder . -- sh --" +export TEST_RUNNER="redoxer exec --folder . --" redoxer env make "$@" diff --git a/tests/.gitignore b/tests/.gitignore index 748ff9d390dd6f07397b222de5591b2cfc268d4a..604e32da6c3c37f56986c66f2b2bebb898277c35 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,4 +1,3 @@ -/bins_static/ -/bins_dynamic/ +/bins_*/ /gen/ /*.out diff --git a/tests/Cargo.lock b/tests/Cargo.lock new file mode 100644 index 0000000000000000000000000000000000000000..40fd7924fc06418bc3bb959cd15062ef98d2c762 --- /dev/null +++ b/tests/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "relibc-tests" +version = "0.1.0" diff --git a/tests/Cargo.toml b/tests/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..d679f7f4ae7c90a9d67320736b37d96259bfe101 --- /dev/null +++ b/tests/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "relibc-tests" +version = "0.1.0" +authors = ["Jeremy Soller <jeremy@system76.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/Makefile b/tests/Makefile index 71f9bcff70383520a851d39208a626d04f0be1e7..506408fe06e42fbb19ac09d30b0343cd780b8502 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -158,7 +158,8 @@ EXPECT_BINS=$(patsubst %,bins_static/%,$(EXPECT_NAMES)) EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(EXPECT_NAMES)) EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES)) -TEST_RUNNER?=sh -- +CARGO_TEST?=cargo +TEST_RUNNER?= .PHONY: all clean run expected verify @@ -184,8 +185,11 @@ expected: | $(EXPECT_BINS) "$${bin}" test args > "expected/$${bin}.stdout" 2> "expected/$${bin}.stderr" || exit $$?; \ done -verify: | $(EXPECT_BINS) - $(TEST_RUNNER) ./verify.sh $(EXPECT_BINS) +bins_verify/relibc-tests: src/main.rs + $(CARGO_TEST) build --release --bin relibc-tests --out-dir bins_verify -Z unstable-options + +verify: bins_verify/relibc-tests | $(EXPECT_BINS) + $(TEST_RUNNER) $< $(EXPECT_BINS) FLAGS=\ -std=c11 \ diff --git a/tests/src/main.rs b/tests/src/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..5f85a4f330e6de19259e5f4d623b6056ea243241 --- /dev/null +++ b/tests/src/main.rs @@ -0,0 +1,79 @@ +use std::{ + env, fs, + io::{self, Write}, + path::PathBuf, + process::{self, Command, ExitStatus}, +}; + +fn expected(bin: &str, kind: &str, generated: &[u8], status: ExitStatus) -> Result<(), String> { + let mut expected_file = PathBuf::from(format!("expected/{}.{}", bin, kind)); + if !expected_file.exists() { + expected_file = PathBuf::from(format!( + "expected/{}.{}", + bin.replace("bins_static", "").replace("bins_dynamic", ""), + kind + )); + } + + let expected = match fs::read(&expected_file) { + Ok(ok) => ok, + Err(err) => { + return Err(format!( + "{} failed to read {}: {}", + bin, + expected_file.display(), + err + )); + } + }; + + if expected != generated { + println!("# {}: {}: expected #", bin, kind); + io::stdout().write(&expected).unwrap(); + + println!("# {}: {}: generated #", bin, kind); + io::stdout().write(generated).unwrap(); + + return Err(format!( + "{} failed - retcode {}, {} mismatch", + bin, status, kind + )); + } + + Ok(()) +} + +fn main() { + let mut failures = Vec::new(); + + for bin in env::args().skip(1) { + println!("# {} #", bin); + + match Command::new(&bin).arg("test").arg("args").output() { + Ok(output) => { + if let Err(failure) = expected(&bin, "stdout", &output.stdout, output.status) { + println!("{}", failure); + failures.push(failure); + } + + if let Err(failure) = expected(&bin, "stderr", &output.stderr, output.status) { + println!("{}", failure); + failures.push(failure); + } + } + Err(err) => { + let failure = format!("{}: failed to execute: {}", bin, err); + println!("{}", failure); + failures.push(failure); + } + } + } + + if !failures.is_empty() { + println!("# FAILURES #"); + for failure in failures { + println!("{}", failure); + } + process::exit(1); + } +} diff --git a/tests/verify.sh b/tests/verify.sh deleted file mode 100755 index 26ebff0495d58b832ef179d646b7302c5e300320..0000000000000000000000000000000000000000 --- a/tests/verify.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/sh - -rm -rf gen || exit 1 -mkdir -p gen || exit 1 - -summary="" - -while [ "$#" -gt 0 ] -do - bin="$1" - shift - - echo "# ${bin} #" - mkdir -p "gen/$(dirname ${bin})" || exit 1 - - "${bin}" test args > "gen/${bin}.stdout" 2> "gen/${bin}.stderr" - retcode="$?" - status="" - - for output in stdout stderr - do - gen="$(sha256sum "gen/${bin}.${output}" | cut -d " " -f 1)" - - # look for expected output file that is specific to binary type (either static or dynamic) - expected_file="expected/${bin}.${output}" - if [ ! -e $expected_file ] - then - # if unable to find above, the expected output file is the same to both static and dynamic binary - name=$(echo $bin | cut -d "/" -f2-) - expected_file="expected/${name}.${output}" - fi - expected="$(sha256sum "${expected_file}" | cut -d " " -f 1)" - if [ "${gen}" != "${expected}" ] - then - echo "# ${bin}: ${output}: expected #" - cat "${expected_file}" - - echo "# ${bin}: ${output}: generated #" - cat "gen/${bin}.${output}" - - # FIXME: Make diff available on Redox - if [ $(uname) != "Redox" ] - then - echo "# ${bin}: ${output}: diff #" - diff --color -u "${expected_file}" "gen/${bin}.${output}" - fi - - status="${bin} failed - retcode ${retcode}, ${output} mismatch" - summary="${summary}${status}\n" - fi - done - - if [ -n "${status}" ] - then - echo "# ${status} #" - fi -done - -if [ -n "$summary" ] -then - echo -e "$summary" - exit 1 -fi