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 an argument passed to setOperandValue() is incompatible with the type expected #81

Closed canxcao closed 5 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:

Actual Result: No exception is thrown when an argument passed to setOperandValue() is incompatible with the type expected

How to reproduce: Set the following incompatible value:

    an Int8Array data
    an Uint8ClampedArray data
    an Int16Array data
    an Uint16Array data
    a Float64Array data
    a DataView data
    an Int8Array data
    an Uint8ClampedArray data
    an Int16Array data
    an Uint16Array data
    a Float64Array data
    a DataView data

For example:

  1. set an Int8Array data for a FLOAT32 scalar
it('raise error when setting an Int8Array data for a FLOAT32 scalar', function() {
  return nn.createModel(options).then((model)=>{
    model.addOperand({type: nn.FLOAT32});
    assert.throws(() => {
      model.setOperandValue(0, new Int8Array([0]));
    });
  });
});
  1. set a Float32Array data which length > 1 for a FLOAT32 scalar
it('raise error when setting a Float32Array data which length > 1 for a FLOAT32 scalar', function() {
  return nn.createModel(options).then((model)=>{
    model.addOperand({type: nn.FLOAT32});
    assert.throws(() => {
      model.setOperandValue(0, new Float32Array([0, 0]));
    });
  });
});
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/testa/index-local.html?backend=nnapi, check the tests in #setOperandValue API:

Christywl commented 5 years ago

This issue was fixed on nightly build 8e6c6d1.