Skip to content

Commit 6d85d34

Browse files
committed
Rename bigendian test to more generic "arg passing"
Signed-off-by: Matt Leon <mattleon@google.com>
1 parent 66059ad commit 6d85d34

4 files changed

Lines changed: 39 additions & 29 deletions

File tree

test/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ cc_test(
7171
srcs = ["runtime_test.cc"],
7272
data = [
7373
"//test/test_data:callback.wasm",
74-
"//test/test_data:bigendian.wasm",
74+
"//test/test_data:arg_passing.wasm",
7575
"//test/test_data:clock.wasm",
7676
"//test/test_data:resource_limits.wasm",
7777
"//test/test_data:trap.wasm",

test/runtime_test.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,31 +190,31 @@ TEST_P(TestVm, Trap2) {
190190
}
191191
}
192192

193-
TEST_P(TestVm, BigendianValuesTranslatedProperly) {
194-
auto source = readTestWasmFile("bigendian.wasm");
193+
TEST_P(TestVm, PassingValuesAcrossWasmBoundary) {
194+
auto source = readTestWasmFile("arg_passing.wasm");
195195
ASSERT_FALSE(source.empty());
196196
auto wasm = TestWasm(std::move(vm_));
197197
ASSERT_TRUE(wasm.load(source, false));
198198
ASSERT_TRUE(wasm.initialize());
199199
auto *context = dynamic_cast<TestContext *>(wasm.vm_context());
200200
ASSERT_NE(context, nullptr);
201-
WasmCall_WWlfd test_bigendian;
202-
wasm.wasm_vm()->getFunction("test_bigendian", &test_bigendian);
203-
WasmCall_WWlfd test_bigendian_negatives;
204-
wasm.wasm_vm()->getFunction("test_bigendian_negatives", &test_bigendian_negatives);
201+
WasmCall_WWlfd test_primitives;
202+
wasm.wasm_vm()->getFunction("test_primitives", &test_primitives);
203+
WasmCall_WWlfd test_negative_primitives;
204+
wasm.wasm_vm()->getFunction("test_negative_primitives", &test_negative_primitives);
205205
WasmCallWord<0> test_buffer_from_wasm;
206-
wasm.wasm_vm()->getFunction("test_bigendian_buffer_from_wasm", &test_buffer_from_wasm);
206+
wasm.wasm_vm()->getFunction("test_buffer_from_wasm", &test_buffer_from_wasm);
207207
WasmCallWord<0> test_buffer_from_host;
208-
wasm.wasm_vm()->getFunction("test_bigendian_buffer_from_host", &test_buffer_from_host);
208+
wasm.wasm_vm()->getFunction("test_buffer_from_host", &test_buffer_from_host);
209209

210-
ASSERT_FALSE(test_bigendian(context, 3333333333U, 11111111111111111111UL, 1111, 1111111111));
210+
ASSERT_FALSE(test_primitives(context, 3333333333U, 11111111111111111111UL, 1111, 1111111111));
211211
ASSERT_FALSE(
212-
test_bigendian_negatives(context, -1111111111, -1111111111111111111, -1111, -1111111111));
212+
test_negative_primitives(context, -1111111111, -1111111111111111111, -1111, -1111111111));
213213

214214
ASSERT_FALSE(test_buffer_from_wasm(context));
215-
context->isLogged("hello from little-endian wasm land!");
215+
context->isLogged("hello from wasm land!");
216216

217-
context->setBuffer(0, "hello from host land endianness!");
217+
context->setBuffer(0, "hello from host land!");
218218
ASSERT_FALSE(test_buffer_from_host(context));
219219
}
220220

test/test_data/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ wasm_rust_binary(
5858
)
5959

6060
wasm_rust_binary(
61-
name = "bigendian.wasm",
62-
srcs = ["bigendian.rs"],
61+
name = "arg_passing.wasm",
62+
srcs = ["arg_passing.rs"],
6363
)
6464

6565
wasm_rust_binary(
Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)