SB.wast.js (2745B)
1 /* Copyright 2021 Mozilla Foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 // ./test/core/threads/SB.wast 17 18 // ./test/core/threads/SB.wast:1 19 let $0 = instantiate(`(module \$Mem 20 (memory (export "shared") 1 1 shared) 21 )`); 22 let $Mem = $0; 23 24 // Missing in source test: 25 // https://github.com/WebAssembly/threads/pull/217 26 register($Mem, `mem`); 27 28 // ./test/core/threads/SB.wast:5 29 let $T1 = new Thread($Mem, "$Mem", ` 30 31 // ./test/core/threads/SB.wast:6:3 32 register(\$Mem, \`mem\`); 33 34 // ./test/core/threads/SB.wast:7:3 35 let \$1 = instantiate(\`(module 36 (memory (import "mem" "shared") 1 10 shared) 37 (func (export "run") 38 (local i32) 39 (i32.store (i32.const 0) (i32.const 1)) 40 (i32.load (i32.const 4)) 41 (local.set 0) 42 43 ;; store results for checking 44 (i32.store (i32.const 24) (local.get 0)) 45 ) 46 )\`); 47 48 // ./test/core/threads/SB.wast:19:3 49 invoke(\$1, \`run\`, []); 50 `); 51 52 // ./test/core/threads/SB.wast:22 53 let $T2 = new Thread($Mem, "$Mem", ` 54 55 // ./test/core/threads/SB.wast:23:3 56 register(\$Mem, \`mem\`); 57 58 // ./test/core/threads/SB.wast:24:3 59 let \$2 = instantiate(\`(module 60 (memory (import "mem" "shared") 1 1 shared) 61 (func (export "run") 62 (local i32) 63 (i32.store (i32.const 4) (i32.const 1)) 64 (i32.load (i32.const 0)) 65 (local.set 0) 66 67 ;; store results for checking 68 (i32.store (i32.const 32) (local.get 0)) 69 ) 70 )\`); 71 72 // ./test/core/threads/SB.wast:37:3 73 invoke(\$2, \`run\`, []); 74 `); 75 76 // ./test/core/threads/SB.wast:40 77 $T1.wait(); 78 79 // ./test/core/threads/SB.wast:41 80 $T2.wait(); 81 82 // ./test/core/threads/SB.wast:43 83 let $3 = instantiate(`(module \$Check 84 (memory (import "mem" "shared") 1 1 shared) 85 86 (func (export "check") (result i32) 87 (local i32 i32) 88 (i32.load (i32.const 24)) 89 (local.set 0) 90 (i32.load (i32.const 32)) 91 (local.set 1) 92 93 ;; allowed results: (L_0 = 0 || L_0 = 1) && (L_1 = 0 || L_1 = 1) 94 95 (i32.or (i32.eq (local.get 0) (i32.const 1)) (i32.eq (local.get 0) (i32.const 0))) 96 (i32.or (i32.eq (local.get 1) (i32.const 1)) (i32.eq (local.get 1) (i32.const 0))) 97 (i32.and) 98 (return) 99 ) 100 )`); 101 let $Check = $3; 102 103 // ./test/core/threads/SB.wast:62 104 assert_return(() => invoke($Check, `check`, []), [value("i32", 1)]);