test_wasm_jspi_profiler.js (3385B)
1 Services.prefs.setBoolPref("javascript.options.wasm_js_promise_integration", true); 2 registerCleanupFunction(() => { 3 Services.prefs.clearUserPref("javascript.options.wasm_js_promise_integration"); 4 }); 5 6 // The tests runs code in tight loop with the profiler enabled. It is testing 7 // behavior of JS PI specific methods and generated code. 8 // It is not guarantee 100% hit since the profiler probes stacks every 1ms, 9 // but it will happen often enough. 10 add_task(async () => { 11 if (!WebAssembly.promising) { 12 return; 13 } 14 15 await Services.profiler.StartProfiler(10, 1, ["js"], ["GeckoMain"]); 16 Assert.ok(Services.profiler.IsActive()); 17 18 /* Wasm module that is tested: 19 (module 20 (import "js" "compute_delta" 21 (func $compute_delta (param i32) (result f64))) 22 23 (func (export "update_state_export") (param i32) (result f64) 24 (call $compute_delta (local.get 0)) 25 ) 26 ) 27 */ 28 29 var compute_delta = (i) => i / 100; 30 const b = new Uint8Array([ 31 0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 124, 2, 20, 1, 2, 106, 32 115, 13, 99, 111, 109, 112, 117, 116, 101, 95, 100, 101, 108, 116, 97, 33 0, 0, 3, 2, 1, 0, 7, 23, 1, 19, 117, 112, 100, 97, 116, 101, 95, 115, 116, 34 97, 116, 101, 95, 101, 120, 112, 111, 114, 116, 0, 1, 10, 8, 1, 6, 0, 32, 35 0, 16, 0, 11, 0, 23, 4, 110, 97, 109, 101, 1, 16, 1, 0, 13, 99, 111, 109, 36 112, 117, 116, 101, 95, 100, 101, 108, 116, 97 37 ]); 38 const ins = new WebAssembly.Instance(new WebAssembly.Module(b), { 39 js: { compute_delta, }, 40 }); 41 var update_state = WebAssembly.promising( 42 ins.exports.update_state_export 43 ); 44 45 for (var i = 0; i < 1000; i++) { 46 var r = await update_state(4); 47 if (i % 222 == 0) { 48 Assert.equal(r, .04); 49 } 50 } 51 52 Assert.ok(true, "Done"); 53 await Services.profiler.StopProfiler(); 54 }); 55 56 add_task(async () => { 57 if (!WebAssembly.promising) { 58 return; 59 } 60 61 await Services.profiler.StartProfiler(10, 1, ["js"], ["GeckoMain"]); 62 Assert.ok(Services.profiler.IsActive()); 63 64 /* Wasm module that is tested: 65 (module 66 (import "js" "compute_delta" 67 (func $compute_delta (param i32) (result f64))) 68 69 (func (export "update_state_export") (param i32) (result f64) 70 (call $compute_delta (local.get 0)) 71 ) 72 ) 73 */ 74 75 var compute_delta = async (i) => i / 100; 76 var suspending_compute_delta = new WebAssembly.Suspending( 77 compute_delta 78 ); 79 const b = new Uint8Array([ 80 0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 124, 2, 20, 1, 2, 106, 81 115, 13, 99, 111, 109, 112, 117, 116, 101, 95, 100, 101, 108, 116, 97, 0, 82 0, 3, 2, 1, 0, 7, 23, 1, 19, 117, 112, 100, 97, 116, 101, 95, 115, 116, 97, 83 116, 101, 95, 101, 120, 112, 111, 114, 116, 0, 1, 10, 8, 1, 6, 0, 32, 0, 84 16, 0, 11, 0, 23, 4, 110, 97, 109, 101, 1, 16, 1, 0, 13, 99, 111, 109, 112, 85 117, 116, 101, 95, 100, 101, 108, 116, 97 86 ]); 87 const ins = new WebAssembly.Instance(new WebAssembly.Module(b), { 88 js: { compute_delta: suspending_compute_delta, }, 89 }); 90 var update_state = WebAssembly.promising( 91 ins.exports.update_state_export 92 ); 93 94 for (var i = 0; i < 1000; i++) { 95 var r = await update_state(4); 96 if (i % 222 == 0) { 97 Assert.equal(r, .04); 98 } 99 } 100 101 Assert.ok(true, "Done"); 102 await Services.profiler.StopProfiler(); 103 }); 104 105 /** 106 * All the tests are implemented with add_task, this starts them automatically. 107 */ 108 function run_test() { 109 do_get_profile(); 110 run_next_test(); 111 }