diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
commit | d8bbc7858622b6d9c278469aab701ca0b609cddf (patch) | |
tree | eff41dc61d9f714852212739e6b3738b82a2af87 /testing/web-platform/tests/webnn/validation_tests/constant.https.any.js | |
parent | Releasing progress-linux version 125.0.3-1~progress7.99u1. (diff) | |
download | firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webnn/validation_tests/constant.https.any.js')
-rw-r--r-- | testing/web-platform/tests/webnn/validation_tests/constant.https.any.js | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webnn/validation_tests/constant.https.any.js b/testing/web-platform/tests/webnn/validation_tests/constant.https.any.js new file mode 100644 index 0000000000..86a60ee209 --- /dev/null +++ b/testing/web-platform/tests/webnn/validation_tests/constant.https.any.js @@ -0,0 +1,141 @@ +// META: title=validation tests for WebNN API constant interface +// META: global=window,dedicatedworker +// META: script=../resources/utils_validation.js + +'use strict'; + +const tests = [ + // Tests for constant(descriptor, bufferView) + { + name: + '[constant] Test building a 0-D scalar constant without presenting dimensions', + descriptor: {dataType: 'float32'}, + bufferView: {type: Float32Array, byteLength: 1 * 4}, + output: {dataType: 'float32', dimensions: []} + }, + { + name: + '[constant] Test building a 0-D scalar constant with empty dimensions', + descriptor: {dataType: 'float32', dimensions: []}, + bufferView: {type: Float32Array, byteLength: 1 * 4}, + output: {dataType: 'float32', dimensions: []} + }, + { + name: '[constant] Test building a constant with float32 data type', + descriptor: {dataType: 'float32', dimensions: [2, 3]}, + bufferView: {type: Float32Array, byteLength: 6 * 4}, + output: {dataType: 'float32', dimensions: [2, 3]} + }, + { + name: + '[constant] Throw if byte length of bufferView for float32 doesn\'t match the given dimensions', + descriptor: {dataType: 'float32', dimensions: [2, 3]}, + bufferView: { + type: Float32Array, + byteLength: 6 * 4 - 4 // The bufferView's byte length is less than the + // one by given dimensions + } + }, + // TODO (crbug.com/329702838): Test building a constant with float16 data type + { + name: '[constant] Test building a constant with int32 data type', + descriptor: {dataType: 'int32', dimensions: [2, 3]}, + bufferView: {type: Int32Array, byteLength: 6 * 4}, + output: {dataType: 'int32', dimensions: [2, 3]} + }, + { + name: + '[constant] Throw if byte length of bufferView for int32 doesn\'t match the given dimensions', + descriptor: {dataType: 'int32', dimensions: [2, 3]}, + bufferView: { + type: Int32Array, + byteLength: 6 * 4 + 4 // The bufferView's byte length is greater than the + // one by given dimensions + } + }, + { + name: '[constant] Test building a constant with uint32 data type', + descriptor: {dataType: 'uint32', dimensions: [2, 3]}, + bufferView: {type: Uint32Array, byteLength: 6 * 4}, + output: {dataType: 'uint32', dimensions: [2, 3]} + }, + { + name: + '[constant] Throw if byte length of bufferView for uint32 doesn\'t match the given dimensions', + descriptor: {dataType: 'uint32', dimensions: [2, 3]}, + bufferView: {type: Uint32Array, byteLength: 6 * 4 + 4} + }, + { + name: '[constant] Test building a constant with int64 data type', + descriptor: {dataType: 'int64', dimensions: [2, 3]}, + bufferView: {type: BigInt64Array, byteLength: 6 * 8}, + output: {dataType: 'int64', dimensions: [2, 3]} + }, + { + name: + '[constant] Throw if byte length of bufferView for int64 doesn\'t match the given dimensions', + descriptor: {dataType: 'int64', dimensions: [2, 3]}, + bufferView: {type: BigInt64Array, byteLength: 6 * 8 + 8} + }, + { + name: '[constant] Test building a constant with uint64 data type', + descriptor: {dataType: 'uint64', dimensions: [2, 3]}, + bufferView: {type: BigUint64Array, byteLength: 6 * 8}, + output: {dataType: 'uint64', dimensions: [2, 3]} + }, + { + name: + '[constant] Throw if byte length of bufferView for uint64 doesn\'t match the given dimensions', + descriptor: {dataType: 'uint64', dimensions: [2, 3]}, + bufferView: {type: BigUint64Array, byteLength: 6 * 8 + 8} + }, + { + name: '[constant] Test building a constant with int8 data type', + descriptor: {dataType: 'int8', dimensions: [2, 3]}, + bufferView: {type: Int8Array, byteLength: 6 * 1}, + output: {dataType: 'int8', dimensions: [2, 3]} + }, + { + name: + '[constant] Throw if byte length of bufferView for int8 doesn\'t match the given dimensions', + descriptor: {dataType: 'int8', dimensions: [2, 3]}, + bufferView: {type: Int8Array, byteLength: 6 * 4 - 4} + }, + { + name: '[constant] Test building a constant with uint8 data type', + descriptor: {dataType: 'uint8', dimensions: [2, 3]}, + bufferView: {type: Uint8Array, byteLength: 6 * 1}, + output: {dataType: 'uint8', dimensions: [2, 3]} + }, + { + name: + '[constant] Throw if byte length of bufferView for uint8 doesn\'t match the given dimensions', + descriptor: {dataType: 'uint8', dimensions: [2, 3]}, + bufferView: {type: Uint8Array, byteLength: 6 * 4 - 4} + }, + { + name: '[constant] Throw if a dimension is 0', + descriptor: {dataType: 'float32', dimensions: [2, 0]}, + bufferView: {type: Float32Array, byteLength: 2 * 4} + }, + { + name: + '[constant] Throw if bufferView type doesn\'t match the operand data type', + descriptor: {dataType: 'float32', dimensions: [2, 3]}, + bufferView: {type: Int32Array, byteLength: 6 * 4} + } +]; + +tests.forEach( + test => promise_test(async t => { + const buffer = new ArrayBuffer(test.bufferView.byteLength); + const bufferView = new test.bufferView.type(buffer); + if (test.output) { + const constantOperand = builder.constant(test.descriptor, bufferView); + assert_equals(constantOperand.dataType(), test.output.dataType); + assert_array_equals(constantOperand.shape(), test.output.dimensions); + } else { + assert_throws_js( + TypeError, () => builder.constant(test.descriptor, bufferView)); + } + }, test.name)); |