Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SharedArrayBuffer and Atomics tests #839

Merged
merged 20 commits into from
Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b07a01e
Add SharedArrayBuffer and Atomics tests
Jan 13, 2017
d1fccaa
Add Atomics[@@toStringTag] test
syg Jan 20, 2017
40bb0d2
Fix new SAB tests' copyright lines to say Mozilla
syg Jan 23, 2017
6e2b2e5
Refactor Atomics tests
syg Jan 24, 2017
9d97d3c
Fix style in SharedArrayBuffer.prototype.slice tests
syg Jan 24, 2017
49ab6c5
Remove features: [Symbol] from SharedArrayBuffer tests
syg Jan 24, 2017
291563d
Split out SharedArrayBuffer versions of TypedArrays/buffer-arg-* tests
syg Jan 24, 2017
388466d
Revert buffer-arg tests to only test ArrayBuffer
syg Jan 24, 2017
ab2ca76
Split out SharedArrayBuffer DataView tests
syg Jan 24, 2017
1297867
Revert DataView tests to only test ArrayBuffer
syg Jan 24, 2017
89a0f73
Remove agent_spidermonkey.js for merging
syg Jan 24, 2017
c55033e
Revert "Fix new SAB tests' copyright lines to say Mozilla"
syg Jan 24, 2017
32ba9c0
Append Mozilla copyright instead of replacing original copyright in m…
syg Jan 24, 2017
b970a8d
Copy more analogous ArrayBuffer tests to SharedArrayBuffer
syg Jan 24, 2017
03e19ad
Adding missing testTypedArray.js include in Atomics tests
syg Jan 24, 2017
2d74325
Refactor 100 to $ATOMICS_MAX_TIME_EPSILON in atomicsHelper.js
syg Jan 24, 2017
28abb1d
Combine two features: lines
syg Jan 24, 2017
adae9e8
Add tests for [Shared]ArrayBuffer.prototype.{byteLength,slice} being …
syg Jan 24, 2017
70e2166
Add test for new %TypedArray%(new %TypedArray%(SAB))
syg Jan 25, 2017
f076541
Add versions of %TypedArray%.prototype.set on SharedArrayBuffer-backe…
syg Jan 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions INTERPRETING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,33 @@ properties of the global scope prior to test execution.

- **`global`** - a reference to the global object on which `$` was initially
defined
- **`agent`** - an ordinary object with the following properties:
- **`start`** - a function that takes a script source string and runs
the script in a concurrent agent. Will block until that agent is
running. The agent has no representation. The agent script will be
run in an environment that has an object `$` with a property `agent`
with the following properties:
- **`receiveBroadcast`** - a function that takes a function and
calls the function when it has received a broadcast from the parent,
passing it the broadcast as two arguments, a SharedArrayBuffer and
an Int32. This function may return before a broadcast is received
(eg to return to an event loop to await a message) and no code should
follow the call to this function.
- **`report`** - a function that takes a string and places it in a
transmit queue whence the parent will retrieve it. Messages
should be short.
- **`sleep`** - a function that takes a millisecond argument and
sleeps the agent for approximately that duration.
- **`leaving`** - a function that signals that the agent is done and
may be terminated (if possible).
- **`broadcast`** - a function that takes a SharedArrayBuffer and an Int32
and broadcasts the two values to all concurrent agents. The function
blocks until all agents have retrieved the message. Note, this assumes
that all agents that were started are still running.
- **`getReport`** - a function that reads an incoming string from any agent,
and returns it if it exists, or returns `null` otherwise.
- **`sleep`** - a function that takes a millisecond argument and
sleeps the execution for approximately that duration.

### Strict Mode

Expand Down
110 changes: 110 additions & 0 deletions harness/testAtomics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/**
* Calls the provided function for a each bad index that should throw a
* RangeError when passed to an Atomics method on a SAB-backed view where
* index 125 is out of range.
*
* @param f - the function to call for each bad index.
*/
function testWithAtomicsOutOfBoundsIndices(f) {
var bad_indices = [
(view) => -1,
(view) => view.length,
(view) => view.length*2,
(view) => undefined,
(view) => Number.NaN,
(view) => Number.POSITIVE_INFINITY,
(view) => Number.NEGATIVE_INFINITY,
(view) => '3.5',
(view) => 3.5,
(view) => { password: "qumquat" },
(view) => ({ valueOf: () => 125 }),
(view) => ({ toString: () => '125', valueOf: false }) // non-callable valueOf triggers invocation of toString
];

for (let IdxGen of bad_indices) {
try {
f(IdxGen);
} catch (e) {
e.message += " (Testing with index gen " + IdxGen + ".)";
throw e;
}
}
}

/**
* Calls the provided function for each good index that should not throw when
* passed to an Atomics method on a SAB-backed view.
*
* @param f - the function to call for each good index.
*/
function testWithAtomicsInBoundsIndices(f) {
var good_indices = [
(view) => 0/-1, // -0
(view) => '-0',
(view) => view.length - 1,
(view) => ({ valueOf: () => 0 }),
(view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString
];

for (let IdxGen of good_indices) {
try {
f(IdxGen);
} catch (e) {
e.message += " (Testing with index gen " + IdxGen + ".)";
throw e;
}
}
}

/**
* Calls the provided function for each value that should throw a TypeError
* when passed to an Atomics method as a view.
*
* @param f - the function to call for each non-view value.
*/

function testWithAtomicsNonViewValues(f) {
var values = [
null,
undefined,
true,
false,
new Boolean(true),
10,
3.14,
new Number(4),
"Hi there",
new Date,
/a*utomaton/g,
{ password: "qumquat" },
new DataView(new ArrayBuffer(10)),
new ArrayBuffer(128),
new SharedArrayBuffer(128),
new Error("Ouch"),
[1,1,2,3,5,8],
((x) => -x),
new Map(),
new Set(),
new WeakMap(),
new WeakSet(),
Symbol("halleluja"),
// TODO: Proxy?
Object,
Int32Array,
Date,
Math,
Atomics
];

for (let nonView of values) {
try {
f(nonView);
} catch (e) {
e.message += " (Testing with non-view value " + nonView + ".)";
throw e;
}
}
}
20 changes: 20 additions & 0 deletions test/built-ins/Atomics/Symbol.toStringTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
`Symbol.toStringTag` property descriptor on Atomics
info: >
The initial value of the @@toStringTag property is the String value
"Atomics".

This property has the attributes { [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Symbol.toStringTag]
---*/

assert.sameValue(Atomics[Symbol.toStringTag], 'Atomics');

verifyNotEnumerable(Atomics, Symbol.toStringTag);
verifyNotWritable(Atomics, Symbol.toStringTag);
verifyConfigurable(Atomics, Symbol.toStringTag);
19 changes: 19 additions & 0 deletions test/built-ins/Atomics/add/bad-range.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
Test range checking of Atomics.add on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/

var sab = new SharedArrayBuffer(4);
var views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];

testWithTypedArrayConstructors(function(View) {
let view = new View(sab);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's already a harness helper that can be used to loop on different TypedArray constructors, even on specific constructors...

testWithTypedArrayConstructors(fn(View) { let view = new View(sab); ... }, views) can be used as it also tells where the error is if an assertion fail.

testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.add(view, Idx, 10));
});
}, views);
11 changes: 11 additions & 0 deletions test/built-ins/Atomics/add/descriptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.

/*---
description: Testing descriptor property of Atomics.add
includes: [propertyHelper.js]
---*/

verifyWritable(Atomics, "add");
verifyNotEnumerable(Atomics, "add");
verifyConfigurable(Atomics, "add");
53 changes: 53 additions & 0 deletions test/built-ins/Atomics/add/good-views.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Test Atomics.add on arrays that allow atomic operations.
includes: [testAtomics.js, testTypedArray.js]
---*/

var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);

var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];

testWithTypedArrayConstructors(function(View) {
// Make it interesting - use non-zero byteOffsets and non-zero indexes.

var view = new View(sab, 32, 20);
var control = new View(ab, 0, 2);

// Add positive number
view[8] = 0;
assert.sameValue(Atomics.add(view, 8, 10), 0);
assert.sameValue(view[8], 10);

// Add negative number
assert.sameValue(Atomics.add(view, 8, -5), 10);
assert.sameValue(view[8], 5);

view[3] = -5;
control[0] = -5;
assert.sameValue(Atomics.add(view, 3, 0), control[0],
"Result is negative and subject to coercion");

control[0] = 12345;
view[3] = 12345;
assert.sameValue(Atomics.add(view, 3, 0), control[0],
"Result is subject to chopping");

control[0] = 123456789;
view[3] = 123456789;
assert.sameValue(Atomics.add(view, 3, 0), control[0],
"Result is subject to chopping");

// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0);
// Atomics.store() computes an index from Idx in the same way as other
// Atomics operations, not quite like view[Idx].
Atomics.store(view, Idx, 37);
assert.sameValue(Atomics.add(view, Idx, 0), 37);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once again an assertion message here indicating the used index

});
}, int_views);
28 changes: 28 additions & 0 deletions test/built-ins/Atomics/add/length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
Atomics.add.length is 3.
info: >
Atomics.add ( ia, index, val )

17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form “...name”
are not included in the default argument count.

Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/

assert.sameValue(Atomics.add.length, 3);

verifyNotEnumerable(Atomics.add, "length");
verifyNotWritable(Atomics.add, "length");
verifyConfigurable(Atomics.add, "length");
14 changes: 14 additions & 0 deletions test/built-ins/Atomics/add/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2017 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
Atomics.add.name is "add".
includes: [propertyHelper.js]
---*/

assert.sameValue(Atomics.add.name, "add");

verifyNotEnumerable(Atomics.add, "name");
verifyNotWritable(Atomics.add, "name");
verifyConfigurable(Atomics.add, "name");
12 changes: 12 additions & 0 deletions test/built-ins/Atomics/add/non-views.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
Test Atomics.add on view values other than TypedArrays
includes: [testAtomics.js]
---*/

testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.add(view, 0, 0)));
});
17 changes: 17 additions & 0 deletions test/built-ins/Atomics/add/nonshared-int-views.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
Test Atomics.add on non-shared integer TypedArrays
---*/

var ab = new ArrayBuffer(16);

var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];

testWithTypedArrayConstructors(function(View) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing include for testTypedArray.js (also applies to other files).

var view = new View(ab);

assert.throws(TypeError, (() => Atomics.add(view, 0, 0)));
}, int_views);
17 changes: 17 additions & 0 deletions test/built-ins/Atomics/add/shared-nonint-views.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
Test Atomics.add on shared non-integer TypedArrays
---*/

var sab = new SharedArrayBuffer(1024);

var other_views = [Uint8ClampedArray, Float32Array, Float64Array];

testWithTypedArrayConstructors(function(View) {
var view = new View(sab);

assert.throws(TypeError, (() => Atomics.add(view, 0, 0)));
}, other_views);
19 changes: 19 additions & 0 deletions test/built-ins/Atomics/and/bad-range.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
Test range checking of Atomics.and on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/

var sab = new SharedArrayBuffer(4);
var views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];

testWithTypedArrayConstructors(function(View) {
let view = new View(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.and(view, Idx, 10));
});
}, views);
11 changes: 11 additions & 0 deletions test/built-ins/Atomics/and/descriptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.

/*---
description: Testing descriptor property of Atomics.and
includes: [propertyHelper.js]
---*/

verifyWritable(Atomics, "and");
verifyNotEnumerable(Atomics, "and");
verifyConfigurable(Atomics, "and");
Loading