Skip to content

Commit

Permalink
Add a wasm code size test for stringifying numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzgen committed Feb 8, 2019
1 parent c104b5c commit 05df9ff
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 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
39 changes: 39 additions & 0 deletions 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);
}

0 comments on commit 05df9ff

Please sign in to comment.