Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
1e7c789
Integrate experimental HTTP into wasmtime.
brendandburns Dec 27, 2022
63887e0
Reset Cargo.lock
brendandburns Mar 18, 2023
8ecc77e
Switch to bail!, plumb options partially.
brendandburns Mar 18, 2023
8657c7c
Implement timeouts.
brendandburns Mar 21, 2023
c983d73
Remove generated files & wasm, add Makefile
brendandburns Mar 21, 2023
febe6bd
Remove generated code textfile
brendandburns Mar 21, 2023
320d620
Update crates/wasi-http/Cargo.toml
brendandburns Mar 23, 2023
356ffa6
Update crates/wasi-http/Cargo.toml
brendandburns Mar 23, 2023
7ed508c
Extract streams from request/response.
brendandburns Mar 21, 2023
4bfde02
Fix read for len < buffer length.
brendandburns Mar 24, 2023
dff5986
Formatting.
brendandburns Mar 24, 2023
aee848b
types impl: swap todos for traps
Mar 24, 2023
41a922f
streams_impl: idioms, and swap todos for traps
Mar 24, 2023
4dbade6
component impl: idioms, swap all unwraps for traps, swap all todos fo…
Mar 24, 2023
8e1b481
http impl: idiom
Mar 24, 2023
76eb40e
Merge pull request #1 from pchickey/pch/wasi_http
brendandburns Mar 24, 2023
08dd153
Merge branch 'bytecodealliance:main' into wasi_http
brendandburns Mar 27, 2023
2a815e0
Remove an unnecessary mut.
brendandburns Mar 28, 2023
9913785
Remove an unsupported function.
brendandburns Mar 28, 2023
96279bf
Switch to the tokio runtime for the HTTP request.
brendandburns Mar 28, 2023
1e23a06
Add a rust example.
brendandburns Mar 28, 2023
57a86aa
Update to latest wit definition
brendandburns Mar 30, 2023
3372ab0
Remove example code.
brendandburns Mar 30, 2023
27f2134
wip: start writing a http test...
Mar 27, 2023
6b7d84d
finish writing the outbound request example
Mar 27, 2023
54dbf97
better debug output
Mar 27, 2023
eb619bd
wasi-http: some stubs required for rust rewrite of the example
Mar 27, 2023
86a0c5d
add wasi_http tests to test-programs
Mar 28, 2023
64d6979
CI: run the http tests
Mar 28, 2023
7c9cfd2
Fix some warnings.
brendandburns Mar 30, 2023
3df74cf
bump new deps to latest releases (#3)
pchickey Mar 30, 2023
8b1a8a3
Merge branch 'bytecodealliance:main' into wasi_http
brendandburns Mar 30, 2023
b73fad8
Update crates/test-programs/tests/http_tests/runtime/wasi_http_tests.rs
pchickey Mar 30, 2023
ff6bf4a
Update crates/test-programs/tests/http_tests/runtime/wasi_http_tests.rs
pchickey Mar 30, 2023
daf5cc6
Update crates/test-programs/tests/http_tests/runtime/wasi_http_tests.rs
pchickey Mar 30, 2023
362696a
wasi-http: fix cargo.toml file and publish script to work together (#4)
pchickey Mar 31, 2023
f9fe6d4
Update crates/test-programs/build.rs
pchickey Mar 31, 2023
cd7bb1f
Switch to rustls
brendandburns Mar 31, 2023
039bc9e
Cleanups.
brendandburns Mar 31, 2023
0150963
Merge switch to rustls.
brendandburns Mar 31, 2023
28ebfe2
Formatting
brendandburns Mar 31, 2023
04f3e13
Remove libssl install
brendandburns Mar 31, 2023
f02db0f
Fix tests.
brendandburns Mar 31, 2023
1e3a651
Merge branch 'bytecodealliance:main' into wasi_http
brendandburns Apr 4, 2023
0c704c7
Rename wasi-http -> wasmtime-wasi-http
brendandburns Apr 4, 2023
390499b
Merge branch 'wasi_http' of https://github.com/brendandburns/wasmtime…
brendandburns Apr 4, 2023
8caa666
prtest:full
brendandburns Apr 5, 2023
b6b70f5
prtest:full
brendandburns Apr 5, 2023
c16aa23
prtest:full
brendandburns Apr 5, 2023
35e6a59
prtest:full
brendandburns Apr 5, 2023
9b2312b
Merge branch 'main' into wasi_http
brendandburns Apr 5, 2023
e536195
Merge branch 'main' into wasi_http
brendandburns Apr 5, 2023
224ba1c
Update crates/wasi-http/Cargo.toml
pchickey Apr 5, 2023
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
Prev Previous commit
Next Next commit
add wasi_http tests to test-programs
  • Loading branch information
Pat Hickey authored and brendandburns committed Mar 30, 2023
commit 86a0c5dd3f824a7890e81b5914ef0e6daf140515
43 changes: 43 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/test-programs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license = "Apache-2.0 WITH LLVM-exception"

[build-dependencies]
cfg-if = "1.0"
cargo_metadata = "0.15.3"

[dev-dependencies]
wasi-common = { workspace = true }
Expand All @@ -23,6 +24,8 @@ anyhow = { workspace = true }
wat = { workspace = true }
cap-std = { workspace = true }
tokio = { version = "1.8.0", features = ["rt-multi-thread"] }
wasi-http = { workspace = true }

[features]
test_programs = []
test_programs_http = [ "wasmtime/component-model" ]
266 changes: 176 additions & 90 deletions crates/test-programs/build.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,105 @@
#![allow(dead_code)]
//! Build program to generate a program which runs all the testsuites.
//!
//! By generating a separate `#[test]` test for each file, we allow cargo test
//! to automatically run the files in parallel.
use std::fs::{read_dir, File};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

fn main() {
#[cfg(feature = "test_programs")]
wasi_tests::build_and_generate_tests()
wasi_tests::build_and_generate_tests();
#[cfg(feature = "test_programs_http")]
wasi_http_tests::build_and_generate_tests();
}

fn build_tests(testsuite: &str, out_dir: &Path) -> io::Result<Vec<String>> {
let mut cmd = Command::new("cargo");
cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "1");
cmd.env_remove("CARGO_ENCODED_RUSTFLAGS");
cmd.args(&[
"build",
"--release",
"--target=wasm32-wasi",
"--target-dir",
out_dir.to_str().unwrap(),
])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.current_dir(testsuite);
let output = cmd.output()?;

let status = output.status;
if !status.success() {
panic!(
"Building tests failed: exit code: {}",
status.code().unwrap()
);
}

let meta = cargo_metadata::MetadataCommand::new()
.manifest_path(PathBuf::from(testsuite).join("Cargo.toml"))
.exec()
.expect("cargo metadata");

Ok(meta
.packages
.iter()
.find(|p| p.name == testsuite)
.unwrap()
.targets
.iter()
.filter(|t| t.kind == ["bin"])
.map(|t| t.name.clone())
.collect::<Vec<String>>())
}

#[allow(dead_code)]
fn test_directory(
out: &mut File,
test_binaries: &[String],
testsuite: &str,
runtime: &str,
out_dir: &Path,
mut write_testsuite_tests: impl FnMut(&mut File, &Path, &str) -> io::Result<()>,
) -> io::Result<()> {
writeln!(
out,
"mod {} {{",
Path::new(testsuite)
.file_stem()
.expect("testsuite filename should have a stem")
.to_str()
.expect("testsuite filename should be representable as a string")
.replace("-", "_")
)?;
writeln!(
out,
" use super::{{runtime::{} as runtime, utils, setup_log}};",
runtime
)?;
for test_binary in test_binaries {
let binary_path = out_dir
.join("wasm32-wasi")
.join("release")
.join(format!("{}.wasm", test_binary.replace("-", "_")));
write_testsuite_tests(out, &binary_path, testsuite)?;
}
writeln!(out, "}}")?;
Ok(())
}

#[cfg(feature = "test_programs")]
mod wasi_tests {
use super::*;
use std::env;
use std::fs::{read_dir, File};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

pub(super) fn build_and_generate_tests() {
// Validate if any of test sources are present and if they changed
// This should always work since there is no submodule to init anymore
let bin_tests = std::fs::read_dir("wasi-tests/src/bin").unwrap();
let bin_tests = read_dir("wasi-tests/src/bin").unwrap();
for test in bin_tests {
if let Ok(test_file) = test {
let test_file_path = test_file
Expand All @@ -38,90 +118,25 @@ mod wasi_tests {
);
let mut out =
File::create(out_dir.join("wasi_tests.rs")).expect("error generating test source file");
build_tests("wasi-tests", &out_dir).expect("building tests");
test_directory(&mut out, "wasi-cap-std-sync", "cap_std_sync", &out_dir)
.expect("generating wasi-cap-std-sync tests");
test_directory(&mut out, "wasi-tokio", "tokio", &out_dir)
.expect("generating wasi-tokio tests");
}

fn build_tests(testsuite: &str, out_dir: &Path) -> io::Result<()> {
let mut cmd = Command::new("cargo");
cmd.env("CARGO_PROFILE_RELEASE_DEBUG", "1");
cmd.env_remove("CARGO_ENCODED_RUSTFLAGS");
cmd.args(&[
"build",
"--release",
"--target=wasm32-wasi",
"--target-dir",
out_dir.to_str().unwrap(),
])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.current_dir(testsuite);
let output = cmd.output()?;

let status = output.status;
if !status.success() {
panic!(
"Building tests failed: exit code: {}",
status.code().unwrap()
);
}

Ok(())
}

fn test_directory(
out: &mut File,
testsuite: &str,
runtime: &str,
out_dir: &Path,
) -> io::Result<()> {
let mut dir_entries: Vec<_> = read_dir(out_dir.join("wasm32-wasi/release"))
.expect("reading testsuite directory")
.map(|r| r.expect("reading testsuite directory entry"))
.filter(|dir_entry| {
let p = dir_entry.path();
if let Some(ext) = p.extension() {
// Only look at wast files.
if ext == "wasm" {
// Ignore files starting with `.`, which could be editor temporary files
if let Some(stem) = p.file_stem() {
if let Some(stemstr) = stem.to_str() {
if !stemstr.starts_with('.') {
return true;
}
}
}
}
}
false
})
.collect();

dir_entries.sort_by_key(|dir| dir.path());

writeln!(
out,
"mod {} {{",
Path::new(testsuite)
.file_stem()
.expect("testsuite filename should have a stem")
.to_str()
.expect("testsuite filename should be representable as a string")
.replace("-", "_")
)?;
writeln!(
out,
" use super::{{runtime::{} as runtime, utils, setup_log}};",
runtime
)?;
for dir_entry in dir_entries {
write_testsuite_tests(out, &dir_entry.path(), testsuite)?;
}
writeln!(out, "}}")?;
Ok(())
let test_binaries = build_tests("wasi-tests", &out_dir).expect("building tests");
test_directory(
&mut out,
&test_binaries,
"wasi-cap-std-sync",
"cap_std_sync",
&out_dir,
write_testsuite_tests,
)
.expect("generating wasi-cap-std-sync tests");
test_directory(
&mut out,
&test_binaries,
"wasi-tokio",
"tokio",
&out_dir,
write_testsuite_tests,
)
.expect("generating wasi-tokio tests");
}

fn write_testsuite_tests(out: &mut File, path: &Path, testsuite: &str) -> io::Result<()> {
Expand Down Expand Up @@ -277,3 +292,74 @@ mod wasi_tests {
}
}
}

#[cfg(feature = "test_programs_http")]
mod wasi_http_tests {
use super::*;
use std::env;

pub(super) fn build_and_generate_tests() {
// Validate if any of test sources are present and if they changed
// This should always work since there is no submodule to init anymore
let bin_tests = read_dir("wasi-http-tests/src/bin").unwrap();
for test in bin_tests {
if let Ok(test_file) = test {
let test_file_path = test_file
.path()
.into_os_string()
.into_string()
.expect("test file path");
println!("cargo:rerun-if-changed={}", test_file_path);
}
}
println!("cargo:rerun-if-changed=wasi-http-tests/Cargo.toml");
println!("cargo:rerun-if-changed=wasi-http-tests/src/lib.rs");
// Build tests to OUT_DIR (target/*/build/wasi-common-*/out/wasm32-wasi/release/*.wasm)
let out_dir = PathBuf::from(
env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set"),
);
let mut out = File::create(out_dir.join("wasi_http_tests.rs"))
.expect("error generating test source file");

let test_binaries = build_tests("wasi-http-tests", &out_dir).expect("building tests");
test_directory(
&mut out,
&test_binaries,
"wasi-http-tests",
"wasi_http_tests",
&out_dir,
write_testsuite_tests,
)
.expect("generating wasi-cap-std-sync tests");
}

fn write_testsuite_tests(out: &mut File, path: &Path, _testsuite: &str) -> io::Result<()> {
let stemstr = path
.file_stem()
.expect("file_stem")
.to_str()
.expect("to_str");

writeln!(out, " #[test]")?;
let test_fn_name = stemstr.replace("-", "_");
writeln!(out, " fn r#{}() -> anyhow::Result<()> {{", test_fn_name,)?;
writeln!(out, " setup_log();")?;
writeln!(
out,
" let path = std::path::Path::new(r#\"{}\"#);",
path.display()
)?;
writeln!(out, " let data = wat::parse_file(path)?;")?;
writeln!(
out,
" let bin_name = utils::extract_exec_name_from_path(path)?;"
)?;
writeln!(
out,
" runtime::instantiate_inherit_stdio(&data, &bin_name, None)",
)?;
writeln!(out, " }}")?;
writeln!(out)?;
Ok(())
}
}
Loading