-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Virtual file support #701
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
Virtual file support #701
Changes from all commits
0af1b9c
8d03646
c9b2b8e
ceb1fb3
b15d01a
d0b0eac
e0d943b
1c729b8
910a0e7
222f0b3
10ee1c5
b96f58f
34cc7b1
2ec462e
29ef153
9fe0f7c
f4ace0c
fbb6d91
6af98fd
9fd7fcd
14d763c
cc8ee2a
18e9946
b43b4bf
17bd739
1892a44
253061a
70d1219
f468b6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,11 +11,19 @@ fn main() { | |
| #[cfg(feature = "test_programs")] | ||
| mod wasi_tests { | ||
| use std::env; | ||
| use std::fs::{read_dir, DirEntry, File}; | ||
| use std::fs::{read_dir, File}; | ||
| use std::io::{self, Write}; | ||
| use std::path::{Path, PathBuf}; | ||
| use std::process::{Command, Stdio}; | ||
|
|
||
| #[derive(Clone, Copy, Debug)] | ||
| enum PreopenType { | ||
| /// Preopens should be satisfied with real OS files. | ||
| OS, | ||
| /// Preopens should be satisfied with virtual files. | ||
| Virtual, | ||
| } | ||
|
|
||
| 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 | ||
|
|
@@ -103,34 +111,52 @@ mod wasi_tests { | |
| .replace("-", "_") | ||
| )?; | ||
| writeln!(out, " use super::{{runtime, utils, setup_log}};")?; | ||
| writeln!(out, " use runtime::PreopenType;")?; | ||
| for dir_entry in dir_entries { | ||
| write_testsuite_tests(out, dir_entry, testsuite)?; | ||
| let test_path = dir_entry.path(); | ||
| let stemstr = test_path | ||
| .file_stem() | ||
| .expect("file_stem") | ||
| .to_str() | ||
| .expect("to_str"); | ||
|
|
||
| if no_preopens(testsuite, stemstr) { | ||
| write_testsuite_tests(out, &test_path, testsuite, PreopenType::OS)?; | ||
| } else { | ||
| write_testsuite_tests(out, &test_path, testsuite, PreopenType::OS)?; | ||
| write_testsuite_tests(out, &test_path, testsuite, PreopenType::Virtual)?; | ||
| } | ||
| } | ||
| writeln!(out, "}}")?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn write_testsuite_tests( | ||
| out: &mut File, | ||
| dir_entry: DirEntry, | ||
| path: &Path, | ||
| testsuite: &str, | ||
| preopen_type: PreopenType, | ||
| ) -> io::Result<()> { | ||
| let path = dir_entry.path(); | ||
| let stemstr = path | ||
| .file_stem() | ||
| .expect("file_stem") | ||
| .to_str() | ||
| .expect("to_str"); | ||
|
|
||
| writeln!(out, " #[test]")?; | ||
| if ignore(testsuite, stemstr) { | ||
| let test_fn_name = format!( | ||
| "{}{}", | ||
| &stemstr.replace("-", "_"), | ||
| if let PreopenType::Virtual = preopen_type { | ||
| "_virtualfs" | ||
| } else { | ||
| "" | ||
| } | ||
| ); | ||
| if ignore(testsuite, &test_fn_name) { | ||
| writeln!(out, " #[ignore]")?; | ||
| } | ||
| writeln!( | ||
| out, | ||
| " fn r#{}() -> anyhow::Result<()> {{", | ||
| &stemstr.replace("-", "_") | ||
| )?; | ||
| writeln!(out, " fn r#{}() -> anyhow::Result<()> {{", test_fn_name,)?; | ||
| writeln!(out, " setup_log();")?; | ||
| writeln!( | ||
| out, | ||
|
|
@@ -145,16 +171,25 @@ mod wasi_tests { | |
| let workspace = if no_preopens(testsuite, stemstr) { | ||
| "None" | ||
| } else { | ||
| writeln!( | ||
| out, | ||
| " let workspace = utils::prepare_workspace(&bin_name)?;" | ||
| )?; | ||
| "Some(workspace.path())" | ||
| match preopen_type { | ||
| PreopenType::OS => { | ||
| writeln!( | ||
| out, | ||
| " let workspace = utils::prepare_workspace(&bin_name)?;" | ||
| )?; | ||
| "Some(workspace.path())" | ||
| } | ||
| PreopenType::Virtual => "Some(std::path::Path::new(&bin_name))", | ||
| } | ||
| }; | ||
| writeln!( | ||
| out, | ||
| " runtime::instantiate(&data, &bin_name, {})", | ||
| workspace | ||
| " runtime::instantiate(&data, &bin_name, {}, {})", | ||
| workspace, | ||
| match preopen_type { | ||
| PreopenType::OS => "PreopenType::OS", | ||
| PreopenType::Virtual => "PreopenType::Virtual", | ||
| } | ||
| )?; | ||
| writeln!(out, " }}")?; | ||
| writeln!(out)?; | ||
|
|
@@ -164,8 +199,30 @@ mod wasi_tests { | |
| cfg_if::cfg_if! { | ||
| if #[cfg(not(windows))] { | ||
| /// Ignore tests that aren't supported yet. | ||
| fn ignore(_testsuite: &str, _name: &str) -> bool { | ||
| false | ||
| fn ignore(testsuite: &str, name: &str) -> bool { | ||
| if testsuite == "wasi-tests" { | ||
| match name { | ||
| // TODO: virtfs files cannot be poll_oneoff'd yet | ||
| "poll_oneoff_virtualfs" => true, | ||
| // TODO: virtfs does not support filetimes yet. | ||
| "path_filestat_virtualfs" | | ||
| "fd_filestat_set_virtualfs" => true, | ||
| // TODO: virtfs does not support symlinks yet. | ||
| "nofollow_errors_virtualfs" | | ||
| "path_link_virtualfs" | | ||
| "readlink_virtualfs" | | ||
| "readlink_no_buffer_virtualfs" | | ||
| "dangling_symlink_virtualfs" | | ||
| "symlink_loop_virtualfs" | | ||
| "path_symlink_trailing_slashes_virtualfs" => true, | ||
| // TODO: virtfs does not support rename yet. | ||
| "path_rename_trailing_slashes_virtualfs" | | ||
| "path_rename_virtualfs" => true, | ||
| _ => false, | ||
| } | ||
| } else { | ||
| unreachable!() | ||
| } | ||
| } | ||
| } else { | ||
| /// Ignore tests that aren't supported yet. | ||
|
|
@@ -178,6 +235,22 @@ mod wasi_tests { | |
| "truncation_rights" => true, | ||
| "path_link" => true, | ||
| "dangling_fd" => true, | ||
| // TODO: virtfs files cannot be poll_oneoff'd yet | ||
| "poll_oneoff_virtualfs" => true, | ||
| // TODO: virtfs does not support filetimes yet. | ||
| "path_filestat_virtualfs" | | ||
| "fd_filestat_set_virtualfs" => true, | ||
| // TODO: virtfs does not support symlinks yet. | ||
| "nofollow_errors_virtualfs" | | ||
| "path_link_virtualfs" | | ||
| "readlink_virtualfs" | | ||
| "readlink_no_buffer_virtualfs" | | ||
| "dangling_symlink_virtualfs" | | ||
| "symlink_loop_virtualfs" | | ||
| "path_symlink_trailing_slashes_virtualfs" => true, | ||
| // TODO: virtfs does not support rename yet. | ||
| "path_rename_trailing_slashes_virtualfs" | | ||
| "path_rename_virtualfs" => true, | ||
|
Comment on lines
+238
to
+253
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this looks like we're redoing every
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So.. my thinking here is that because Realistically, your recommendation to adjust dispatch to I think the last reason to run
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I see what you mean by having a mix of the two: a host plus some virtual fs on top of it. The reason I mentioned it here is since there seems to be a lot of code duplication so I was trying to figure out if we could somehow reduce it especially since it seems to be very much copy-paste reuse. 🤔
I think I'd actually be more comfortable always having it on so that we make sure we don't break it with any changes to |
||
| _ => false, | ||
| } | ||
| } else { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.