-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
work on integration testing framework (#41)
- Loading branch information
Showing
10 changed files
with
220 additions
and
114 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
"Chunker", | ||
"cmdline", | ||
"composability", | ||
"cpus", | ||
"discoverability", | ||
"Discoverability", | ||
"editenv", | ||
|
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,61 +1,77 @@ | ||
use std::{path::Path, time::Duration}; | ||
|
||
use case::{TestCase, TestStep}; | ||
use reportify::{bail, Report, ResultExt}; | ||
use rugpi_cli::info; | ||
use tokio::fs; | ||
use tokio::{fs, task::spawn_blocking}; | ||
use workflow::{TestStep, TestWorkflow}; | ||
|
||
use crate::{bake, project::Project}; | ||
|
||
pub mod case; | ||
pub mod qemu; | ||
pub mod workflow; | ||
|
||
reportify::new_whatever_type! { | ||
RugpiTestError | ||
} | ||
|
||
pub type RugpiTestResult<T> = Result<T, Report<RugpiTestError>>; | ||
|
||
pub async fn main(case: &Path) -> RugpiTestResult<()> { | ||
let case = toml::from_str::<TestCase>( | ||
&fs::read_to_string(&case) | ||
pub async fn main(project: &Project, workflow: &Path) -> RugpiTestResult<()> { | ||
let workflow = toml::from_str::<TestWorkflow>( | ||
&fs::read_to_string(&workflow) | ||
.await | ||
.whatever("unable to read test case")?, | ||
.whatever("unable to read test workflow")?, | ||
) | ||
.whatever("unable to parse test case")?; | ||
|
||
let vm = qemu::start(&case.vm).await?; | ||
|
||
info!("VM started"); | ||
|
||
for step in &case.steps { | ||
match step { | ||
case::TestStep::Reboot => todo!(), | ||
case::TestStep::Copy { .. } => todo!(), | ||
case::TestStep::Run { | ||
script, | ||
stdin, | ||
may_fail, | ||
} => { | ||
info!("running script"); | ||
vm.wait_for_ssh() | ||
.await | ||
.whatever("unable to connect to VM via SSH")?; | ||
if let Err(report) = vm | ||
.run_script(script, stdin.as_ref().map(|p| p.as_ref())) | ||
.await | ||
.whatever::<RugpiTestError, _>("unable to run script") | ||
{ | ||
if may_fail.unwrap_or(false) { | ||
eprintln!("ignoring error while executing script:\n{report:?}"); | ||
} else { | ||
bail!("error during test") | ||
.whatever("unable to parse test workflow")?; | ||
|
||
for system in &workflow.systems { | ||
let output = Path::new("build/images") | ||
.join(&system.disk_image) | ||
.with_extension("img"); | ||
let project = project.clone(); | ||
let disk_image = system.disk_image.clone(); | ||
{ | ||
let output = output.clone(); | ||
spawn_blocking(move || bake::bake_image(&project, &disk_image, &output)) | ||
.await | ||
.whatever("error baking image")? | ||
.whatever("error baking image")?; | ||
} | ||
|
||
let vm = qemu::start(&output.to_string_lossy(), system).await?; | ||
|
||
info!("VM started"); | ||
|
||
for step in &workflow.steps { | ||
match step { | ||
workflow::TestStep::Run { | ||
script, | ||
stdin, | ||
may_fail, | ||
} => { | ||
info!("running script"); | ||
vm.wait_for_ssh() | ||
.await | ||
.whatever("unable to connect to VM via SSH")?; | ||
if let Err(report) = vm | ||
.run_script(script, stdin.as_ref().map(|p| p.as_ref())) | ||
.await | ||
.whatever::<RugpiTestError, _>("unable to run script") | ||
{ | ||
if may_fail.unwrap_or(false) { | ||
eprintln!("ignoring error while executing script:\n{report:?}"); | ||
} else { | ||
bail!("error during test") | ||
} | ||
} | ||
} | ||
} | ||
TestStep::Wait { duration_secs } => { | ||
info!("waiting for {duration_secs} seconds"); | ||
tokio::time::sleep(Duration::from_secs_f64(*duration_secs)).await; | ||
TestStep::Wait { duration } => { | ||
info!("waiting for {duration} seconds"); | ||
tokio::time::sleep(Duration::from_secs_f64(*duration)).await; | ||
} | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains 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
Oops, something went wrong.