Skip to content

Commit

Permalink
Add Atomic load/store tests
Browse files Browse the repository at this point in the history
Move generated spec test to `chakra_generated`
  • Loading branch information
Cellule committed Dec 22, 2017
1 parent 01df540 commit 65a14e0
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 16 deletions.
1 change: 1 addition & 0 deletions test/WasmSpec/baselines/atomic_load.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
13/13 tests passed.
1 change: 1 addition & 0 deletions test/WasmSpec/baselines/atomic_store.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
13/13 tests passed.
1 change: 1 addition & 0 deletions test/WasmSpec/baselines/chakra_atomic_load.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18/18 tests passed.
1 change: 1 addition & 0 deletions test/WasmSpec/baselines/chakra_atomic_store.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18/18 tests passed.
29 changes: 29 additions & 0 deletions test/WasmSpec/chakra/chakra_atomic_load.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(module
;; todo make this a shared memory
(memory 1)
(data (i32.const 16) "\ff\ff\ff\ff\ff\ff\ff\ff")
(data (i32.const 24) "\12\34\56\78\00\00\ce\41")

(func (export "load") (param i32) (result i64)
(i64.atomic.load32_u offset=15 (get_local 0))
)
)

(assert_return (invoke "load" (i32.const 1)) (i64.const 0xffffffff))
(assert_return (invoke "load" (i32.const 5)) (i64.const 0xffffffff))
(assert_return (invoke "load" (i32.const 9)) (i64.const 0x78563412))
(assert_return (invoke "load" (i32.const 13)) (i64.const 0x41ce0000))
(assert_trap (invoke "load" (i32.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "load" (i32.const 2)) "atomic memory access is unaligned")
(assert_trap (invoke "load" (i32.const 3)) "atomic memory access is unaligned")
(assert_trap (invoke "load" (i32.const 4)) "atomic memory access is unaligned")
(assert_trap (invoke "load" (i32.const 6)) "atomic memory access is unaligned")
(assert_trap (invoke "load" (i32.const 7)) "atomic memory access is unaligned")
(assert_trap (invoke "load" (i32.const 8)) "atomic memory access is unaligned")
(assert_trap (invoke "load" (i32.const 10)) "atomic memory access is unaligned")
(assert_trap (invoke "load" (i32.const 11)) "atomic memory access is unaligned")
(assert_trap (invoke "load" (i32.const 12)) "atomic memory access is unaligned")
(assert_trap (invoke "load" (i32.const 14)) "atomic memory access is unaligned")

(assert_return (invoke "load" (i32.const 65517)) (i64.const 0))
(assert_trap (invoke "load" (i32.const 65521)) "out of bounds memory access")
28 changes: 28 additions & 0 deletions test/WasmSpec/chakra/chakra_atomic_store.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(module
;; todo make this a shared memory
(memory 1)

(func (export "store") (param i32 i64) (result i32)
(i64.atomic.store offset=15 (get_local 0) (get_local 1))
(i32.atomic.load offset=19 (get_local 0))
)
)

(assert_return (invoke "store" (i32.const 1) (i64.const 0xffffffff41ce0000)) (i32.const 0xffffffff))
(assert_return (invoke "store" (i32.const 9) (i64.const 0x78563412ffffffff)) (i32.const 0x78563412))
(assert_trap (invoke "store" (i32.const 0) (i64.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "store" (i32.const 2) (i64.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "store" (i32.const 3) (i64.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "store" (i32.const 4) (i64.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "store" (i32.const 5) (i64.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "store" (i32.const 6) (i64.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "store" (i32.const 7) (i64.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "store" (i32.const 8) (i64.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "store" (i32.const 10) (i64.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "store" (i32.const 11) (i64.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "store" (i32.const 12) (i64.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "store" (i32.const 13) (i64.const 0)) "atomic memory access is unaligned")
(assert_trap (invoke "store" (i32.const 14) (i64.const 0)) "atomic memory access is unaligned")

(assert_return (invoke "store" (i32.const 65513) (i64.const 0x78563412ffffffff)) (i32.const 0x78563412))
(assert_trap (invoke "store" (i32.const 65521) (i64.const 0)) "out of bounds memory access")
File renamed without changes.
File renamed without changes.
14 changes: 13 additions & 1 deletion test/WasmSpec/convert-test-suite/config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"folders": [
"chakra",
"chakra_generated",
"testsuite/core",
"testsuite/js-api",

"features/extends"
"features/extends",
"features/threads"
],
"features": [{
"flags": ["-wasmfastarray-"],
Expand Down Expand Up @@ -37,6 +39,16 @@
"chakra_extends_i32",
"chakra_extends_i64"
]
}, {
"required": true,
"flags": ["-WasmThreads"],
"folders": [
"features/threads"
],
"files": [
"chakra_atomic_load",
"chakra_atomic_store"
]
}],
"excludes": [
"names"
Expand Down
2 changes: 1 addition & 1 deletion test/WasmSpec/convert-test-suite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function removePossiblyEmptyFolder(folder) {
}

function generateChakraTests() {
const chakraTestsDestination = path.join(rlRoot, "chakra");
const chakraTestsDestination = path.join(rlRoot, "chakra_generated");

const chakraTests = require("./generateTests");
return removePossiblyEmptyFolder(chakraTestsDestination)
Expand Down
50 changes: 50 additions & 0 deletions test/WasmSpec/features/threads/atomic_load.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
(module
;; todo make this a shared memory
(memory 1)
(data (i32.const 0) "\ff\ff\ff\ff")
(data (i32.const 4) "\00\00\ce\41")
(data (i32.const 8) "\00\00\00\00\00\ff\8f\40")

(func (export "i32.atomic.load8_u") (result i32)
i32.const 1 i32.atomic.load8_u)
(func (export "i32.atomic.load16_u") (result i32)
i32.const 2 i32.atomic.load16_u)
(func (export "i32.atomic.load") (result i32)
i32.const 4 i32.atomic.load)

(func (export "i64.atomic.load8_u") (result i64)
i32.const 1 i64.atomic.load8_u)
(func (export "i64.atomic.load16_u") (result i64)
i32.const 2 i64.atomic.load16_u)
(func (export "i64.atomic.load32_u") (result i64)
i32.const 4 i64.atomic.load32_u)
(func (export "i64.atomic.load") (result i64)
i32.const 0 i64.atomic.load)

;; Test bad alignment

(func (export "bad.align-i32.atomic.load16_u") (result i32)
i32.const 1 i32.atomic.load16_u)
(func (export "bad.align-i32.atomic.load") (result i32)
i32.const 2 i32.atomic.load)

(func (export "bad.align-i64.atomic.load16_u") (result i64)
i32.const 1 i64.atomic.load16_u)
(func (export "bad.align-i64.atomic.load32_u") (result i64)
i32.const 2 i64.atomic.load32_u)
(func (export "bad.align-i64.atomic.load") (result i64)
i32.const 4 i64.atomic.load)
)

(assert_return (invoke "i32.atomic.load8_u") (i32.const 255))
(assert_return (invoke "i32.atomic.load16_u") (i32.const 65535))
(assert_return (invoke "i32.atomic.load") (i32.const 1104019456))
(assert_return (invoke "i64.atomic.load8_u") (i64.const 255))
(assert_return (invoke "i64.atomic.load16_u") (i64.const 65535))
(assert_return (invoke "i64.atomic.load32_u") (i64.const 1104019456))
(assert_return (invoke "i64.atomic.load") (i64.const 4741727461962678271))
(assert_trap (invoke "bad.align-i32.atomic.load16_u") "atomic memory access is unaligned")
(assert_trap (invoke "bad.align-i32.atomic.load") "atomic memory access is unaligned")
(assert_trap (invoke "bad.align-i64.atomic.load16_u") "atomic memory access is unaligned")
(assert_trap (invoke "bad.align-i64.atomic.load32_u") "atomic memory access is unaligned")
(assert_trap (invoke "bad.align-i64.atomic.load") "atomic memory access is unaligned")
68 changes: 68 additions & 0 deletions test/WasmSpec/features/threads/atomic_store.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
(module
;; todo make this a shared memory
(memory 1)

(func (export "i32.atomic.store8") (result i32)
i32.const 0 i32.const 0xfb i32.atomic.store8
i32.const 1 i32.const 0xfc i32.atomic.store8
i32.const 2 i32.const 0xfd i32.atomic.store8
i32.const 3 i32.const 0xfe i32.atomic.store8
i32.const 0 i32.load)

(func (export "i32.atomic.store16") (result i32)
i32.const 0 i32.const 0xcac9 i32.atomic.store16
i32.const 2 i32.const 0xcccb i32.atomic.store16
i32.const 0 i32.load)

(func (export "i32.atomic.store") (result i32)
i32.const 0 i32.const -123456 i32.atomic.store
i32.const 0 i32.load)

(func (export "i64.atomic.store8") (result i32)
i32.const 0 i64.const 0xeeeeeeeeeeeeeefb i64.atomic.store8
i32.const 1 i64.const 0xeeeeeeeeeeeeeefc i64.atomic.store8
i32.const 2 i64.const 0xeeeeeeeeeeeeeefd i64.atomic.store8
i32.const 3 i64.const 0xeeeeeeeeeeeeeefe i64.atomic.store8
i32.const 0 i32.load)

(func (export "i64.atomic.store16") (result i32)
i32.const 0 i64.const 0xeeeeeeeeeeeecac9 i64.atomic.store16
i32.const 2 i64.const 0xeeeeeeeeeeeecccb i64.atomic.store16
i32.const 0 i32.load)

(func (export "i64.atomic.store32") (result i32)
i32.const 0 i64.const -123456 i64.atomic.store32
i32.const 0 i32.load)

(func (export "i64.atomic.store") (result i64)
i32.const 0 i64.const 0xbaddc0de600dd00d i64.atomic.store
i32.const 0 i64.load)

;; Test bad alignment

(func (export "bad.align-i32.atomic.store16")
i32.const 1 i32.const 0 i32.atomic.store16)
(func (export "bad.align-i32.atomic.store")
i32.const 2 i32.const 0 i32.atomic.store)

(func (export "bad.align-i64.atomic.store16")
i32.const 1 i64.const 0 i64.atomic.store16)
(func (export "bad.align-i64.atomic.store32")
i32.const 2 i64.const 0 i64.atomic.store32)
(func (export "bad.align-i64.atomic.store")
i32.const 4 i64.const 0 i64.atomic.store)

)

(assert_return (invoke "i32.atomic.store8") (i32.const 4278058235))
(assert_return (invoke "i32.atomic.store16") (i32.const 3435907785))
(assert_return (invoke "i32.atomic.store") (i32.const 4294843840))
(assert_return (invoke "i64.atomic.store8") (i32.const 4278058235))
(assert_return (invoke "i64.atomic.store16") (i32.const 3435907785))
(assert_return (invoke "i64.atomic.store32") (i32.const 4294843840))
(assert_return (invoke "i64.atomic.store") (i64.const 13465130522234441741))
(assert_trap (invoke "bad.align-i32.atomic.store16") "atomic memory access is unaligned")
(assert_trap (invoke "bad.align-i32.atomic.store") "atomic memory access is unaligned")
(assert_trap (invoke "bad.align-i64.atomic.store16") "atomic memory access is unaligned")
(assert_trap (invoke "bad.align-i64.atomic.store32") "atomic memory access is unaligned")
(assert_trap (invoke "bad.align-i64.atomic.store") "atomic memory access is unaligned")
Loading

0 comments on commit 65a14e0

Please sign in to comment.