Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Project Keter's test runner to this project #3

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7913179
chore: Set up keter-test
notgull Dec 24, 2023
45e7bab
feat(test): Add test harness
notgull Dec 24, 2023
e883d78
chore: Use keter-test in keter-reactor
notgull Dec 24, 2023
dd43095
feat(test): Asyncify the Reporter trait
notgull Dec 24, 2023
263493c
feat(test): Add TCP test harness backend
notgull Dec 24, 2023
e98ce17
chore: Beginnings of test runner crate
notgull Dec 24, 2023
01ece7f
feat(test-runner): Add clippy support
notgull Dec 24, 2023
8444c3a
feat(test-runner): Different host environments
notgull Dec 24, 2023
dba508f
chore: Put a bow on functionality testing
notgull Dec 25, 2023
b60d170
chore: Fix minor warts
notgull Dec 25, 2023
9863aa0
m(test-runner): Cache test environments
notgull Dec 26, 2023
739e8a1
feat(test): Add Unix socket test harness
notgull Dec 26, 2023
14792a5
chore: Rearrange project so xbuild works
notgull Dec 26, 2023
15e682e
feat(test-runner): Android environment setup
notgull Dec 26, 2023
920be7f
feat(test-runner): Setup Docker test harness
notgull Dec 26, 2023
7347f7f
chore(test-runner): Test runner fixes
notgull Dec 29, 2023
1cc6d8b
chore: Setup android runner and keter tests
notgull Jan 5, 2024
edc3006
feat(test-runner): Pwd arg for HostEnvironment
notgull Jan 5, 2024
f6fa977
feat(test-runner): Add pwd option to Command
notgull Jan 6, 2024
74aebc4
bugfix(test-harness): Fix Android harness
notgull Jan 6, 2024
ac3208d
chore(test-runner): Fix some warnings
notgull Jan 6, 2024
e1a0643
bugfix(test-runner): Tests now appear in docker
notgull Jan 6, 2024
2221c78
chore(test): keter -> winit
notgull Jan 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/target
Cargo.lock
/Cargo.lock
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
members = [ "winit",
"winit-core", "winit-examples",
"winit-wayland",
"winit-test",
"winit-test-runner"
]
resolver = "2"

[workspace.dependencies]
winit-test = { path = "winit-test" }
17 changes: 17 additions & 0 deletions ci/build_docker_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

set -eu

rx() {
echo >&2 "+ $*"
"$@"
}
build_dockerfile() {
tag="$1"
name="$2"

rx docker build . -f dockerfiles/"$name" \
-t ghcr.io/notgull/winit_test:"$tag"
}

build_dockerfile ubuntu Dockerfile.ubuntu
56 changes: 56 additions & 0 deletions ci/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh
# MIT/Apache2 License

set -eu

rx() {
echo >&2 "+ $*"
"$@"
}
no_out() {
cmd_noout="$1"
shift
"$cmd_noout" "$@" > /dev/null 2> /dev/null
}
bail() {
echo "[fatal] $*"
exit 1
}
info() {
echo "[info] $*"
}
bail_if_absent() {
if ! no_out command -v "$1"; then
bail "could not find $1"
fi
}
test_runner() {
bail_if_absent "${CARGO:-cargo}"
rx "${CARGO:-cargo}" run --release -p winit-test-runner -- "$@"
}

basedir="$(dirname -- "$(dirname -- "$0")")"
cd "$basedir" || exit 1

config_path="${1:-basedir/ci/tests_linux.json}"

# Tell which level of test we're running.
case "${2:-2}" in
0) info "running level 0 (style) tests"; level=0 ;;
1) info "running level 1 (function) tests"; level=1 ;;
2) info "running level 2 (full) tests"; level=2 ;;
*) bail "unknown test level $1" ;;
esac

# Always run style tests.
#test_runner style --config "$config_path"

# At level 1 or higher, run functionality tests.
#if [ "$level" -ge 1 ]; then
# test_runner functionality --config "$config_path"
#fi

# At level 2 or higher, run full tests.
if [ "$level" -ge 2 ]; then
test_runner full --config "$config_path"
fi
10 changes: 10 additions & 0 deletions ci/tests_android.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"name": "winit-core",
"checks": [
{
"target": "x86_64-linux-android"
}
]
}
]
10 changes: 10 additions & 0 deletions ci/tests_linux.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"name": "winit-core",
"checks": [
{
"target": "x86_64-unknown-linux-gnu"
}
]
}
]
18 changes: 18 additions & 0 deletions dockerfiles/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Ubuntu testing container
# Usually tagged as ghcr.io/notgull/winit:ubuntu

FROM rust as final
ARG DEBIAN_FRONTEND=noninteractive

RUN \
apt-get -o Acquire::Retries=10 -qq update && \
apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends \
xvfb \
libx11-dev \
libxcb1-dev \
libxkbcommon-dev && \
rm -rf \
/var/lib/apt/lists/* \
/var/cache/* \
/var/log/* \
/usr/share/{doc,man}
8 changes: 8 additions & 0 deletions winit-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ publish = false
bitflags = "2.4.1"
raw-window-handle = "0.6.0"
raw-window-handle-05 = { package = "raw-window-handle", version = "0.5.2" }

[dev-dependencies]
futures-lite = "2.0.0"
winit-test.workspace = true

[[example]]
name = "winit-core_hello_world"
path = "winit_tests/hello_world/src/lib.rs"
14 changes: 14 additions & 0 deletions winit-core/winit_tests/hello_world/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// MIT/Apache2 License

use futures_lite::future::block_on;

#[allow(clippy::eq_op)]
fn main() {
winit_test::run_tests(|harness| {
block_on(async move {
harness.test("hello world", async {
assert_eq!(1 + 1, 2)
}).await;
});
Comment on lines +3 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need any tests here? This doesn't have any core logic stuff it should all go into the winit crate instead.

})
}
31 changes: 31 additions & 0 deletions winit-test-runner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "winit-test-runner"
version = "0.1.0"
edition = "2021"
authors = ["John Nunley <[email protected]>"]
publish = false

[dependencies]
async-channel = "2.1.1"
async-executor = "1.8.0"
async-fs = "2.1.0"
async-io = "2.2.2"
async-lock = "3.2.0"
async-process = "2.0.1"
blocking = "1.5.1"
clap = "4.4.11"
color-eyre = "0.6.2"
eyre = "0.6.11"
futures-lite = "2.1.0"
human-panic = "1.2.2"
ignore = "0.4.21"
winit-test.workspace = true
once_cell = "1.19.0"
owo-colors = "4.0.0"
pin-project-lite = "0.2.13"
regex = "1.10.2"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
tracing = { version = "0.1.40", default-features = false, features = ["async-await"] }
tracing-subscriber = "0.3.18"
which = "5.0.0"
23 changes: 23 additions & 0 deletions winit-test-runner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# winit-test-runner

Test runner for `winit`.

This binary acts as orchestration for running tests in `winit`. In addition to
what is often used in normal Rust tests (formatting, Clippy, unit tests), it also
runs those tests in cross-compilation environments on other platforms.

There are different types of tests:

- **Style tests** make sure that code is formatted and linted properly.
`cargo fmt` and `cargo clippy` are used to inspect Rust code.
- **Functionality tests** run the doctests and unit tests in Rust code. These
often ensure that basic functionality and logic are in working order.
- **Host tests** run the `winit` test suite on the current host. This test suite
fully tests the functionality of `winit` to ensure that it is working properly.
A full CI run with `winit` should be fully bug-free.
- **Cross tests** run the `winit` test suite in Docker containers/virtual
machines in order to ensure `winit` works on all possible hosts.

## License

MIT/Apache2
4 changes: 4 additions & 0 deletions winit-test-runner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// MIT/Apache2 License

mod runner;
pub use runner::*;
79 changes: 79 additions & 0 deletions winit-test-runner/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// MIT/Apache2 License

mod runner;

use std::path::Path;
use std::process::exit;

use color_eyre::{eyre::bail, Result};
use owo_colors::OwoColorize;

fn main() {
// Setup error hooks.
tracing_subscriber::fmt::try_init().ok();
color_eyre::install().ok();

// Get CLI matches.
let matches = cli().get_matches();

// Run the main function.
if let Err(e) = async_io::block_on(entry(matches)) {
println!("{}{:?}", "encountered a fatal error: ".red().bold(), e);
exit(1);
}
}

async fn entry(matches: clap::ArgMatches) -> Result<()> {
match matches.subcommand() {
None => bail!("expected a subcommand"),
Some(("style", matches)) => {
let crates = read_config(matches.get_one::<String>("config").unwrap()).await?;
runner::Test::Style.run(crates).await?;
}
Some(("functionality", matches)) => {
let crates = read_config(matches.get_one::<String>("config").unwrap()).await?;
runner::Test::Functionality.run(crates).await?;
}
Some(("full", matches)) => {
let crates = read_config(matches.get_one::<String>("config").unwrap()).await?;
runner::Test::Host.run(crates).await?;
}
Some((subcommand, _matches)) => bail!("unknown subcommand {subcommand}"),
}

Ok(())
}

async fn read_config(path: impl AsRef<Path>) -> Result<Vec<runner::Crate>> {
let data = async_fs::read(path).await?;
let crates = serde_json::from_slice(&data)?;
Ok(crates)
}

fn cli() -> clap::Command {
clap::Command::new("winit-test-runner")
.subcommand(
clap::Command::new("style").arg(
clap::Arg::new("config")
.required(true)
.short('c')
.long("config"),
),
)
.subcommand(
clap::Command::new("functionality").arg(
clap::Arg::new("config")
.required(true)
.short('c')
.long("config"),
),
)
.subcommand(
clap::Command::new("full").arg(
clap::Arg::new("config")
.required(true)
.short('c')
.long("config"),
),
)
}
Loading