diff --git a/testing/web-platform/tests/webnn/resources/utils_validation.js b/testing/web-platform/tests/webnn/resources/utils_validation.js index 188951964466a..856eea6cb3fc1 100644 --- a/testing/web-platform/tests/webnn/resources/utils_validation.js +++ b/testing/web-platform/tests/webnn/resources/utils_validation.js @@ -218,7 +218,7 @@ function assert_throws_with_label(func, regrexp) { } } -function validateTwoInputsBroadcastable(operationName, label, regrexp) { +function validateTwoInputsBroadcastable(operationName, label) { if (navigator.ml === undefined) { return; } @@ -240,6 +240,7 @@ function validateTwoInputsBroadcastable(operationName, label, regrexp) { const inputB = builder.input(`inputB${++inputBIndex}`, {dataType, dimensions: unbroadcastableDimensions}); assert_equals(typeof builder[operationName], 'function'); const options = {label}; + const regrexp = new RegExp('\\[' + label + '\\]'); assert_throws_with_label( () => builder[operationName](inputA, inputB, options), regrexp); assert_throws_with_label( @@ -251,7 +252,7 @@ function validateTwoInputsBroadcastable(operationName, label, regrexp) { }, `[${operationName}] TypeError is expected if two inputs aren't broadcastable`); } -function validateTwoInputsOfSameDataType(operationName, label, regrexp) { +function validateTwoInputsOfSameDataType(operationName, label) { if (navigator.ml === undefined) { return; } @@ -288,6 +289,7 @@ function validateTwoInputsOfSameDataType(operationName, label, regrexp) { if (dataType !== dataTypeB) { const inputB = builder.input(`inputB${++inputBIndex}`, {dataType: dataTypeB, dimensions}); const options = {label}; + const regrexp = new RegExp('\\[' + label + '\\]'); assert_equals(typeof builder[subOperationName], 'function'); assert_throws_with_label( () => builder[subOperationName](inputA, inputB, options), @@ -423,8 +425,7 @@ function validateOptionsAxes(operationName) { * @param {Array} supportedDataTypes - Test building with these data types * succeeds and test building with all other data types fails */ -function validateUnaryOperation( - operationName, supportedDataTypes, label, regrexp) { +function validateUnaryOperation(operationName, supportedDataTypes, label) { promise_test(async t => { const builder = new MLGraphBuilder(context); for (let dataType of supportedDataTypes) { @@ -461,6 +462,7 @@ function validateUnaryOperation( const input = builder.input(`input`, {dataType, dimensions}); assert_equals(typeof builder[operationName], 'function'); const options = {label}; + const regrexp = new RegExp('\\[' + label + '\\]'); assert_throws_with_label( () => builder[operationName](input, options), regrexp); } @@ -472,7 +474,7 @@ function validateUnaryOperation( * Validate a single input operation * @param {String} operationName - An operation name */ -function validateSingleInputOperation(operationName, label, regrexp) { +function validateSingleInputOperation(operationName, label) { promise_test(async t => { const builder = new MLGraphBuilder(context); const supportedDataTypes = @@ -508,6 +510,7 @@ function validateSingleInputOperation(operationName, label, regrexp) { const input = builder.input(`input`, {dataType, dimensions}); assert_equals(typeof builder[operationName], 'function'); const options = {label}; + const regrexp = new RegExp('\\[' + label + '\\]'); assert_throws_with_label( () => builder[operationName](input, options), regrexp); } diff --git a/testing/web-platform/tests/webnn/validation_tests/clamp.https.any.js b/testing/web-platform/tests/webnn/validation_tests/clamp.https.any.js index 4526db3451229..8302961e2c481 100644 --- a/testing/web-platform/tests/webnn/validation_tests/clamp.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/clamp.https.any.js @@ -9,7 +9,9 @@ validateInputFromAnotherBuilder('clamp'); -validateUnaryOperation('clamp', allWebNNOperandDataTypes); +const label = '123_clamp'; + +validateUnaryOperation('clamp', allWebNNOperandDataTypes, label); promise_test(async t => { const builder = new MLGraphBuilder(context); @@ -45,7 +47,6 @@ promise_test(async t => { assert_array_equals(output.shape(), [1, 2, 3, 4]); }, '[clamp] Build with options.minValue == options.maxValue'); -const label = '123_clamp'; promise_test(async t => { const builder = new MLGraphBuilder(context); const options = { diff --git a/testing/web-platform/tests/webnn/validation_tests/elementwise-binary.https.any.js b/testing/web-platform/tests/webnn/validation_tests/elementwise-binary.https.any.js index 810f671cec023..fc0616f569b39 100644 --- a/testing/web-platform/tests/webnn/validation_tests/elementwise-binary.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/elementwise-binary.https.any.js @@ -95,8 +95,8 @@ function runElementWiseBinaryTests(operatorName, tests) { } kElementwiseBinaryOperators.forEach((operatorName) => { - validateTwoInputsOfSameDataType(operatorName, label, regrexp); - validateTwoInputsBroadcastable(operatorName, label, regrexp); + validateTwoInputsOfSameDataType(operatorName, label); + validateTwoInputsBroadcastable(operatorName, label); validateTwoInputsFromMultipleBuilders(operatorName); runElementWiseBinaryTests(operatorName, tests); }); diff --git a/testing/web-platform/tests/webnn/validation_tests/elementwise-logical.https.any.js b/testing/web-platform/tests/webnn/validation_tests/elementwise-logical.https.any.js index e154f515fbdfc..bada9e7648b1e 100644 --- a/testing/web-platform/tests/webnn/validation_tests/elementwise-logical.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/elementwise-logical.https.any.js @@ -16,12 +16,11 @@ const kElementwiseLogicalBinaryOperators = [ ]; const label = 'elementwise_logic_op'; -const regrexp = new RegExp('\\[' + label + '\\]'); kElementwiseLogicalBinaryOperators.forEach((operatorName) => { - validateTwoInputsOfSameDataType(operatorName, label, regrexp); + validateTwoInputsOfSameDataType(operatorName, label); validateTwoInputsFromMultipleBuilders(operatorName); - validateTwoInputsBroadcastable(operatorName, label, regrexp); + validateTwoInputsBroadcastable(operatorName, label); }); // The `logicalNot()` operator is unary. diff --git a/testing/web-platform/tests/webnn/validation_tests/elementwise-unary.https.any.js b/testing/web-platform/tests/webnn/validation_tests/elementwise-unary.https.any.js index e3efe2e9caf05..5de8cb19c9ec7 100644 --- a/testing/web-platform/tests/webnn/validation_tests/elementwise-unary.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/elementwise-unary.https.any.js @@ -17,7 +17,6 @@ kElementwiseUnaryOperators.forEach((operatorName) => { }); const label = 'elementwise_unary_op'; -const regrexp = new RegExp('\\[' + label + '\\]'); kElementwiseUnaryOperators.forEach((operatorName) => { - validateSingleInputOperation(operatorName, label, regrexp); + validateSingleInputOperation(operatorName, label); }); diff --git a/testing/web-platform/tests/webnn/validation_tests/elu.https.any.js b/testing/web-platform/tests/webnn/validation_tests/elu.https.any.js index 011065aa46f55..4236925aed188 100644 --- a/testing/web-platform/tests/webnn/validation_tests/elu.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/elu.https.any.js @@ -9,11 +9,11 @@ validateInputFromAnotherBuilder('elu'); -validateSingleInputOperation('elu'); - const label = 'elu_xxx'; const regrexp = new RegExp('\\[' + label + '\\]'); +validateSingleInputOperation('elu', label); + promise_test(async t => { const builder = new MLGraphBuilder(context); const options = {alpha: 1.0}; diff --git a/testing/web-platform/tests/webnn/validation_tests/hardSigmoid.https.any.js b/testing/web-platform/tests/webnn/validation_tests/hardSigmoid.https.any.js index de8ed3e2a18bc..b0104dfc2c272 100644 --- a/testing/web-platform/tests/webnn/validation_tests/hardSigmoid.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/hardSigmoid.https.any.js @@ -9,7 +9,9 @@ validateInputFromAnotherBuilder('hardSigmoid'); -validateUnaryOperation('hardSigmoid', floatingPointTypes); +const label = 'hard_sigmoid'; + +validateUnaryOperation('hardSigmoid', floatingPointTypes, label); promise_test(async t => { const builder = new MLGraphBuilder(context); diff --git a/testing/web-platform/tests/webnn/validation_tests/hardSwish.https.any.js b/testing/web-platform/tests/webnn/validation_tests/hardSwish.https.any.js index 0dc20ac579109..53c78c8c81df2 100644 --- a/testing/web-platform/tests/webnn/validation_tests/hardSwish.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/hardSwish.https.any.js @@ -10,5 +10,4 @@ validateInputFromAnotherBuilder('hardSwish'); const label = 'hard_swish'; -const regrexp = new RegExp('\\[' + label + '\\]'); -validateUnaryOperation('hardSwish', floatingPointTypes, label, regrexp); +validateUnaryOperation('hardSwish', floatingPointTypes, label); diff --git a/testing/web-platform/tests/webnn/validation_tests/leakyRelu.https.any.js b/testing/web-platform/tests/webnn/validation_tests/leakyRelu.https.any.js index d70ce65edcac3..6766763cd749a 100644 --- a/testing/web-platform/tests/webnn/validation_tests/leakyRelu.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/leakyRelu.https.any.js @@ -9,7 +9,8 @@ validateInputFromAnotherBuilder('leakyRelu'); -validateSingleInputOperation('leakyRelu'); +const label = 'leaky_relu'; +validateSingleInputOperation('leakyRelu', label); promise_test(async t => { const builder = new MLGraphBuilder(context); diff --git a/testing/web-platform/tests/webnn/validation_tests/linear.https.any.js b/testing/web-platform/tests/webnn/validation_tests/linear.https.any.js index 05c2b8061189f..936843374b992 100644 --- a/testing/web-platform/tests/webnn/validation_tests/linear.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/linear.https.any.js @@ -9,7 +9,8 @@ validateInputFromAnotherBuilder('linear'); -validateUnaryOperation('linear', floatingPointTypes); +const label = 'linear_xxx'; +validateUnaryOperation('linear', floatingPointTypes, label); promise_test(async t => { const builder = new MLGraphBuilder(context); diff --git a/testing/web-platform/tests/webnn/validation_tests/relu.https.any.js b/testing/web-platform/tests/webnn/validation_tests/relu.https.any.js index f059275e26ab4..7bd61fe413b2a 100644 --- a/testing/web-platform/tests/webnn/validation_tests/relu.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/relu.https.any.js @@ -10,5 +10,4 @@ validateInputFromAnotherBuilder('relu'); const label = 'relu_1'; -const regrexp = new RegExp('\\[' + label + '\\]'); -validateSingleInputOperation('relu', label, regrexp); +validateSingleInputOperation('relu', label); diff --git a/testing/web-platform/tests/webnn/validation_tests/sigmoid.https.any.js b/testing/web-platform/tests/webnn/validation_tests/sigmoid.https.any.js index 565008d34ae16..271bef2111690 100644 --- a/testing/web-platform/tests/webnn/validation_tests/sigmoid.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/sigmoid.https.any.js @@ -10,5 +10,4 @@ validateInputFromAnotherBuilder('sigmoid'); const label = 'sigmoid_xxx'; -const regrexp = new RegExp('\\[' + label + '\\]'); -validateSingleInputOperation('sigmoid', label, regrexp); +validateSingleInputOperation('sigmoid', label); diff --git a/testing/web-platform/tests/webnn/validation_tests/softplus.https.any.js b/testing/web-platform/tests/webnn/validation_tests/softplus.https.any.js index 0526bfa0055bf..72049573a48f1 100644 --- a/testing/web-platform/tests/webnn/validation_tests/softplus.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/softplus.https.any.js @@ -10,5 +10,4 @@ validateInputFromAnotherBuilder('softplus'); const label = 'softplus_xxx'; -const regrexp = new RegExp('\\[' + label + '\\]'); -validateSingleInputOperation('softplus', label, regrexp); +validateSingleInputOperation('softplus', label); diff --git a/testing/web-platform/tests/webnn/validation_tests/softsign.https.any.js b/testing/web-platform/tests/webnn/validation_tests/softsign.https.any.js index 00eb0c7db7a51..59a0199a3fb75 100644 --- a/testing/web-platform/tests/webnn/validation_tests/softsign.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/softsign.https.any.js @@ -10,5 +10,4 @@ validateInputFromAnotherBuilder('softsign'); const label = 'softsign_xxx'; -const regrexp = new RegExp('\\[' + label + '\\]'); -validateSingleInputOperation('softsign', label, regrexp); +validateSingleInputOperation('softsign', label); diff --git a/testing/web-platform/tests/webnn/validation_tests/tanh.https.any.js b/testing/web-platform/tests/webnn/validation_tests/tanh.https.any.js index 96c49e5e05995..b7ddf461c5215 100644 --- a/testing/web-platform/tests/webnn/validation_tests/tanh.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/tanh.https.any.js @@ -10,5 +10,4 @@ validateInputFromAnotherBuilder('tanh'); const label = 'tanh-xxx'; -const regrexp = new RegExp('\\[' + label + '\\]'); -validateUnaryOperation('tanh', floatingPointTypes, label, regrexp); +validateUnaryOperation('tanh', floatingPointTypes, label);