tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

input.https.any.js (2413B)


      1 // META: title=validation tests for WebNN API input interface
      2 // META: global=window,worker
      3 // META: variant=?cpu
      4 // META: variant=?gpu
      5 // META: variant=?npu
      6 // META: script=../resources/utils_validation.js
      7 
      8 'use strict';
      9 
     10 // Tests for input(name, descriptor)
     11 const tests = [
     12  {
     13    testName: '[input] Test building a 0-D scalar input with empty shape',
     14    name: 'input',
     15    descriptor: {dataType: 'float32', shape: []},
     16    output: {dataType: 'float32', shape: []},
     17  },
     18  {
     19    testName: '[input] Test building a 1-D input with int64 data type',
     20    name: 'input',
     21    descriptor: {dataType: 'int64', shape: [3]},
     22    output: {dataType: 'int64', shape: [3]},
     23  },
     24  {
     25    testName: '[input] Test building a 2-D input without errors',
     26    name: 'input',
     27    descriptor: {dataType: 'float32', shape: [3, 4]},
     28    output: {dataType: 'float32', shape: [3, 4]},
     29  },
     30  {
     31    testName: '[input] Throw if the name is empty',
     32    name: '',
     33    descriptor: {dataType: 'float32', shape: [3, 4]}
     34  },
     35  {
     36    testName: '[input] Throw if a dimension size is 0',
     37    name: 'input',
     38    descriptor: {dataType: 'float32', shape: [3, 0]}
     39  },
     40  {
     41    testName:
     42        '[input] Throw if the value of any element in dimensions is outside the \'unsigned long\' value range',
     43    name: 'input',
     44    descriptor: {dataType: 'float32', shape: [kMaxUnsignedLong + 1]}
     45  },
     46  {
     47    testName: '[input] Throw if the number of elements is too large',
     48    name: 'input',
     49    descriptor: {
     50      dataType: 'float32',
     51      shape: [kMaxUnsignedLong, kMaxUnsignedLong, kMaxUnsignedLong]
     52    }
     53  }
     54 ];
     55 
     56 tests.forEach(
     57    test => promise_test(async t => {
     58      const builder = new MLGraphBuilder(context);
     59      if (test.output) {
     60        const inputOperand = builder.input(test.name, test.descriptor);
     61        assert_equals(inputOperand.dataType, test.output.dataType);
     62        assert_array_equals(inputOperand.shape, test.output.shape);
     63      } else {
     64        assert_throws_js(
     65            TypeError, () => builder.input(test.name, test.descriptor));
     66      }
     67    }, test.testName));
     68 
     69 promise_test(async t => {
     70  const builder = new MLGraphBuilder(context);
     71 
     72  const inputDescriptor = {
     73      dataType: 'float32',
     74      shape: [(context.opSupportLimits().maxTensorByteLength + 1) / 4]};
     75 
     76  assert_throws_js(
     77    TypeError, () => builder.input('input', inputDescriptor));
     78 }, '[input] throw if the output tensor byte length exceeds limit');