@@ -25,56 +25,66 @@ pub extern "C" fn proxy_on_memory_allocate(size: usize) -> *mut u8 {
2525 Box :: into_raw ( slice) as * mut u8
2626}
2727
28+ extern "C" {
29+ fn proxy_log ( level : u32 , message_data : * const u8 , message_size : usize ) -> bool ;
30+ }
31+
32+ fn log ( message : & str ) {
33+ unsafe {
34+ proxy_log ( /*error*/ 4 , message. as_bytes ( ) . as_ptr ( ) , message. len ( ) ) ;
35+ }
36+ }
37+
2838#[ no_mangle]
29- pub extern "C" fn test_bigendian ( uint32 : u32 , uint64 : u64 , float32 : f32 , float64 : f64 ) -> i32 {
39+ pub extern "C" fn test_primitives ( uint32 : u32 , uint64 : u64 , float32 : f32 , float64 : f64 ) -> i32 {
3040 if uint32 != 3333333333 {
31- println ! ( "uint32 was not little-endian : {}" , uint32) ;
41+ log ( & format ! ( "unexpected uint32 value : {}" , uint32) ) ;
3242 return 1 ;
3343 }
3444 if uint64 != 11111111111111111111 {
35- println ! ( "uint64 was not little-endian : {}" , uint32) ;
45+ log ( & format ! ( "unexpected uint64 value : {}" , uint32) ) ;
3646 return 2 ;
3747 }
3848 if float32 < 1110.0 || float32 > 1112.0 {
39- println ! ( "float32 was not little-endian : {}" , float32) ;
49+ log ( & format ! ( "unexpected float32 value : {}" , float32) ) ;
4050 return 3 ;
4151 }
4252 if float64 < 1111111110.0 || float64 > 1111111112.0 {
43- println ! ( "float64 was not little-endian : {}" , float64) ;
53+ log ( & format ! ( "unexpected float64 value : {}" , float64) ) ;
4454 return 4 ;
4555 }
4656 return 0 ;
4757}
4858
4959#[ no_mangle]
50- pub extern "C" fn test_bigendian_negatives (
60+ pub extern "C" fn test_negative_primitives (
5161 int32 : i32 ,
5262 int64 : i64 ,
5363 float32 : f32 ,
5464 float64 : f64 ,
5565) -> i32 {
5666 if int32 != -1111111111 {
67+ log ( & format ! ( "unexpected int32 value: {}" , int32) ) ;
5768 return 1 ;
5869 }
5970 if int64 != -1111111111111111111 {
71+ log ( & format ! ( "unexpected int64 value: {}" , int32) ) ;
6072 return 2 ;
6173 }
6274 if float32 > -1110.0 || float32 < -1112.0 {
75+ log ( & format ! ( "unexpected float32 value: {}" , float32) ) ;
6376 return 3 ;
6477 }
6578 if float64 > -1111111110.0 || float64 < -1111111112.0 {
79+ log ( & format ! ( "unexpected float64 value: {}" , float64) ) ;
6680 return 4 ;
6781 }
6882 return 0 ;
6983}
7084
71- extern "C" {
72- fn proxy_log ( level : u32 , message_data : * const u8 , message_size : usize ) -> bool ;
73- }
74-
7585#[ no_mangle]
76- pub extern "C" fn test_bigendian_buffer_from_wasm ( ) -> bool {
77- let message = "hello from little-endian wasm land!" ;
86+ pub extern "C" fn test_buffer_from_wasm ( ) -> bool {
87+ let message = "hello from wasm land!" ;
7888 unsafe {
7989 match proxy_log ( /*info*/ 2 , message. as_ptr ( ) , message. len ( ) ) {
8090 false => false ,
@@ -94,7 +104,7 @@ extern "C" {
94104}
95105
96106#[ no_mangle]
97- pub extern "C" fn test_bigendian_buffer_from_host ( ) -> bool {
107+ pub extern "C" fn test_buffer_from_host ( ) -> bool {
98108 let mut return_data: * mut u8 = std:: ptr:: null_mut ( ) ;
99109 let mut return_size: usize = 0 ;
100110 unsafe {
@@ -105,7 +115,7 @@ pub extern "C" fn test_bigendian_buffer_from_host() -> bool {
105115 }
106116 let result =
107117 String :: from_utf8 ( Vec :: from_raw_parts ( return_data, return_size, return_size) ) ;
108- if result. unwrap ( ) != "hello from host land endianness " {
118+ if result. unwrap ( ) != "hello from host land" {
109119 panic ! ( "message did not match expectation" ) ;
110120 }
111121 false
0 commit comments