diff options
author | Xusong Wang <xusongw@google.com> | 2020-03-30 10:07:10 -0700 |
---|---|---|
committer | Xusong Wang <xusongw@google.com> | 2020-03-30 15:27:57 -0700 |
commit | 139e82ccf51f563944548c786157b10d7409ba5b (patch) | |
tree | dfa9490ebac08087b9aa78d4ce3f6d391f99438f /nn/runtime/test/specs | |
parent | bc3b1e4bab6f55665ab0410b8e3d915c0025b5d9 (diff) | |
download | ml-139e82ccf51f563944548c786157b10d7409ba5b.tar.gz |
Add tests of DIV by zero.
Added tests of DIV by zero. The tests exercise DIV by zero of all
supported data types in CTS/VTS and only expect runtime/drivers to not
crash.
Updated the reference implementation of INT32 DIV. Before this CL, the
reference implementation will crash with floating point exception. This
CL forces INT DIV by zero to return 0.
Fixes: 151151830
Test: NNT_static
Change-Id: I49f39c6ed41bab5d368498b37909de6a1c808d1e
Diffstat (limited to 'nn/runtime/test/specs')
-rw-r--r-- | nn/runtime/test/specs/V1_1/div.mod.py | 13 | ||||
-rw-r--r-- | nn/runtime/test/specs/V1_2/div_v1_2.mod.py | 13 | ||||
-rw-r--r-- | nn/runtime/test/specs/V1_3/div_int32.mod.py | 13 |
3 files changed, 39 insertions, 0 deletions
diff --git a/nn/runtime/test/specs/V1_1/div.mod.py b/nn/runtime/test/specs/V1_1/div.mod.py index e012f79f0..1c9fd6c69 100644 --- a/nn/runtime/test/specs/V1_1/div.mod.py +++ b/nn/runtime/test/specs/V1_1/div.mod.py @@ -17,3 +17,16 @@ output0 = {i3: # output 0 # Instantiate an example Example((input0, output0)) + + +# Test DIV by zero. +# It is undefined behavior. The output is ignored and we only require the drivers to not crash. +input0 = Input("input0", "TENSOR_FLOAT32", "{1}") +input1 = Input("input1", "TENSOR_FLOAT32", "{1}") +output = IgnoredOutput("output", "TENSOR_FLOAT32", "{1}") +model = Model("by_zero").Operation("DIV", input0, input1, 0).To(output) +Example({ + input0: [1], + input1: [0], + output: [0], +}).AddVariations("relaxed") diff --git a/nn/runtime/test/specs/V1_2/div_v1_2.mod.py b/nn/runtime/test/specs/V1_2/div_v1_2.mod.py index 84cf3beff..82ea3ba62 100644 --- a/nn/runtime/test/specs/V1_2/div_v1_2.mod.py +++ b/nn/runtime/test/specs/V1_2/div_v1_2.mod.py @@ -85,3 +85,16 @@ Example({ o2: [], o3: [], }).AddVariations("relaxed", "float16") + + +# TEST 4: DIV by zero. +# It is undefined behavior. The output is ignored and we only require the drivers to not crash. +input0 = Input("input0", "TENSOR_FLOAT16", "{1}") +input1 = Input("input1", "TENSOR_FLOAT16", "{1}") +output = IgnoredOutput("output", "TENSOR_FLOAT16", "{1}") +model = Model("by_zero").Operation("DIV", input0, input1, 0).To(output) +Example({ + input0: [1], + input1: [0], + output: [0], +}) diff --git a/nn/runtime/test/specs/V1_3/div_int32.mod.py b/nn/runtime/test/specs/V1_3/div_int32.mod.py index d378f5973..d3642f3e0 100644 --- a/nn/runtime/test/specs/V1_3/div_int32.mod.py +++ b/nn/runtime/test/specs/V1_3/div_int32.mod.py @@ -74,3 +74,16 @@ Example({ -3, -5, -9, 9, 4, 3, ], }) + + +# Test DIV by zero. +# It is undefined behavior. The output is ignored and we only require the drivers to not crash. +input0 = Input("input0", "TENSOR_INT32", "{1}") +input1 = Input("input1", "TENSOR_INT32", "{1}") +output = IgnoredOutput("output", "TENSOR_INT32", "{1}") +model = Model("by_zero").Operation("DIV", input0, input1, 0).To(output) +Example({ + input0: [1], + input1: [0], + output: [0], +}) |