diff options
author | Xusong Wang <xusongw@google.com> | 2020-04-24 14:46:28 -0700 |
---|---|---|
committer | Xusong Wang <xusongw@google.com> | 2020-04-28 16:16:46 -0700 |
commit | 7b9a944b1a21bde77b0af82a27b3c8daa09afc01 (patch) | |
tree | 67a636a08da69461315fd9958b022f5659c1b1a0 /nn/runtime/test/fuzzing | |
parent | 4771108bc09751db04c64971473dd4f4d5cebbf7 (diff) | |
download | ml-7b9a944b1a21bde77b0af82a27b3c8daa09afc01.tar.gz |
Add STRIDED_SLICE validations on neg stride with shrinkMask.
Fixes: 154639297
Test: NNT_static
Test: NNT_static_fuzzing
Change-Id: I2b37dd7fe07f3239682b5bc7f7cef0ae76134ad0
Diffstat (limited to 'nn/runtime/test/fuzzing')
-rw-r--r-- | nn/runtime/test/fuzzing/operation_signatures/Selection.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/nn/runtime/test/fuzzing/operation_signatures/Selection.cpp b/nn/runtime/test/fuzzing/operation_signatures/Selection.cpp index 6d45d0433..02612c0df 100644 --- a/nn/runtime/test/fuzzing/operation_signatures/Selection.cpp +++ b/nn/runtime/test/fuzzing/operation_signatures/Selection.cpp @@ -320,24 +320,23 @@ static void stridedSliceFinalizer(RandomOperation* op) { // arbitrary value. if (beginMask[i]) begin[i] = getUniform<int32_t>(-inputSize, inputSize - 1); if (endMask[i]) end[i] = getUniform<int32_t>(-inputSize, inputSize - 1); + + // Switch to negative stride. + if (getBernoulli(0.2f)) { + op->inputs[3]->value<int32_t>(i) = -stride; + std::swap(begin[i], end[i]); + std::swap(beginMask[i], endMask[i]); + begin[i]--; + end[i]--; + // end = -1 will be interpreted to inputSize - 1 if not setting endMask. + if (end[i] < 0) endMask[i] = true; + } } else { // When shrink mask is set, the begin and end must define a slice of size 1, e.g. // begin[i] = x, end[i] = x + 1. begin[i] = getUniform<int32_t>(0, inputSize - 1); end[i] = begin[i] + 1; } - - // Switch to negative stride. - // TODO(b/154639297): shrinkMask with negative stride will produce uninitialized output. - if (!shrink && getBernoulli(0.2f)) { - op->inputs[3]->value<int32_t>(i) = -stride; - std::swap(begin[i], end[i]); - std::swap(beginMask[i], endMask[i]); - begin[i]--; - end[i]--; - // end = -1 will be intepreted to inputSize - 1 if not setting endMask. - if (end[i] < 0) endMask[i] = true; - } } op->inputs[4]->setScalarValue<int32_t>(convertToBitMask(beginMask)); op->inputs[5]->setScalarValue<int32_t>(convertToBitMask(endMask)); |