[exo-tflite] Helper macro and class for test (#7255)
author윤현식/On-Device Lab(SR)/Principal Engineer/삼성전자 <hyunsik.yoon@samsung.com>
Mon, 9 Sep 2019 03:38:09 +0000 (12:38 +0900)
committer박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 9 Sep 2019 03:38:09 +0000 (12:38 +0900)
* [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 <hyunsik.yoon@samsung.com>
* phase -> _phase

compiler/exo-tflite/src/TestHelper.h [new file with mode: 0644]

diff --git a/compiler/exo-tflite/src/TestHelper.h b/compiler/exo-tflite/src/TestHelper.h
new file mode 100644 (file)
index 0000000..ac1795e
--- /dev/null
@@ -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 <logo/Pass.h>
+#include <logo/Phase.h>
+
+#include <loco.h>
+
+#include <stdex/Memory.h>
+
+#include <gtest/gtest.h>
+
+/**
+ * @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 <typename PassT> void add_pass() { _phase.emplace_back(stdex::make_unique<PassT>()); }
+
+  void run(loco::Graph *g)
+  {
+    logo::PhaseRunner<logo::PhaseStrategy::Saturate> 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__