diff --git a/test/built-ins/Atomics/add/expected-return-value.js b/test/built-ins/Atomics/add/expected-return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..b60694689d2cc761b56bf8ad914071b2ed80ca77 --- /dev/null +++ b/test/built-ins/Atomics/add/expected-return-value.js @@ -0,0 +1,35 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.add +description: > + Atomics.add returns the value that existed at the + index prior to the operation. +info: | + Atomics.add( typedArray, index, value ) + + 1. Return ? AtomicReadModifyWrite(typedArray, index, value, add). + + AtomicReadModifyWrite( typedArray, index, value, op ) + + ... + 9. Return GetModifySetValueInBuffer(buffer, indexedPosition, + elementType, v, op). + + + GetModifySetValueInBuffer( arrayBuffer, + byteIndex, type, value, op [ , isLittleEndian ] ) + + ... + 16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian). + +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT); +var i32a = new Int32Array(buffer); +var value = 0b00000001000000001000000010000001; + +assert.sameValue(Atomics.add(i32a, 0, value), 0); +assert.sameValue(i32a[0], value); diff --git a/test/built-ins/Atomics/and/expected-return-value.js b/test/built-ins/Atomics/and/expected-return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..86282e1d99d39e232af4dd8924c429bfa60b9251 --- /dev/null +++ b/test/built-ins/Atomics/and/expected-return-value.js @@ -0,0 +1,38 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.and +description: > + Atomics.and returns the value that existed at the + index prior to the operation. +info: | + Atomics.and( typedArray, index, value ) + + 1. Return ? AtomicReadModifyWrite(typedArray, index, value, and). + + AtomicReadModifyWrite( typedArray, index, value, op ) + + ... + 9. Return GetModifySetValueInBuffer(buffer, indexedPosition, + elementType, v, op). + + + GetModifySetValueInBuffer( arrayBuffer, + byteIndex, type, value, op [ , isLittleEndian ] ) + + ... + 16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian). + +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT); +var i32a = new Int32Array(buffer); +var value = 0b00000001000000001000000010000001; +var other = 0b00000001111111111000000011111111; + +i32a[0] = value; + +assert.sameValue(Atomics.and(i32a, 0, value), value); +assert.sameValue(i32a[0], value & other); diff --git a/test/built-ins/Atomics/compareExchange/expected-return-value.js b/test/built-ins/Atomics/compareExchange/expected-return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..5f46bb74ef09df4d03b31f718be2fe5560f4c647 --- /dev/null +++ b/test/built-ins/Atomics/compareExchange/expected-return-value.js @@ -0,0 +1,36 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.compareExchange +description: > + Atomics.compareExchange returns the value that existed at the + index prior to the operation. +info: | + Atomics.compareExchange( typedArray, index, expectedValue, replacementValue ) + + ... + 12. Let compareExchange denote a semantic function of two List of + byte values arguments that returns the second argument if the + first argument is element-wise equal to expectedBytes. + 13. Return GetModifySetValueInBuffer(buffer, indexedPosition, + elementType, replacement, compareExchange). + + + GetModifySetValueInBuffer( arrayBuffer, + byteIndex, type, value, op [ , isLittleEndian ] ) + + ... + 16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian). + +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT); +var i32a = new Int32Array(buffer); +var value = 0b00000001000000001000000010000001; + +i32a[0] = value; + +assert.sameValue(Atomics.compareExchange(i32a, 0, value, 0), value); +assert.sameValue(i32a[0], 0); diff --git a/test/built-ins/Atomics/exchange/expected-return-value.js b/test/built-ins/Atomics/exchange/expected-return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..b5a91b03f6ace2df96c2b1dc0b433c58313b2cb1 --- /dev/null +++ b/test/built-ins/Atomics/exchange/expected-return-value.js @@ -0,0 +1,35 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.exchange +description: > + Atomics.and returns the value that existed at the + index prior to the operation. +info: | + Atomics.exchange( typedArray, index, value ) + + 1. Return ? AtomicReadModifyWrite(typedArray, index, value, second). + + AtomicReadModifyWrite( typedArray, index, value, op ) + + ... + 9. Return GetModifySetValueInBuffer(buffer, indexedPosition, + elementType, v, op). + + + GetModifySetValueInBuffer( arrayBuffer, + byteIndex, type, value, op [ , isLittleEndian ] ) + + ... + 16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian). + +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT); +var i32a = new Int32Array(buffer); +var value = 0b00000001000000001000000010000001; + +assert.sameValue(Atomics.exchange(i32a, 0, value), 0); +assert.sameValue(i32a[0], value); diff --git a/test/built-ins/Atomics/isLockFree/bigint/expected-return-value.js b/test/built-ins/Atomics/isLockFree/bigint/expected-return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..1213d6e1cda44b021f90c606653a9981e32e5903 --- /dev/null +++ b/test/built-ins/Atomics/isLockFree/bigint/expected-return-value.js @@ -0,0 +1,29 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.isLockFree +description: > + Atomics.isLockFree returns a boolean that indicates whether + operations on datum of size will be performed without the agent + acquiring a lock outside of size bytes. +info: | + Atomics.isLockFree( size ) + + 1. Let n be ? ToInteger(size). + 2. Let AR be the Agent Record of the surrounding agent. + 3. If n equals 1, return AR.[[IsLockFree1]]. + 4. If n equals 2, return AR.[[IsLockFree2]]. + 5. If n equals 4, return true. + 6. If n equals 8, return AR.[[IsLockFree8]]. + 7. Return false. + +features: [Atomics, SharedArrayBuffer, TypedArray] +includes: [testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(Atomics.isLockFree(TA.BYTES_PER_ELEMENT), true); +}); + + diff --git a/test/built-ins/Atomics/isLockFree/expected-return-value.js b/test/built-ins/Atomics/isLockFree/expected-return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..81898abe72a7ade57631bbabaedf184492843a5b --- /dev/null +++ b/test/built-ins/Atomics/isLockFree/expected-return-value.js @@ -0,0 +1,30 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.isLockFree +description: > + Atomics.isLockFree returns a boolean that indicates whether + operations on datum of size will be performed without the agent + acquiring a lock outside of size bytes. +info: | + Atomics.isLockFree( size ) + + 1. Let n be ? ToInteger(size). + 2. Let AR be the Agent Record of the surrounding agent. + 3. If n equals 1, return AR.[[IsLockFree1]]. + 4. If n equals 2, return AR.[[IsLockFree2]]. + 5. If n equals 4, return true. + 6. Return false. + +features: [Atomics, SharedArrayBuffer, TypedArray] +includes: [testTypedArray.js] +---*/ + +var views = intArrayConstructors.slice(); + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(Atomics.isLockFree(TA.BYTES_PER_ELEMENT), true); +}, views); + + diff --git a/test/built-ins/Atomics/load/expected-return-value.js b/test/built-ins/Atomics/load/expected-return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..b2ad4e19ae0315f6f320196df1de982329ba5ba5 --- /dev/null +++ b/test/built-ins/Atomics/load/expected-return-value.js @@ -0,0 +1,40 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.load +description: > + Atomics.load returns the value that existed at the + index prior to the operation. +info: | + Atomics.load( typedArray, index, value ) + + 1. Return ? AtomicLoad(typedArray, index). + + AtomicLoad( typedArray, index ) + + 1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray). + 2. Let i be ? ValidateAtomicAccess(typedArray, index). + 3. Let arrayTypeName be typedArray.[[TypedArrayName]]. + 4. Let elementSize be the Number value of the Element Size value + specified in Table 56 for arrayTypeName. + 5. Let elementType be the String value of the Element Type value + in Table 56 for arrayTypeName. + 6. Let offset be typedArray.[[ByteOffset]]. + 7. Let indexedPosition be (i × elementSize) + offset. + 8. Return GetValueFromBuffer(buffer, indexedPosition, elementType, + true, "SeqCst"). + +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT); +var i32a = new Int32Array(buffer); +var value = 0b00000001000000001000000010000001; + +assert.sameValue(Atomics.load(i32a, 0), 0); + +i32a[0] = value; + +assert.sameValue(Atomics.load(i32a, 0), value); + diff --git a/test/built-ins/Atomics/or/expected-return-value.js b/test/built-ins/Atomics/or/expected-return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..1cb876ede60e03a899f4cb1e3306a97e900564ca --- /dev/null +++ b/test/built-ins/Atomics/or/expected-return-value.js @@ -0,0 +1,35 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.or +description: > + Atomics.and returns the value that existed at the + index prior to the operation. +info: | + Atomics.or( typedArray, index, value ) + + 1. Return ? AtomicReadModifyWrite(typedArray, index, value, or). + + AtomicReadModifyWrite( typedArray, index, value, op ) + + ... + 9. Return GetModifySetValueInBuffer(buffer, indexedPosition, + elementType, v, op). + + + GetModifySetValueInBuffer( arrayBuffer, + byteIndex, type, value, op [ , isLittleEndian ] ) + + ... + 16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian). + +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT); +var i32a = new Int32Array(buffer); +var value = 0b00000001000000001000000010000001; + +assert.sameValue(Atomics.or(i32a, 0, value), 0); +assert.sameValue(i32a[0], 0 | value); diff --git a/test/built-ins/Atomics/store/expected-return-value.js b/test/built-ins/Atomics/store/expected-return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..133b39ec92a425269531bbe7aae57c7c1bb3346d --- /dev/null +++ b/test/built-ins/Atomics/store/expected-return-value.js @@ -0,0 +1,26 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.store +description: > + Atomics.store returns the newly stored value +info: | + Atomics.store( typedArray, index, value ) + + ... + 3. Let v be ? ToInteger(value). + ... + 9. Perform SetValueInBuffer(buffer, indexedPosition, + elementType, v, true, "SeqCst"). + 10. Return v. + +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT); +var i32a = new Int32Array(buffer); +var expect = 0b00000001000000001000000010000001; + +assert.sameValue(Atomics.store(i32a, 0, expect), expect); +assert.sameValue(i32a[0], expect); diff --git a/test/built-ins/Atomics/sub/expected-return-value.js b/test/built-ins/Atomics/sub/expected-return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..77ce9506e79af899df7fc6cc6149c05595e6bd75 --- /dev/null +++ b/test/built-ins/Atomics/sub/expected-return-value.js @@ -0,0 +1,37 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.sub +description: > + Atomics.and returns the value that existed at the + index prior to the operation. +info: | + Atomics.sub( typedArray, index, value ) + + 1. Return ? AtomicReadModifyWrite(typedArray, index, value, subtract). + + AtomicReadModifyWrite( typedArray, index, value, op ) + + ... + 9. Return GetModifySetValueInBuffer(buffer, indexedPosition, + elementType, v, op). + + + GetModifySetValueInBuffer( arrayBuffer, + byteIndex, type, value, op [ , isLittleEndian ] ) + + ... + 16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian). + +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT); +var i32a = new Int32Array(buffer); +var value = 0b00000001000000001000000010000001; + +i32a[0] = value; + +assert.sameValue(Atomics.sub(i32a, 0, value), value); +assert.sameValue(i32a[0], 0); diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-no-sleep.js b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-no-sleep.js new file mode 100644 index 0000000000000000000000000000000000000000..4dfd02da1855cca107e2c4be7abc1026fd5b2ddf --- /dev/null +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-no-sleep.js @@ -0,0 +1,39 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.wait +description: > + Demonstrates that Atomics.store(...) is causing a waiting +features: [Atomics, computed-property-names, SharedArrayBuffer, TypedArray] +---*/ +function getReport() { + var r; + while ((r = $262.agent.getReport()) == null) { + $262.agent.sleep(10); + } + return r; +} + +const TWO_SECOND_TIMEOUT = 2000; +const i32a = new Int32Array( + new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT) +); + +$262.agent.start(` + $262.agent.receiveBroadcast(function(sab) { + var i32a = new Int32Array(sab); + var before = Date.now(); + Atomics.wait(i32a, 0, 0, ${TWO_SECOND_TIMEOUT}); + $262.agent.report("done"); + $262.agent.leaving(); + }); +`); + +$262.agent.broadcast(i32a.buffer); +$262.agent.sleep(10); +Atomics.store(i32a, 0, 0x111111); + +assert.sameValue(getReport(), "done"); + + diff --git a/test/built-ins/Atomics/xor/expected-return-value.js b/test/built-ins/Atomics/xor/expected-return-value.js new file mode 100644 index 0000000000000000000000000000000000000000..a9bfbbb48caafdda5cd5b34a55287cff615f9e80 --- /dev/null +++ b/test/built-ins/Atomics/xor/expected-return-value.js @@ -0,0 +1,38 @@ +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.xor +description: > + Atomics.xor returns the value that existed at the + index prior to the operation. +info: | + Atomics.xor( typedArray, index, value ) + + 1. Return ? AtomicReadModifyWrite(typedArray, index, value, xor). + + AtomicReadModifyWrite( typedArray, index, value, op ) + + ... + 9. Return GetModifySetValueInBuffer(buffer, indexedPosition, + elementType, v, op). + + + GetModifySetValueInBuffer( arrayBuffer, + byteIndex, type, value, op [ , isLittleEndian ] ) + + ... + 16. Return RawBytesToNumber(type, rawBytesRead, isLittleEndian). + +features: [Atomics, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT); +var i32a = new Int32Array(buffer); +var value = 0b00000001000000001000000010000001; +var other = 0b00000001111111111000000011111111; + +i32a[0] = value; + +assert.sameValue(Atomics.xor(i32a, 0, other), value); +assert.sameValue(i32a[0], value ^ other);