summaryrefslogtreecommitdiff
path: root/nn
diff options
context:
space:
mode:
authorSlava Shklyaev <slavash@google.com>2020-02-18 15:56:51 +0000
committerSlava Shklyaev <slavash@google.com>2020-02-18 22:38:58 +0000
commitd5b4cbd3afc6d86a4415fdbbb15661180064099c (patch)
treec1bd9092e66afe842900cf1b6f902f1d74fb5179 /nn
parent64ffe91670d39eca7e072e07d258a6337c3b3b1b (diff)
downloadml-d5b4cbd3afc6d86a4415fdbbb15661180064099c.tar.gz
Add generated infinite loop test
See change I642772d3. Bug: 149554639 Bug: 145906499 Bug: 136735929 Test: m Change-Id: Ibc92e97fabd57e38de22e1397677fdf8aba6bb95
Diffstat (limited to 'nn')
-rw-r--r--nn/runtime/test/TestGenerated.cpp5
-rw-r--r--nn/runtime/test/generated/spec_V1_3/while_infinite_loop.example.cpp181
-rw-r--r--nn/runtime/test/specs/V1_3/while_infinite_loop.mod.py57
-rw-r--r--nn/tools/test_generator/test_harness/include/TestHarness.h5
4 files changed, 246 insertions, 2 deletions
diff --git a/nn/runtime/test/TestGenerated.cpp b/nn/runtime/test/TestGenerated.cpp
index da1094cc2..bcb3193c6 100644
--- a/nn/runtime/test/TestGenerated.cpp
+++ b/nn/runtime/test/TestGenerated.cpp
@@ -550,8 +550,9 @@ INSTANTIATE_GENERATED_TEST(DynamicOutputShapeTest, [](const TestModel& testModel
return !testModel.expectFailure && !testModel.hasScalarOutputs();
});
-INSTANTIATE_GENERATED_TEST(GeneratedValidationTests,
- [](const TestModel& testModel) { return testModel.expectFailure; });
+INSTANTIATE_GENERATED_TEST(GeneratedValidationTests, [](const TestModel& testModel) {
+ return testModel.expectFailure && !testModel.isInfiniteLoopTimeoutTest();
+});
INSTANTIATE_GENERATED_TEST(QuantizationCouplingTest, [](const TestModel& testModel) {
return testModel.main.operations.size() == 1 && testModel.referenced.size() == 0 &&
diff --git a/nn/runtime/test/generated/spec_V1_3/while_infinite_loop.example.cpp b/nn/runtime/test/generated/spec_V1_3/while_infinite_loop.example.cpp
new file mode 100644
index 000000000..5bab38497
--- /dev/null
+++ b/nn/runtime/test/generated/spec_V1_3/while_infinite_loop.example.cpp
@@ -0,0 +1,181 @@
+// Generated from while_infinite_loop.mod.py
+// DO NOT EDIT
+// clang-format off
+#include "TestHarness.h"
+using namespace test_helper;
+
+namespace generated_tests::while_infinite_loop {
+
+const TestModel& get_test_model() {
+ static TestModel model = {
+ .expectFailure = true,
+ .expectedMultinomialDistributionTolerance = 0,
+ .isRelaxed = false,
+ .main = {
+ .inputIndexes = {3},
+ .operands = {{
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<uint32_t>({0}),
+ .dimensions = {},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::SUBGRAPH,
+ .numberOfConsumers = 1,
+ .scale = 0.0f,
+ .type = TestOperandType::SUBGRAPH,
+ .zeroPoint = 0
+ }, {
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<uint32_t>({1}),
+ .dimensions = {},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::SUBGRAPH,
+ .numberOfConsumers = 1,
+ .scale = 0.0f,
+ .type = TestOperandType::SUBGRAPH,
+ .zeroPoint = 0
+ }, {
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<float>({1.0f}),
+ .dimensions = {1},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::CONSTANT_COPY,
+ .numberOfConsumers = 1,
+ .scale = 0.0f,
+ .type = TestOperandType::TENSOR_FLOAT32,
+ .zeroPoint = 0
+ }, {
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<float>({0.0f}),
+ .dimensions = {1},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT,
+ .numberOfConsumers = 1,
+ .scale = 0.0f,
+ .type = TestOperandType::TENSOR_FLOAT32,
+ .zeroPoint = 0
+ }, {
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<float>({999.9f}),
+ .dimensions = {1},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT,
+ .numberOfConsumers = 0,
+ .scale = 0.0f,
+ .type = TestOperandType::TENSOR_FLOAT32,
+ .zeroPoint = 0
+ }},
+ .operations = {{
+ .inputs = {0, 1, 2, 3},
+ .outputs = {4},
+ .type = TestOperationType::WHILE
+ }},
+ .outputIndexes = {4}
+ },
+ .minSupportedVersion = TestHalVersion::V1_3,
+ .referenced = {{
+ .inputIndexes = {0, 1},
+ .operands = {{
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<float>({}),
+ .dimensions = {1},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT,
+ .numberOfConsumers = 1,
+ .scale = 0.0f,
+ .type = TestOperandType::TENSOR_FLOAT32,
+ .zeroPoint = 0
+ }, {
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<float>({}),
+ .dimensions = {1},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT,
+ .numberOfConsumers = 1,
+ .scale = 0.0f,
+ .type = TestOperandType::TENSOR_FLOAT32,
+ .zeroPoint = 0
+ }, {
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<bool8>({}),
+ .dimensions = {1},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT,
+ .numberOfConsumers = 0,
+ .scale = 0.0f,
+ .type = TestOperandType::TENSOR_BOOL8,
+ .zeroPoint = 0
+ }},
+ .operations = {{
+ .inputs = {0, 1},
+ .outputs = {2},
+ .type = TestOperationType::GREATER_EQUAL
+ }},
+ .outputIndexes = {2}
+ }, {
+ .inputIndexes = {0, 1},
+ .operands = {{
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<float>({}),
+ .dimensions = {1},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT,
+ .numberOfConsumers = 1,
+ .scale = 0.0f,
+ .type = TestOperandType::TENSOR_FLOAT32,
+ .zeroPoint = 0
+ }, {
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<float>({}),
+ .dimensions = {1},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT,
+ .numberOfConsumers = 0,
+ .scale = 0.0f,
+ .type = TestOperandType::TENSOR_FLOAT32,
+ .zeroPoint = 0
+ }, {
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<float>({}),
+ .dimensions = {1},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT,
+ .numberOfConsumers = 0,
+ .scale = 0.0f,
+ .type = TestOperandType::TENSOR_FLOAT32,
+ .zeroPoint = 0
+ }, {
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<float>({1.0f}),
+ .dimensions = {1},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::CONSTANT_COPY,
+ .numberOfConsumers = 1,
+ .scale = 0.0f,
+ .type = TestOperandType::TENSOR_FLOAT32,
+ .zeroPoint = 0
+ }, {
+ .channelQuant = {},
+ .data = TestBuffer::createFromVector<int32_t>({0}),
+ .dimensions = {},
+ .isIgnored = false,
+ .lifetime = TestOperandLifeTime::CONSTANT_COPY,
+ .numberOfConsumers = 1,
+ .scale = 0.0f,
+ .type = TestOperandType::INT32,
+ .zeroPoint = 0
+ }},
+ .operations = {{
+ .inputs = {0, 3, 4},
+ .outputs = {2},
+ .type = TestOperationType::ADD
+ }},
+ .outputIndexes = {2}
+ }}
+ };
+ return model;
+}
+
+const auto dummy_test_model = TestModelManager::get().add("while_infinite_loop", get_test_model());
+
+} // namespace generated_tests::while_infinite_loop
+
diff --git a/nn/runtime/test/specs/V1_3/while_infinite_loop.mod.py b/nn/runtime/test/specs/V1_3/while_infinite_loop.mod.py
new file mode 100644
index 000000000..e322123c4
--- /dev/null
+++ b/nn/runtime/test/specs/V1_3/while_infinite_loop.mod.py
@@ -0,0 +1,57 @@
+#
+# Copyright (C) 2020 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Model: given n <= 1.0, never returns.
+# Expected result: execution aborted after a timeout.
+#
+# i = 1.0
+# while i >= n:
+# i = i + 1.0
+
+CounterType = ["TENSOR_FLOAT32", "{1}"]
+BoolType = ["TENSOR_BOOL8", "{1}"]
+
+def MakeConditionModel():
+ i = Input("i", CounterType)
+ n = Input("n", CounterType)
+ out = Output("out", BoolType)
+ model = Model()
+ model.IdentifyInputs(i, n)
+ model.IdentifyOutputs(out)
+ model.Operation("GREATER_EQUAL", i, n).To(out)
+ return model
+
+def MakeBodyModel():
+ i = Input("i", CounterType)
+ n = Input("n", CounterType)
+ i_out = Output("i_out", CounterType)
+ model = Model()
+ model.IdentifyInputs(i, n)
+ model.IdentifyOutputs(i_out)
+ model.Operation("ADD", i, [1.0], 0).To(i_out)
+ return model
+
+n = Input("n", CounterType)
+i_out = Output("i_out", CounterType)
+cond = MakeConditionModel()
+body = MakeBodyModel()
+i_init = [1.0]
+model = Model().Operation("WHILE", cond, body, i_init, n).To(i_out)
+
+example = Example({n: [0.0], i_out: [999.9]}, model=model)
+example.DisableLifeTimeVariation()
+example.DisableDynamicOutputShapeVariation()
+example.ExpectFailure()
diff --git a/nn/tools/test_generator/test_harness/include/TestHarness.h b/nn/tools/test_generator/test_harness/include/TestHarness.h
index a84863c48..bd6f1d28b 100644
--- a/nn/tools/test_generator/test_harness/include/TestHarness.h
+++ b/nn/tools/test_generator/test_harness/include/TestHarness.h
@@ -411,6 +411,11 @@ struct TestModel {
});
return result;
}
+
+ bool isInfiniteLoopTimeoutTest() const {
+ // This should only match the TestModel generated from while_infinite_loop.mod.py.
+ return expectFailure && main.operations[0].type == TestOperationType::WHILE;
+ }
};
// Manages all generated test models.