From 05df9ff41537bab6586eea7ad9272eeb611e09e1 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 7 Feb 2019 17:05:23 +0100 Subject: [PATCH] Add a wasm code size test for stringifying numbers --- .../wasm-stringify-ints-small/Makefile | 10 +++++ .../run-make/wasm-stringify-ints-small/foo.rs | 39 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/test/run-make/wasm-stringify-ints-small/Makefile create mode 100755 src/test/run-make/wasm-stringify-ints-small/foo.rs diff --git a/src/test/run-make/wasm-stringify-ints-small/Makefile b/src/test/run-make/wasm-stringify-ints-small/Makefile new file mode 100644 index 00000000000..18e47242f80 --- /dev/null +++ b/src/test/run-make/wasm-stringify-ints-small/Makefile @@ -0,0 +1,10 @@ +-include ../../run-make-fulldeps/tools.mk + +ifeq ($(TARGET),wasm32-unknown-unknown) +all: + $(RUSTC) foo.rs -C lto -O --target wasm32-unknown-unknown + wc -c < $(TMPDIR)/foo.wasm + [ "`wc -c < $(TMPDIR)/foo.wasm`" -lt "21000" ] +else +all: +endif diff --git a/src/test/run-make/wasm-stringify-ints-small/foo.rs b/src/test/run-make/wasm-stringify-ints-small/foo.rs new file mode 100755 index 00000000000..6aa249aabeb --- /dev/null +++ b/src/test/run-make/wasm-stringify-ints-small/foo.rs @@ -0,0 +1,39 @@ +#![crate_type = "cdylib"] + +extern "C" { + fn observe(ptr: *const u8, len: usize); + + fn get_u8() -> u8; + fn get_i8() -> i8; + fn get_u16() -> u16; + fn get_i16() -> i16; + fn get_u32() -> u32; + fn get_i32() -> i32; + fn get_u64() -> u64; + fn get_i64() -> i64; + fn get_usize() -> usize; + fn get_isize() -> isize; +} + +macro_rules! stringify { + ( $($f:ident)* ) => { + $( + let s = $f().to_string(); + observe(s.as_ptr(), s.len()); + )* + }; +} + +#[no_mangle] +pub unsafe extern "C" fn foo() { + stringify!(get_u8); + stringify!(get_i8); + stringify!(get_u16); + stringify!(get_i16); + stringify!(get_u32); + stringify!(get_i32); + stringify!(get_u64); + stringify!(get_i64); + stringify!(get_usize); + stringify!(get_isize); +}