intel / webml-polyfill

Deprecated, the Web Neural Network Polyfill project has been moved to https://github.com/webmachinelearning/webnn-polyfill
Apache License 2.0
160 stars 42 forks source link

[webml/MPS] No exception is thrown when passing an invalid argument to addOperand() #66

Closed Christywl closed 5 years ago

Christywl commented 6 years ago

Test Env: Chromium Version : nightly build 65.0.3324.0 (revision f9e1a31) OS : Mac OS X 10.13.4

Expected Result: Pass an invalid argument to addOperand(), it should throw an exception

Actual Result: No exception is thrown when passing an invalid argument to addOperand()

How to reproduce: Pass the following invalid arguments to addOperand():

For example: 1.TENSOR_FLOAT32 type: no "dimensions":

it('raise error when passing a TENSOR_FLOAT32 tensor not having "dimensions" option', function() {
  return nn.createModel(options).then((model)=>{
    assert.throws(() => {
      model.addOperand({type: nn.TENSOR_FLOAT32});
    });
  });
});

2.addOperand() only requires one argument, passing two arguments should raise an error: pass two scalars

it('raise error when passing two scalars', function() {
  return nn.createModel(options).then((model)=>{
    assert.throws(() => {
      model.addOperand({type: nn.INT32}, {type: nn.INT32});
    });
  });
});
sunlin-link commented 6 years ago

Should add more check for the details of operand based on Android NN API

sunlin-link commented 5 years ago

@Christywl Fixed. Please verify

Christywl commented 5 years ago

@sunlin-link , I tried the chromium nightly build 313c1c2, most negative tests passed except for the following case:

Steps: Run https://brucedai.github.io/nt/testm/index-local.html?backend=mps, check the tests in #addOperand API:

fujunwei commented 5 years ago

The SyntaxError is thrown while the code is being parsed and not while it's running. you can use window.onerror and figure out that there's an error.

<script>
  window.onerror = function (e) {
    console.log('Error: ', e);
  };
</script>
BruceDai commented 5 years ago

@fujunwei About "addOperand() only requires one argument, passing two arguments should raise an error....", we find it doesn't throw any error, so we couldn't catch it by test case. Please help to handle this exception to throw error, thanks

fujunwei commented 5 years ago

It's not a issue for javascript, remaining parameters will be ignored but don't raise a error, for example

<textarea id="textarea" rows=100 cols=100></textarea>
var textarea = document.getElementById("textarea", "normal");

but var textarea will be null if the first parameter is not found

<textarea id="textarea" rows=100 cols=100></textarea>
var textarea = document.getElementById("notFound", "textarea");