Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: test/mjsunit/wasm/test-wasm-module-builder.js

Issue 2345593003: [wasm] Master CL for Binary 0xC changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test failures and TSAN races. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/wasm/test-import-export-wrapper.js ('k') | test/mjsunit/wasm/trap-location.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --expose-wasm 5 // Flags: --expose-wasm
6 6
7 load('test/mjsunit/wasm/wasm-constants.js'); 7 load('test/mjsunit/wasm/wasm-constants.js');
8 load('test/mjsunit/wasm/wasm-module-builder.js'); 8 load('test/mjsunit/wasm/wasm-module-builder.js');
9 9
10 var debug = false; 10 var debug = true;
11 11
12 (function BasicTest() { 12 (function BasicTest() {
13 var module = new WasmModuleBuilder(); 13 var module = new WasmModuleBuilder();
14 module.addMemory(1, 2, false); 14 module.addMemory(1, 2, false);
15 module.addFunction("foo", kSig_i) 15 module.addFunction("foo", kSig_i)
16 .addBody([kExprI8Const, 11]) 16 .addBody([kExprI8Const, 11])
17 .exportAs("blarg"); 17 .exportAs("blarg");
18 18
19 var buffer = module.toBuffer(debug); 19 var buffer = module.toBuffer(debug);
20 var instance = Wasm.instantiateModule(buffer); 20 var instance = Wasm.instantiateModule(buffer);
21 assertEquals(11, instance.exports.blarg()); 21 assertEquals(11, instance.exports.blarg());
22 })(); 22 })();
23 23
24 (function ImportTest() { 24 (function ImportTest() {
25 var module = new WasmModuleBuilder(); 25 var module = new WasmModuleBuilder();
26 var index = module.addImport("print", makeSig_v_x(kAstI32)); 26 var index = module.addImport("print", makeSig_v_x(kAstI32));
27 module.addFunction("foo", kSig_v_v) 27 module.addFunction("foo", kSig_v_v)
28 .addBody([kExprI8Const, 13, kExprCallImport, kArity1, index]) 28 .addBody([kExprI8Const, 13, kExprCallFunction, index])
29 .exportAs("main"); 29 .exportAs("main");
30 30
31 var buffer = module.toBuffer(debug); 31 var buffer = module.toBuffer(debug);
32 var instance = Wasm.instantiateModule(buffer, {print: print}); 32 var instance = Wasm.instantiateModule(buffer, {print: print});
33 print("should print 13! "); 33 print("should print 13! ");
34 instance.exports.main(); 34 instance.exports.main();
35 })(); 35 })();
36 36
37 (function LocalsTest() { 37 (function LocalsTest() {
38 var module = new WasmModuleBuilder(); 38 var module = new WasmModuleBuilder();
39 module.addFunction(undefined, kSig_i_i) 39 module.addFunction(undefined, kSig_i_i)
40 .addLocals({i32_count: 1}) 40 .addLocals({i32_count: 1})
41 .addBody([kExprGetLocal, 0, kExprSetLocal, 1]) 41 .addBody([kExprGetLocal, 0, kExprSetLocal, 1, kExprGetLocal, 1])
42 .exportAs("main"); 42 .exportAs("main");
43 43
44 var buffer = module.toBuffer(debug); 44 var buffer = module.toBuffer(debug);
45 var instance = Wasm.instantiateModule(buffer); 45 var instance = Wasm.instantiateModule(buffer);
46 assertEquals(19, instance.exports.main(19)); 46 assertEquals(19, instance.exports.main(19));
47 assertEquals(27777, instance.exports.main(27777)); 47 assertEquals(27777, instance.exports.main(27777));
48 })(); 48 })();
49 49
50 (function LocalsTest2() { 50 (function LocalsTest2() {
51 // TODO(titzer): i64 only works on 64-bit platforms. 51 // TODO(titzer): i64 only works on 64-bit platforms.
52 var types = [ 52 var types = [
53 {locals: {i32_count: 1}, type: kAstI32}, 53 {locals: {i32_count: 1}, type: kAstI32},
54 // {locals: {i64_count: 1}, type: kAstI64}, 54 // {locals: {i64_count: 1}, type: kAstI64},
55 {locals: {f32_count: 1}, type: kAstF32}, 55 {locals: {f32_count: 1}, type: kAstF32},
56 {locals: {f64_count: 1}, type: kAstF64}, 56 {locals: {f64_count: 1}, type: kAstF64},
57 ]; 57 ];
58 58
59 for (p of types) { 59 for (p of types) {
60 var module = new WasmModuleBuilder(); 60 var module = new WasmModuleBuilder();
61 module.addFunction(undefined, makeSig_r_x(p.type, p.type)) 61 module.addFunction(undefined, makeSig_r_x(p.type, p.type))
62 .addLocals(p.locals) 62 .addLocals(p.locals)
63 .addBody([kExprGetLocal, 0, kExprSetLocal, 1]) 63 .addBody([kExprGetLocal, 0, kExprSetLocal, 1, kExprGetLocal, 1])
64 .exportAs("main"); 64 .exportAs("main");
65 65
66 var buffer = module.toBuffer(debug); 66 var buffer = module.toBuffer(debug);
67 var instance = Wasm.instantiateModule(buffer); 67 var instance = Wasm.instantiateModule(buffer);
68 assertEquals(19, instance.exports.main(19)); 68 assertEquals(19, instance.exports.main(19));
69 assertEquals(27777, instance.exports.main(27777)); 69 assertEquals(27777, instance.exports.main(27777));
70 } 70 }
71 })(); 71 })();
72 72
73 (function CallTest() { 73 (function CallTest() {
74 var module = new WasmModuleBuilder(); 74 var module = new WasmModuleBuilder();
75 module.addFunction("add", kSig_i_ii) 75 module.addFunction("add", kSig_i_ii)
76 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]); 76 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]);
77 module.addFunction("main", kSig_i_ii) 77 module.addFunction("main", kSig_i_ii)
78 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, kArity2 , 0]) 78 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprCallFunction, 0])
79 .exportAs("main"); 79 .exportAs("main");
80 80
81 var instance = module.instantiate(); 81 var instance = module.instantiate();
82 assertEquals(44, instance.exports.main(11, 33)); 82 assertEquals(44, instance.exports.main(11, 33));
83 assertEquals(7777, instance.exports.main(2222, 5555)); 83 assertEquals(7777, instance.exports.main(2222, 5555));
84 })(); 84 })();
85 85
86 (function IndirectCallTest() { 86 (function IndirectCallTest() {
87 var module = new WasmModuleBuilder(); 87 var module = new WasmModuleBuilder();
88 module.addFunction("add", kSig_i_ii) 88 module.addFunction("add", kSig_i_ii)
89 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]); 89 .addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add]);
90 module.addFunction("main", kSig_i_iii) 90 module.addFunction("main", kSig_i_iii)
91 .addBody([kExprGetLocal, 91 .addBody([kExprGetLocal,
92 0, kExprGetLocal, 1, kExprGetLocal, 2, kExprCallIndirect, kAri ty2, 0]) 92 1, kExprGetLocal, 2, kExprGetLocal, 0, kExprCallIndirect, 0])
93 .exportAs("main"); 93 .exportAs("main");
94 module.appendToTable([0]); 94 module.appendToTable([0]);
95 95
96 var instance = module.instantiate(); 96 var instance = module.instantiate();
97 assertEquals(44, instance.exports.main(0, 11, 33)); 97 assertEquals(44, instance.exports.main(0, 11, 33));
98 assertEquals(7777, instance.exports.main(0, 2222, 5555)); 98 assertEquals(7777, instance.exports.main(0, 2222, 5555));
99 assertThrows(function() { instance.exports.main(1, 1, 1); }); 99 assertThrows(function() { instance.exports.main(1, 1, 1); });
100 })(); 100 })();
101 101
102 (function DataSegmentTest() { 102 (function DataSegmentTest() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 array2[i] = array[i]; 136 array2[i] = array[i];
137 } 137 }
138 var instance = Wasm.instantiateModule(array2); 138 var instance = Wasm.instantiateModule(array2);
139 assertEquals(17, instance.exports.blarg()); 139 assertEquals(17, instance.exports.blarg());
140 })(); 140 })();
141 141
142 (function ImportTestTwoLevel() { 142 (function ImportTestTwoLevel() {
143 var module = new WasmModuleBuilder(); 143 var module = new WasmModuleBuilder();
144 var index = module.addImportWithModule("mod", "print", makeSig_v_x(kAstI32)) ; 144 var index = module.addImportWithModule("mod", "print", makeSig_v_x(kAstI32)) ;
145 module.addFunction("foo", kSig_v_v) 145 module.addFunction("foo", kSig_v_v)
146 .addBody([kExprI8Const, 19, kExprCallImport, kArity1, index]) 146 .addBody([kExprI8Const, 19, kExprCallFunction, index])
147 .exportAs("main"); 147 .exportAs("main");
148 148
149 var buffer = module.toBuffer(debug); 149 var buffer = module.toBuffer(debug);
150 var instance = Wasm.instantiateModule(buffer, {mod: {print: print}}); 150 var instance = Wasm.instantiateModule(buffer, {mod: {print: print}});
151 print("should print 19! "); 151 print("should print 19! ");
152 instance.exports.main(); 152 instance.exports.main();
153 })(); 153 })();
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/test-import-export-wrapper.js ('k') | test/mjsunit/wasm/trap-location.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698