Skip to content

Commit ef2d6c2

Browse files
committed
asm test
1 parent b24d32e commit ef2d6c2

File tree

4 files changed

+98
-22
lines changed

4 files changed

+98
-22
lines changed

orchestrator/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

orchestrator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ tokio-util = { version = "0.7.8", default-features = false, features = ["io", "i
1717
toml = { version = "0.7.3", default-features = false, features = ["parse", "display"] }
1818

1919
[dev-dependencies]
20+
assertables = "7.0.1"
2021
tempdir = "0.3.7"

orchestrator/src/coordinator.rs

Lines changed: 84 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -709,14 +709,19 @@ fn spawn_io_queue(stdin: ChildStdin, stdout: ChildStdout, token: CancellationTok
709709

710710
#[cfg(test)]
711711
mod tests {
712+
use assertables::*;
713+
use futures::{Future, FutureExt};
712714
use std::{sync::Once, time::Duration};
713715
use tempdir::TempDir;
714716
use tokio::join;
715717
use tokio_stream::{wrappers::ReceiverStream, StreamExt};
716718

717719
use crate::{
718720
coordinator::Coordinator,
719-
sandbox::{Channel, CompileRequest, CompileTarget, CrateType, Edition, Mode},
721+
sandbox::{
722+
AssemblyFlavor, Channel, CompileRequest, CompileTarget, CrateType, DemangleAssembly,
723+
Edition, LibraryType, Mode, ProcessAssembly,
724+
},
720725
};
721726

722727
use super::*;
@@ -749,6 +754,9 @@ mod tests {
749754
.expect("Build failed");
750755
assert!(output.status.success(), "Cargo initialization failed");
751756

757+
let main = project_dir.path().join("src").join("main.rs");
758+
std::fs::remove_file(main).expect("Could not delete main.rs");
759+
752760
Self { project_dir }
753761
}
754762
}
@@ -767,10 +775,27 @@ mod tests {
767775

768776
fn new_coordinator() -> Result<Coordinator<impl Backend>> {
769777
Coordinator::new(TestBackend::new())
770-
// Coordinator::new_docker()
778+
//Coordinator::new_docker()
771779
}
772780

773-
fn new_compile_request() -> CompileRequest {
781+
fn new_compile_asm_request() -> CompileRequest {
782+
CompileRequest {
783+
target: CompileTarget::Assembly(
784+
AssemblyFlavor::Intel,
785+
DemangleAssembly::Demangle,
786+
ProcessAssembly::Filter,
787+
),
788+
channel: Channel::Beta,
789+
crate_type: CrateType::Library(LibraryType::Lib),
790+
mode: Mode::Release,
791+
edition: Edition::Rust2018,
792+
tests: false,
793+
backtrace: false,
794+
code: r#"pub fn add(a: u8, b: u8) -> u8 { a + b }"#.to_owned(),
795+
}
796+
}
797+
798+
fn new_compile_mir_request() -> CompileRequest {
774799
CompileRequest {
775800
target: CompileTarget::Mir,
776801
channel: Channel::Stable,
@@ -783,20 +808,24 @@ mod tests {
783808
}
784809
}
785810

811+
fn new_compile_request() -> CompileRequest {
812+
new_compile_mir_request()
813+
}
814+
786815
#[tokio::test]
787816
#[snafu::report]
788817
async fn test_compile_response() -> Result<()> {
789818
let coordinator = new_coordinator()?;
790819

791-
let response = tokio::time::timeout(
792-
Duration::from_millis(5000),
793-
coordinator.compile(new_compile_request()),
794-
)
795-
.await
796-
.expect("Failed to receive streaming from container in time")
797-
.unwrap();
820+
let response = coordinator
821+
.compile(new_compile_request())
822+
.with_timeout()
823+
.await
824+
.unwrap();
798825

799-
assert!(response.success);
826+
assert!(response.success, "stderr: {}", response.stderr);
827+
assert_contains!(response.stderr, "Compiling");
828+
assert_contains!(response.stderr, "Finished");
800829

801830
coordinator.shutdown().await?;
802831

@@ -824,21 +853,55 @@ mod tests {
824853
let stderr = stderr.collect::<String>();
825854

826855
let (complete, _stdout, stderr) =
827-
tokio::time::timeout(Duration::from_millis(5000), async move {
828-
join!(task, stdout, stderr)
829-
})
856+
async { join!(task, stdout, stderr) }.with_timeout().await;
857+
858+
let response = complete.unwrap().unwrap();
859+
860+
assert!(response.success, "stderr: {}", stderr);
861+
assert_contains!(stderr, "Compiling");
862+
assert_contains!(stderr, "Finished");
863+
864+
coordinator.shutdown().await?;
865+
866+
Ok(())
867+
}
868+
869+
#[tokio::test]
870+
#[snafu::report]
871+
async fn test_compile_assembly() -> Result<()> {
872+
let coordinator = new_coordinator()?;
873+
874+
let response = coordinator
875+
.compile(new_compile_asm_request())
876+
.with_timeout()
830877
.await
831-
.expect("Failed to receive streaming from container in time");
878+
.unwrap();
879+
880+
//#[cfg(target_arch = "x86_64")]
881+
//let asm = "";
882+
883+
#[cfg(target_arch = "aarch64")]
884+
let asm = "w0, w1, w0";
832885

833-
complete.unwrap().unwrap();
834-
assert!(
835-
stderr.contains("Compiling"),
836-
"Missing `Compiling`: {stderr}"
837-
);
838-
assert!(stderr.contains("Finished"), "Missing `Finished`: {stderr}");
886+
assert!(response.success, "stderr: {}", response.stderr);
887+
assert_contains!(response.code, asm);
839888

840889
coordinator.shutdown().await?;
841890

842891
Ok(())
843892
}
893+
894+
trait TimeoutExt: Future + Sized {
895+
fn with_timeout(
896+
self,
897+
) -> futures::future::Map<
898+
tokio::time::Timeout<Self>,
899+
fn(Result<Self::Output, tokio::time::error::Elapsed>) -> Self::Output,
900+
> {
901+
tokio::time::timeout(Duration::from_millis(5000), self)
902+
.map(|v| v.expect("The operation timed out"))
903+
}
904+
}
905+
906+
impl<F: Future> TimeoutExt for F {}
844907
}

orchestrator/src/sandbox.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ pub struct CompileRequest {
101101

102102
impl CompileRequest {
103103
pub(crate) fn write_main_request(&self) -> WriteFileRequest {
104+
let path = match self.crate_type {
105+
CrateType::Binary => "src/main.rs",
106+
CrateType::Library(_) => "src/lib.rs",
107+
};
108+
104109
WriteFileRequest {
105-
path: "src/main.rs".to_owned(),
110+
path: path.to_owned(),
106111
content: self.code.clone().into(),
107112
}
108113
}

0 commit comments

Comments
 (0)