[test/layers] enable tests when only available
authorJihoon Lee <jhoon.it.lee@samsung.com>
Tue, 14 Sep 2021 06:03:45 +0000 (15:03 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 15 Sep 2021 03:58:02 +0000 (12:58 +0900)
This patch enables tests when only available. for example,
unittest_layers_nnstreamer.cpp cannot be run on tizen so excluded.

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
nntrainer/layers/common_properties.cpp
nntrainer/layers/common_properties.h
nntrainer/layers/preprocess_flip_layer.cpp
nntrainer/layers/preprocess_translate_layer.cpp
packaging/nntrainer.spec
test/unittest/layers/meson.build
test/unittest/layers/unittest_layers_preprocess_flip.cpp [moved from test/unittest/layers/unittest_layers_preprocess.cpp with 59% similarity]
test/unittest/layers/unittest_layers_preprocess_translate.cpp [new file with mode: 0644]
test/unittest/layers/unittest_layers_split.cpp

index aaefc76..0f21d0c 100644 (file)
@@ -246,6 +246,8 @@ bool WeightRegularizer::isValid(
   const nntrainer::WeightRegularizer &value) const {
   return value != nntrainer::WeightRegularizer::UNKNOWN;
 }
+
+FlipDirection::FlipDirection(FlipDirectionInfo::Enum value) { set(value); }
 } // namespace props
 
 static const std::vector<std::pair<char, std::string>>
index 9687573..4e47320 100644 (file)
@@ -823,6 +823,8 @@ struct FlipDirectionInfo {
  */
 class FlipDirection final : public EnumProperty<FlipDirectionInfo> {
 public:
+  FlipDirection(FlipDirectionInfo::Enum value =
+                  FlipDirectionInfo::Enum::horizontal_and_vertical);
   using prop_tag = enum_class_prop_tag;
   static constexpr const char *key = "flip_direction";
 };
index fdaf1a7..b9e711d 100644 (file)
@@ -40,8 +40,8 @@ void PreprocessFlipLayer::setProperty(const std::vector<std::string> &values) {
 }
 
 void PreprocessFlipLayer::forwarding(RunLayerContext &context, bool training) {
-  props::FlipDirection flipdirection =
-    std::get<props::FlipDirection>(preprocess_flip_props);
+  props::FlipDirectionInfo::Enum flipdirection =
+    std::get<props::FlipDirection>(preprocess_flip_props).get();
 
   if (!training) {
     for (unsigned int idx = 0; idx < context.getNumInputs(); idx++) {
index 181ae0d..314914f 100644 (file)
@@ -82,12 +82,12 @@ void PreprocessTranslateLayer::forwarding(RunLayerContext &context,
     return;
   }
 
+  float random_translate =
+    std::get<props::RandomTranslate>(preprocess_translate_props);
   for (unsigned int idx = 0; idx < context.getNumInputs(); idx++) {
     Tensor &hidden_ = context.getOutput(idx);
     Tensor &input_ = context.getInput(idx);
     const TensorDim input_dim = input_.getDim();
-    float random_translate =
-      std::get<props::RandomTranslate>(preprocess_translate_props);
 
     if (random_translate < epsilon) {
       hidden_ = input_;
index a08cca4..3a7a001 100644 (file)
@@ -413,7 +413,9 @@ lcov -t 'NNTrainer Unit Test Coverage' -o unittest.info -c -d . -b %{_builddir}/
     --exclude "*/test/*" \
     --exclude "*/meson*/*" \
     --exclude "*/nntrainer_logger.cpp" \
-    --exclude "*/tf_schema_generated.h"
+    --exclude "*/tf_schema_generated.h" \
+    --exclude "*/nnstreamer_layer.*"
+# nnstreamer layer is untestable here
 
 # Visualize the report
 genhtml -o result unittest.info -t "nntrainer %{version}-%{release} ${VCS}" --ignore-errors source -p ${RPM_BUILD_DIR}
index c3f6abf..aad326f 100644 (file)
@@ -43,15 +43,28 @@ test_target = [
   'unittest_layers_rnn.cpp',
   'unittest_layers_lstm.cpp',
   'unittest_layers_gru.cpp',
-  'unittest_layers_preprocess.cpp',
+  'unittest_layers_preprocess_flip.cpp',
   'unittest_layers_split.cpp',
   'unittest_layers_embedding.cpp',
   'unittest_layers_concat.cpp',
-  'unittest_layers_tflite.cpp',
   'unittest_layers_permute.cpp',
-  'unittest_layers_nnstreamer.cpp',
 ]
 
+if get_option('enable-tflite-backbone')
+  test_target += 'unittest_layers_tflite.cpp'
+endif
+
+if opencv_dep.found()
+  test_target += 'unittest_layers_preprocess_translate.cpp'
+endif
+
+if get_option('enable-nnstreamer-backbone')
+  if get_option('platform') != 'tizen'
+    # ml singleshot api cannot be tested inside tizen because of feature issue
+    test_target += 'unittest_layers_nnstreamer.cpp'
+  endif
+endif
+
 exe = executable(
   'unittest_layers', test_target,
   dependencies: [
@@ -2,9 +2,9 @@
 /**
  * Copyright (C) 2021 Parichay Kapoor <pk.kapoor@samsung.com>
  *
- * @file unittest_layers_fully_connected.cpp
- * @date 11 June 2021
- * @brief Preprocess Layer Test
+ * @file unittest_layers_preprocess_flip.cpp
+ * @date 11 June Flip
+ * @brief Preprocess flip Layer Test
  * @see        https://github.com/nnstreamer/nntrainer
  * @author Parichay Kapoor <pk.kapoor@samsung.com>
  * @bug No known bugs except for NYI items
 
 #include <layers_common_tests.h>
 #include <preprocess_flip_layer.h>
-#include <preprocess_translate_layer.h>
 
 auto semantic_flip = LayerSemanticsParamType(
   nntrainer::createLayer<nntrainer::PreprocessFlipLayer>,
   nntrainer::PreprocessFlipLayer::type, {}, 0, false);
 
-auto semantic_translate = LayerSemanticsParamType(
-  nntrainer::createLayer<nntrainer::PreprocessTranslateLayer>,
-  nntrainer::PreprocessTranslateLayer::type, {}, 0, false);
-
 INSTANTIATE_TEST_CASE_P(Preprocess, LayerSemantics,
-                        ::testing::Values(semantic_flip, semantic_translate));
+                        ::testing::Values(semantic_flip));
diff --git a/test/unittest/layers/unittest_layers_preprocess_translate.cpp b/test/unittest/layers/unittest_layers_preprocess_translate.cpp
new file mode 100644 (file)
index 0000000..611c4df
--- /dev/null
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: Apache-2.0
+/**
+ * Copyright (C) 2021 Parichay Kapoor <pk.kapoor@samsung.com>
+ *
+ * @file unittest_layers_preprocess_translate.cpp
+ * @date 11 June 2021
+ * @brief Preprocess Translate Layer Test
+ * @see        https://github.com/nnstreamer/nntrainer
+ * @author Parichay Kapoor <pk.kapoor@samsung.com>
+ * @bug No known bugs except for NYI items
+ */
+#include <tuple>
+
+#include <gtest/gtest.h>
+
+#include <layers_common_tests.h>
+#include <preprocess_translate_layer.h>
+
+auto semantic_translate = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::PreprocessTranslateLayer>,
+  nntrainer::PreprocessTranslateLayer::type, {"random_translate=0.1"}, 0,
+  false);
+
+INSTANTIATE_TEST_CASE_P(Preprocess, LayerSemantics,
+                        ::testing::Values(semantic_translate));
index d8e93e3..ddb9c06 100644 (file)
@@ -16,9 +16,9 @@
 #include <layers_common_tests.h>
 #include <split_layer.h>
 
-auto semantic_split =
-  LayerSemanticsParamType(nntrainer::createLayer<nntrainer::SplitLayer>,
-                          nntrainer::SplitLayer::type, {}, 0, false);
+auto semantic_split = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::SplitLayer>, nntrainer::SplitLayer::type,
+  {"split_dimension=3"}, 0, false);
 
 INSTANTIATE_TEST_CASE_P(Split, LayerSemantics,
                         ::testing::Values(semantic_split));