From b7406143b2bc2ec2451fb2f325cef9e662d114aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9C=A4=ED=98=84=EC=8B=9D/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 9 Sep 2019 12:38:09 +0900 Subject: [PATCH] [exo-tflite] Helper macro and class for test (#7255) * [exo-tflite] Helper macro and class for test Adding a macro to count the number of node and a class to easily run a pass to test. Signed-off-by: Hyun Sik Yoon * phase -> _phase --- compiler/exo-tflite/src/TestHelper.h | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 compiler/exo-tflite/src/TestHelper.h diff --git a/compiler/exo-tflite/src/TestHelper.h b/compiler/exo-tflite/src/TestHelper.h new file mode 100644 index 0000000..ac1795e --- /dev/null +++ b/compiler/exo-tflite/src/TestHelper.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * 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. + */ + +#ifndef __TEST_HELPER_H__ +#define __TEST_HELPER_H__ + +#include "ProgressReporter.h" +#include "Conversion/TypeInferencePass.h" +#include "Conversion/ShapeInferencePass.h" + +#include +#include + +#include + +#include + +#include + +/** + * @brief Check the number of nodes in a graph starting from OUTPUTS + */ +#define EXO_TEST_ASSERT_NODE_COUNT(OUTPUTS, COUNT) \ + { \ + auto v = loco::postorder_traversal((OUTPUTS)); \ + ASSERT_EQ(v.size(), (COUNT)); \ + } + +namespace exo +{ +namespace test +{ + +/** + * @brief Phase for test, that is used to test pass. This phase initially adds TypeInferencePass + * and ShapeInferencePass + */ +class TypeShapeReadyPhase +{ +public: + TypeShapeReadyPhase() + { + // Type and Shape inference is prerequisite for run other test + _phase.emplace_back(stdex::make_unique<::exo::TypeInferencePass>()); + _phase.emplace_back(stdex::make_unique<::exo::ShapeInferencePass>()); + } + + template void add_pass() { _phase.emplace_back(stdex::make_unique()); } + + void run(loco::Graph *g) + { + logo::PhaseRunner phase_runner{g}; + + ::exo::ProgressReporter prog(g, logo::PhaseStrategy::Saturate); + phase_runner.attach(&prog); + phase_runner.run(_phase); + } + +private: + logo::Phase _phase; +}; + +} // namespace test +} // namespace exo + +#endif // __TEST_HELPER_H__ -- 2.7.4