-
Notifications
You must be signed in to change notification settings - Fork 3
test: fix eval and file-close #43
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
Open
GregoryLi360
wants to merge
1
commit into
main
Choose a base branch
from
test/fix-eval
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+115
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| use std::path::{Path, PathBuf}; | ||
| use std::process::{Child, Command, Output, Stdio}; | ||
| use std::thread; | ||
| use std::time::{Duration, Instant}; | ||
|
|
||
| // Keep the regression input with the test instead of relying on a fixture | ||
| const FIX_PROGRAM: &str = r#"x = create_blob(Int(2)); | ||
| y = create_blob(Int(3)); | ||
| add = create_blob(Path("./target/x86_64-unknown-none/addblob")); | ||
| add_x_y = create_application_thunk(create_tree(add, x, y)); | ||
| z = create_blob(Int(1)); | ||
| sum_x_y = create_strict_encode(add_x_y) | ||
| add_xy_z = create_application_thunk(create_tree(add, sum_x_y, z)); | ||
| eval(create_strict_encode(add_xy_z)); | ||
| "#; | ||
| const EXPECTED_OUTPUT: &str = "as a u64: 6"; | ||
| // Time limited so this test doesn't stall the test suite (usually runs in <10s) | ||
| const DEADLOCK_LIMIT: Duration = Duration::from_secs(30); | ||
| // Poll lightly instead of busy-waiting for the child | ||
| const POLL_INTERVAL: Duration = Duration::from_millis(10); | ||
|
|
||
| struct ProgramFile { | ||
| path: PathBuf, | ||
| } | ||
|
|
||
| impl ProgramFile { | ||
| fn new() -> Self { | ||
| // The production CLI requires a path, so materialize the inline program | ||
| let path = std::env::temp_dir().join(format!("arca-fix-eval-{}.fix", std::process::id())); | ||
| std::fs::write(&path, FIX_PROGRAM).expect("write temporary Fix program"); | ||
| Self { path } | ||
| } | ||
|
|
||
| fn path(&self) -> &Path { | ||
| &self.path | ||
| } | ||
| } | ||
|
|
||
| impl Drop for ProgramFile { | ||
| fn drop(&mut self) { | ||
| // Clean up the temp file | ||
| let _ = std::fs::remove_file(&self.path); | ||
| } | ||
| } | ||
|
|
||
| // Fail instead of hanging if the file-close handshake deadlocks | ||
| fn wait_for_output(mut child: Child) -> Output { | ||
| let start = Instant::now(); | ||
|
|
||
| loop { | ||
| match child.try_wait().expect("poll Fix-on-Arca process") { | ||
| Some(_) => { | ||
| // Kill the child and collect both captured streams | ||
| return child | ||
| .wait_with_output() | ||
| .expect("collect Fix-on-Arca output"); | ||
| } | ||
| None if start.elapsed() < DEADLOCK_LIMIT => thread::sleep(POLL_INTERVAL), | ||
| None => { | ||
| // Stop the hung VM before reporting diagnostics | ||
| let _ = child.kill(); | ||
| let output = child | ||
| .wait_with_output() | ||
| .expect("collect timed-out Fix-on-Arca output"); | ||
| panic!( | ||
| "fix eval did not complete its file-close handshake\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&output.stdout), | ||
| String::from_utf8_lossy(&output.stderr), | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn fix_eval_completes_and_prints_result() { | ||
| let program = ProgramFile::new(); | ||
| // Resolve the program's addblob helper from the workspace target directory | ||
| let workspace = Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| .parent() | ||
| .expect("vmm crate is inside the workspace"); | ||
|
|
||
| // Cargo supplies both binaries; VMM expects the guest ELF before guest argv | ||
| let child = Command::new(env!("CARGO_BIN_EXE_vmm")) | ||
| .arg(env!("CARGO_BIN_FILE_FIX_GUEST_fix")) | ||
| .arg("eval") | ||
| .arg(program.path()) | ||
| .current_dir(workspace) | ||
| .stdout(Stdio::piped()) | ||
| .stderr(Stdio::piped()) | ||
| .spawn() | ||
| .expect("launch Fix-on-Arca under the VMM"); | ||
|
|
||
| // Decode captured bytes for assertions and failure diagnostics | ||
| let output = wait_for_output(child); | ||
| let stdout = String::from_utf8_lossy(&output.stdout); | ||
| let stderr = String::from_utf8_lossy(&output.stderr); | ||
|
|
||
| // A successful status proves the guest reached kernel shutdown | ||
| assert!( | ||
| output.status.success(), | ||
| "fix eval failed with {}\nstdout:\n{stdout}\nstderr:\n{stderr}", | ||
| output.status, | ||
| ); | ||
| // VMM forwards guest debug-console output to stderr | ||
| assert!( | ||
| stderr.contains(EXPECTED_OUTPUT), | ||
| "fix eval did not print the expected result\nstdout:\n{stdout}\nstderr:\n{stderr}", | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you have Rust embed the guest binary into this one instead or reading it? This currently seems brittle.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Cargo.toml I added
so calling
cargo testshould build the Fix guest artifact first. I tried embedding it but couldn't really see a clean way of doing so. Also, I'm not quite sure of the benefit of that approach, is there something that could fail with how it is right now?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the main thing that concerns me is the path possibly being incorrect depending on the user's config; like their editor might invoke
cargo testin the current file's directory rather than the project root. Right now the path is a compile-time literal but it's being evaluated at runtime which is odd. Also philosophically I'm hesitant to have a hard dependency that isn't visible to the compiler/runtime/OS...