@@ -709,14 +709,19 @@ fn spawn_io_queue(stdin: ChildStdin, stdout: ChildStdout, token: CancellationTok
709
709
710
710
#[ cfg( test) ]
711
711
mod tests {
712
+ use assertables:: * ;
713
+ use futures:: { Future , FutureExt } ;
712
714
use std:: { sync:: Once , time:: Duration } ;
713
715
use tempdir:: TempDir ;
714
716
use tokio:: join;
715
717
use tokio_stream:: { wrappers:: ReceiverStream , StreamExt } ;
716
718
717
719
use crate :: {
718
720
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
+ } ,
720
725
} ;
721
726
722
727
use super :: * ;
@@ -749,6 +754,9 @@ mod tests {
749
754
. expect ( "Build failed" ) ;
750
755
assert ! ( output. status. success( ) , "Cargo initialization failed" ) ;
751
756
757
+ let main = project_dir. path ( ) . join ( "src" ) . join ( "main.rs" ) ;
758
+ std:: fs:: remove_file ( main) . expect ( "Could not delete main.rs" ) ;
759
+
752
760
Self { project_dir }
753
761
}
754
762
}
@@ -767,10 +775,27 @@ mod tests {
767
775
768
776
fn new_coordinator ( ) -> Result < Coordinator < impl Backend > > {
769
777
Coordinator :: new ( TestBackend :: new ( ) )
770
- // Coordinator::new_docker()
778
+ //Coordinator::new_docker()
771
779
}
772
780
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 {
774
799
CompileRequest {
775
800
target : CompileTarget :: Mir ,
776
801
channel : Channel :: Stable ,
@@ -783,20 +808,24 @@ mod tests {
783
808
}
784
809
}
785
810
811
+ fn new_compile_request ( ) -> CompileRequest {
812
+ new_compile_mir_request ( )
813
+ }
814
+
786
815
#[ tokio:: test]
787
816
#[ snafu:: report]
788
817
async fn test_compile_response ( ) -> Result < ( ) > {
789
818
let coordinator = new_coordinator ( ) ?;
790
819
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 ( ) ;
798
825
799
- assert ! ( response. success) ;
826
+ assert ! ( response. success, "stderr: {}" , response. stderr) ;
827
+ assert_contains ! ( response. stderr, "Compiling" ) ;
828
+ assert_contains ! ( response. stderr, "Finished" ) ;
800
829
801
830
coordinator. shutdown ( ) . await ?;
802
831
@@ -824,21 +853,55 @@ mod tests {
824
853
let stderr = stderr. collect :: < String > ( ) ;
825
854
826
855
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 ( )
830
877
. 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" ;
832
885
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) ;
839
888
840
889
coordinator. shutdown ( ) . await ?;
841
890
842
891
Ok ( ( ) )
843
892
}
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 { }
844
907
}
0 commit comments