intel / webml-polyfill

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

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

Open canxcao opened 6 years ago

canxcao commented 6 years ago

Test Env: Chromium Version : nightly build 65.0.3324.0 (revision f9e1a31) OS : Android 8.1.0;Pixel 2

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():

TENSOR_FLOAT32 type: no "dimensions" TENSOR_INT32 type: no "dimensions" TENSOR_QUANT8_ASYMM type: no "dimensions" TENSOR_QUANT8_ASYMM type: no "scale" TENSOR_QUANT8_ASYMM type: no "zeroPoint" TENSOR_QUANT8_ASYMM type: no "scale" and "zeroPoint" TENSOR_QUANT8_ASYMM type: "zeroPoint" < 0 TENSOR_QUANT8_ASYMM type: "zeroPoint" > 255 TENSOR_QUANT8_ASYMM type: "scale" is negative addOperand() only requires one argument, passing two arguments should raise an error: two scalars or two tensors 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});
    });
  });
});
Christywl commented 5 years ago

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

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