tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MP.wast.js (2697B)


      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/MP.wast
     17 
     18 // ./test/core/threads/MP.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/MP.wast:5
     29 let $T1 = new Thread($Mem, "$Mem", `
     30 
     31 // ./test/core/threads/MP.wast:6:3
     32 register(\$Mem, \`mem\`);
     33 
     34 // ./test/core/threads/MP.wast:7:3
     35 let \$1 = instantiate(\`(module
     36    (memory (import "mem" "shared") 1 10 shared)
     37    (func (export "run")
     38      (i32.store (i32.const 0) (i32.const 42))
     39      (i32.store (i32.const 4) (i32.const 1))
     40    )
     41  )\`);
     42 
     43 // ./test/core/threads/MP.wast:14:3
     44 invoke(\$1, \`run\`, []);
     45 `);
     46 
     47 // ./test/core/threads/MP.wast:17
     48 let $T2 = new Thread($Mem, "$Mem", `
     49 
     50 // ./test/core/threads/MP.wast:18:3
     51 register(\$Mem, \`mem\`);
     52 
     53 // ./test/core/threads/MP.wast:19:3
     54 let \$2 = instantiate(\`(module
     55    (memory (import "mem" "shared") 1 1 shared)
     56    (func (export "run")
     57      (local i32 i32)
     58      (i32.load (i32.const 4))
     59      (local.set 0)
     60      (i32.load (i32.const 0))
     61      (local.set 1)
     62 
     63      ;; store results for checking
     64      (i32.store (i32.const 24) (local.get 0))
     65      (i32.store (i32.const 32) (local.get 1))
     66    )
     67  )\`);
     68 
     69 // ./test/core/threads/MP.wast:34:3
     70 invoke(\$2, \`run\`, []);
     71 `);
     72 
     73 // ./test/core/threads/MP.wast:37
     74 $T1.wait();
     75 
     76 // ./test/core/threads/MP.wast:38
     77 $T2.wait();
     78 
     79 // ./test/core/threads/MP.wast:40
     80 let $3 = instantiate(`(module \$Check
     81  (memory (import "mem" "shared") 1 1 shared)
     82 
     83  (func (export "check") (result i32)
     84    (local i32 i32)
     85    (i32.load (i32.const 24))
     86    (local.set 0)
     87    (i32.load (i32.const 32))
     88    (local.set 1)
     89 
     90    ;; allowed results: (L_0 = 0 || L_0 = 1) && (L_1 = 0 || L_1 = 42)
     91 
     92    (i32.or (i32.eq (local.get 0) (i32.const 1)) (i32.eq (local.get 0) (i32.const 0)))
     93    (i32.or (i32.eq (local.get 1) (i32.const 42)) (i32.eq (local.get 1) (i32.const 0)))
     94    (i32.and)
     95    (return)
     96  )
     97 )`);
     98 let $Check = $3;
     99 
    100 // ./test/core/threads/MP.wast:59
    101 assert_return(() => invoke($Check, `check`, []), [value("i32", 1)]);