From: 윤현식/On-Device Lab(SR)/Principal Engineer/삼성전자 Date: Mon, 9 Sep 2019 03:38:09 +0000 (+0900) Subject: [exo-tflite] Helper macro and class for test (#7255) X-Git-Tag: accepted/tizen/unified/20190911.111615~44 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b7406143b2bc2ec2451fb2f325cef9e662d114aa;p=platform%2Fcore%2Fml%2Fnnfw.git [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 --- 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__