webnn: Migrate concat validation tests to WPTs
This CL adds WPT tests for concat and removes the unit tests `MLGraphBuilderTest.ConcatTest` and `MLGraphTestMojo.ConcatTest`.
Bug: 327337526, 328026885
Change-Id: I6dc130211693ca6c215f91ff4cf43fc7df13eafa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5371168
Commit-Queue: ningxin hu <ningxin.hu@intel.com>
Reviewed-by: Austin Sullivan <asully@chromium.org>
Reviewed-by: ningxin hu <ningxin.hu@intel.com>
Cr-Commit-Position: refs/heads/main@{#1276012}
diff --git a/webnn/validation_tests/concat.https.any.js b/webnn/validation_tests/concat.https.any.js
new file mode 100644
index 0000000..0d69b27
--- /dev/null
+++ b/webnn/validation_tests/concat.https.any.js
@@ -0,0 +1,93 @@
+// META: title=validation tests for WebNN API concat operation
+// META: global=window,dedicatedworker
+// META: script=../resources/utils_validation.js
+// META: timeout=long
+
+'use strict';
+
+const tests = [
+ {
+ name: '[concat] Test building Concat with one input.',
+ inputs: [{dataType: 'float32', dimensions: [4,4,3]}],
+ axis: 2,
+ output: {dataType: 'float32', dimensions: [4,4,3]}
+ },
+ {
+ name: '[concat] Test building Concat with two inputs',
+ inputs: [{dataType: 'float32', dimensions: [3,1,5]},
+ {dataType: 'float32', dimensions: [3,2,5]}],
+ axis: 1,
+ output: {dataType: 'float32', dimensions: [3,3,5]}
+ },
+ {
+ name: '[concat] Test building Concat with three inputs',
+ inputs: [{dataType: 'float32', dimensions: [3,5,1]},
+ {dataType: 'float32', dimensions: [3,5,2]},
+ {dataType: 'float32', dimensions: [3,5,3]}],
+ axis: 2,
+ output: {dataType: 'float32', dimensions: [3,5,6]}
+ },
+ {
+ name: '[concat] Test building Concat with two 1D inputs.',
+ inputs: [{dataType: 'float32', dimensions: [1]},
+ {dataType: 'float32', dimensions: [1]}],
+ axis: 0,
+ output: {dataType: 'float32', dimensions: [2]}
+ },
+ {
+ name: '[concat] Throw if the inputs are empty.',
+ axis: 0,
+ },
+ {
+ name: '[concat] Throw if the argument types are inconsistent.',
+ inputs: [{dataType: 'float32', dimensions: [1,1]},
+ {dataType: 'int32', dimensions: [1,1]}],
+ axis: 0,
+ },
+ {
+ name: '[concat] Throw if the inputs have different ranks.',
+ inputs: [{dataType: 'float32', dimensions: [1,1]},
+ {dataType: 'float32', dimensions: [1,1,1]}],
+ axis: 0,
+ },
+ {
+ name: '[concat] Throw if the axis is equal to or greater than the size of ranks',
+ inputs: [{dataType: 'float32', dimensions: [1,1]},
+ {dataType: 'float32', dimensions: [1,1]}],
+ axis: 2,
+ },
+ {
+ name: '[concat] Throw if concat with two 0-D scalars.',
+ inputs: [{dataType: 'float32', dimensions: []},
+ {dataType: 'float32', dimensions: []}],
+ axis: 0,
+ },
+ {
+ name: '[concat] Throw if the inputs have other axes with different sizes except on the axis.',
+ inputs: [{dataType: 'float32', dimensions: [1,1,1]},
+ {dataType: 'float32', dimensions: [1,2,3]}],
+ axis: 1,
+ },
+
+];
+
+tests.forEach(test =>
+ promise_test(async t => {
+ let inputs = [];
+ if (test.inputs) {
+ for (let i = 0; i < test.inputs.length; ++i) {
+ inputs[i] = builder.input(
+ `inputs[${i}]`,
+ { dataType: test.inputs[i].dataType, dimensions: test.inputs[i].dimensions }
+ );
+ }
+ }
+ if (test.output) {
+ const output = builder.concat(inputs, test.axis);
+ assert_equals(output.dataType(), test.output.dataType);
+ assert_array_equals(output.shape(), test.output.dimensions);
+ } else {
+ assert_throws_js(TypeError, () => builder.concat(inputs, test.axis));
+ }
+ }, test.name)
+ );
\ No newline at end of file