From 7c30ad5c4f9e070d531f2314013b00143d800c83 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Thu, 26 Apr 2018 11:16:34 -0400 Subject: [PATCH] Atomics: expected return values for all atomic operations --- .../Atomics/add/expected-return-value.js | 35 ++++++++++++++++ .../Atomics/and/expected-return-value.js | 38 ++++++++++++++++++ .../compareExchange/expected-return-value.js | 36 +++++++++++++++++ .../Atomics/exchange/expected-return-value.js | 35 ++++++++++++++++ .../bigint/expected-return-value.js | 29 ++++++++++++++ .../isLockFree/expected-return-value.js | 30 ++++++++++++++ .../Atomics/load/expected-return-value.js | 40 +++++++++++++++++++ .../Atomics/or/expected-return-value.js | 35 ++++++++++++++++ .../Atomics/store/expected-return-value.js | 26 ++++++++++++ .../Atomics/sub/expected-return-value.js | 37 +++++++++++++++++ .../no-spurious-wakeup-on-store-no-sleep.js | 39 ++++++++++++++++++ .../Atomics/xor/expected-return-value.js | 38 ++++++++++++++++++ 12 files changed, 418 insertions(+) create mode 100644 test/built-ins/Atomics/add/expected-return-value.js create mode 100644 test/built-ins/Atomics/and/expected-return-value.js create mode 100644 test/built-ins/Atomics/compareExchange/expected-return-value.js create mode 100644 test/built-ins/Atomics/exchange/expected-return-value.js create mode 100644 test/built-ins/Atomics/isLockFree/bigint/expected-return-value.js create mode 100644 test/built-ins/Atomics/isLockFree/expected-return-value.js create mode 100644 test/built-ins/Atomics/load/expected-return-value.js create mode 100644 test/built-ins/Atomics/or/expected-return-value.js create mode 100644 test/built-ins/Atomics/store/expected-return-value.js create mode 100644 test/built-ins/Atomics/sub/expected-return-value.js create mode 100644 test/built-ins/Atomics/wait/no-spurious-wakeup-on-store-no-sleep.js create mode 100644 test/built-ins/Atomics/xor/expected-return-value.js 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 0000000000..b60694689d --- /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 0000000000..86282e1d99 --- /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 0000000000..5f46bb74ef --- /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 0000000000..b5a91b03f6 --- /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 0000000000..1213d6e1cd --- /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 0000000000..81898abe72 --- /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 0000000000..b2ad4e19ae --- /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 0000000000..1cb876ede6 --- /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 0000000000..133b39ec92 --- /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 0000000000..77ce9506e7 --- /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 0000000000..4dfd02da18 --- /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 0000000000..a9bfbbb48c --- /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);