I8PrepareA.js (2757B)
1 // This file contains all the tests for int8_prepare_a intrinsic. It depends 2 // on the CommonTestSetup.js script which contains the common functionality 3 // that is required for testing all the intrinsics. 4 const COMMON_TEST_SETUP_SCRIPT = "./CommonTestSetup.js" 5 6 // All tests for this intrinsic as a string 7 const ALL_TESTS_AS_STRING =` 8 let {int8_prepare_a} = instance.exports; 9 10 const VALID = {input: 0, scale: 1.0, zeroPoint: 0.0, rows: ROWS_A_MULTIPLIER, cols: COLUMNS_A_MULTIPLIER, output: ARRAY_ALIGNMENT << 5}; 11 12 function testInvalidSize() { 13 let invalidSize; 14 15 // row: 0 16 invalidSize = 0; 17 assertErrorMessage(() => int8_prepare_a(VALID.input, VALID.scale, VALID.zeroPoint, invalidSize, VALID.cols, VALID.output), WebAssembly.RuntimeError, /unreachable/); 18 19 // col: 0 20 invalidSize = 0; 21 assertErrorMessage(() => int8_prepare_a(VALID.input, VALID.scale, VALID.zeroPoint, VALID.rows, invalidSize, VALID.output), WebAssembly.RuntimeError, /unreachable/); 22 23 // col: Not an integral multiple of COLUMNS_A_MULTIPLIER 24 invalidSize = COLUMNS_A_MULTIPLIER + 1; 25 assertErrorMessage(() => int8_prepare_a(VALID.input, VALID.scale, VALID.zeroPoint, VALID.rows, invalidSize, VALID.output), WebAssembly.RuntimeError, /unreachable/); 26 } 27 28 function testInvalidAlignment() { 29 let invalidAlignment = ARRAY_ALIGNMENT + 1; 30 31 // input: Not an integral multiple of ARRAY_ALIGNMENT 32 assertErrorMessage(() => int8_prepare_a(invalidAlignment, VALID.scale, VALID.zeroPoint, VALID.rows, VALID.cols, VALID.output), WebAssembly.RuntimeError, /index out of bounds/); 33 34 // output: Not an integral multiple of ARRAY_ALIGNMENT 35 assertErrorMessage(() => int8_prepare_a(VALID.input, VALID.scale, VALID.zeroPoint, VALID.rows, VALID.cols, invalidAlignment), WebAssembly.RuntimeError, /index out of bounds/); 36 } 37 38 function testOutOfBounds() { 39 let outOfBound = PageSizeInBytes - ARRAY_ALIGNMENT; 40 41 // input: Out of Bounds 42 assertErrorMessage(() => int8_prepare_a(outOfBound, VALID.scale, VALID.zeroPoint, VALID.rows, VALID.cols, VALID.output), WebAssembly.RuntimeError, /index out of bounds/); 43 44 // output: Out of Bounds 45 assertErrorMessage(() => int8_prepare_a(VALID.input, VALID.scale, VALID.zeroPoint, VALID.rows, VALID.cols, outOfBound), WebAssembly.RuntimeError, /index out of bounds/); 46 } 47 48 function testSuccessfulCall() { 49 // We just test that with valid arguments the intrinsic executes without any error 50 int8_prepare_a(VALID.input, VALID.scale, VALID.zeroPoint, VALID.rows, VALID.cols, VALID.output); 51 } 52 53 testInvalidSize(); 54 testInvalidAlignment(); 55 testOutOfBounds(); 56 testSuccessfulCall(); 57 ` 58 59 // Run all the tests 60 import(COMMON_TEST_SETUP_SCRIPT).then((importedModule) => { 61 importedModule.runTest(importedModule.COMMON_TEST_SETUP_AS_STRING + ALL_TESTS_AS_STRING); 62 });