Skip to content

Commit 06692ff

Browse files
authored
Check full JS output for hello world (#12806)
For the smallest hello world test, don't just check the output size but check the full JS output matches the expectations. That means that any change that touches those core lines of output will need to rebaseline this test. However: a) such changes deserve extra scrutiny b) such changes should be few and far between c) rebaselining is trivial (just run with EMTEST_REBASELINE=1) Note that we do not compare the full wasm output since that is even more fragile and can change with LLVM updates.
1 parent d4b9951 commit 06692ff

File tree

3 files changed

+124
-3
lines changed

3 files changed

+124
-3
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var d = Module;
2+
3+
var e = new TextDecoder("utf8");
4+
5+
function f(a) {
6+
if (!a) return "";
7+
for (var b = a + NaN, c = a; !(c >= b) && g[c]; ) ++c;
8+
return e.decode(g.subarray(a, c));
9+
}
10+
11+
var g, h, k;
12+
13+
WebAssembly.instantiate(d.wasm, {
14+
a: {
15+
a: function(a) {
16+
console.log(f(a));
17+
}
18+
}
19+
}).then((function(a) {
20+
a = a.instance.exports;
21+
k = a.e;
22+
h = a.b;
23+
var b = h.buffer;
24+
g = new Uint8Array(b);
25+
a.d();
26+
k();
27+
}));
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
var b = Module;
2+
3+
var c = new TextDecoder("utf8");
4+
5+
function e(a) {
6+
if (!a) return "";
7+
for (var m = a + NaN, d = a; !(d >= m) && f[d]; ) ++d;
8+
return c.decode(f.subarray(a, d));
9+
}
10+
11+
var f, g;
12+
13+
g = new function(a) {
14+
this.buffer = new ArrayBuffer(65536 * a.initial);
15+
}({
16+
initial: 256,
17+
maximum: 256
18+
});
19+
20+
var h = g.buffer;
21+
22+
f = new Uint8Array(h);
23+
24+
var k = {
25+
a: function(a) {
26+
console.log(e(a));
27+
},
28+
memory: g
29+
}, l, n = (new function() {
30+
this.exports = function instantiate(t) {
31+
function r(u) {
32+
u.set = function(v, w) {
33+
this[v] = w;
34+
};
35+
u.get = function(v) {
36+
return this[v];
37+
};
38+
return u;
39+
}
40+
function s(x) {
41+
var a = Math.imul;
42+
var b = Math.fround;
43+
var c = Math.abs;
44+
var d = Math.clz32;
45+
var e = Math.min;
46+
var f = Math.max;
47+
var g = Math.floor;
48+
var h = Math.ceil;
49+
var i = Math.trunc;
50+
var j = Math.sqrt;
51+
var k = x.abort;
52+
var l = NaN;
53+
var m = Infinity;
54+
var n = x.a;
55+
function q(a, b) {
56+
a = a | 0;
57+
b = b | 0;
58+
n(1024);
59+
return 0;
60+
}
61+
function p() {}
62+
var o = r([]);
63+
return {
64+
b: o,
65+
c: p,
66+
d: q
67+
};
68+
}
69+
return s(t);
70+
}(k);
71+
}).exports;
72+
73+
l = n.d;
74+
75+
f.set(new Uint8Array(b.mem), 1024);
76+
77+
n.c();
78+
79+
l();

tests/test_other.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8189,16 +8189,16 @@ def test(args, closure, opt):
81898189
@no_windows("Code size is slightly different on Windows")
81908190
@no_mac("Code size is slightly different on Mac")
81918191
@parameterized({
8192-
'hello_world_wasm': ('hello_world', False),
8193-
'hello_world_wasm2js': ('hello_world', True),
8192+
'hello_world_wasm': ('hello_world', False, True),
8193+
'hello_world_wasm2js': ('hello_world', True, True),
81948194
'random_printf_wasm': ('random_printf', False),
81958195
'random_printf_wasm2js': ('random_printf', True),
81968196
'hello_webgl_wasm': ('hello_webgl', False),
81978197
'hello_webgl_wasm2js': ('hello_webgl', True),
81988198
'hello_webgl2_wasm': ('hello_webgl2', False),
81998199
'hello_webgl2_wasm2js': ('hello_webgl2', True),
82008200
})
8201-
def test_minimal_runtime_code_size(self, test_name, js):
8201+
def test_minimal_runtime_code_size(self, test_name, js, compare_js_output=False):
82028202
smallest_code_size_args = ['-s', 'MINIMAL_RUNTIME=2',
82038203
'-s', 'ENVIRONMENT=web',
82048204
'-s', 'TEXTDECODER=2',
@@ -8286,6 +8286,21 @@ def get_file_gzipped_size(f):
82868286
try_delete(f_gz)
82878287
return size
82888288

8289+
# For certain tests, don't just check the output size but check
8290+
# the full JS output matches the expectations. That means that
8291+
# any change that touches those core lines of output will need
8292+
# to rebaseline this test. However:
8293+
# a) such changes deserve extra scrutiny
8294+
# b) such changes should be few and far between
8295+
# c) rebaselining is trivial (just run with EMTEST_REBASELINE=1)
8296+
# Note that we do not compare the full wasm output since that is
8297+
# even more fragile and can change with LLVM updates.
8298+
if compare_js_output:
8299+
js_out = path_from_root('tests', 'code_size', test_name + '.js')
8300+
terser = shared.get_npm_cmd('terser')
8301+
self.run_process(terser + ['-b', 'beautify=true', 'a.js', '-o', 'pretty.js'])
8302+
self.assertFileContents(js_out, open('pretty.js').read())
8303+
82898304
obtained_results = {}
82908305
total_output_size = 0
82918306
total_expected_size = 0

0 commit comments

Comments
 (0)