[Refactor] s/Layer/LayerV1
authorJihoon Lee <jhoon.it.lee@samsung.com>
Tue, 15 Jun 2021 07:43:08 +0000 (16:43 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 23 Jun 2021 07:42:19 +0000 (16:42 +0900)
Change class name of layer to layerV1 to prepare migration
This should pass CI test.

**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>
Applications/Custom/LayerPlugin/layer_plugin_test.cpp [new file with mode: 0644]

diff --git a/Applications/Custom/LayerPlugin/layer_plugin_test.cpp b/Applications/Custom/LayerPlugin/layer_plugin_test.cpp
new file mode 100644 (file)
index 0000000..4c97dfc
--- /dev/null
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: Apache-2.0
+/**
+ * Copyright (C) 2020 Jihoon Lee <jhoon.it.lee@samsung.com>
+ *
+ * @file   layer_plugin_test.cpp
+ * @date   26 January 2021
+ * @brief  This file contains the execution part of LayerPlugin example
+ * @see    https://github.com/nnstreamer/nntrainer
+ * @author Jihoon Lee <jhoon.it.lee@samsung.com>
+ * @bug    No known bugs except for NYI items
+ *
+ */
+#include <gtest/gtest.h>
+
+#include <dlfcn.h>
+#include <fstream>
+#include <iostream>
+#include <string>
+
+#include <app_context.h>
+#include <layer.h>
+#include <layer_internal.h>
+
+const char *NNTRAINER_PATH = std::getenv("NNTRAINER_PATH");
+
+TEST(AppContext, DlRegisterOpen_p) {
+  ASSERT_NE(NNTRAINER_PATH, nullptr)
+    << "NNTRAINER_PATH environment value must be set";
+  auto ac = nntrainer::AppContext();
+
+  ac.registerLayer("libpow_layer.so", NNTRAINER_PATH);
+
+  auto layer = ac.createObject<nntrainer::LayerV1>("pow");
+
+  EXPECT_EQ(layer->getType(), "pow");
+}
+
+TEST(AppContext, DlRegisterWrongPath_n) {
+  ASSERT_NE(NNTRAINER_PATH, nullptr)
+    << "NNTRAINER_PATH environment value must be set";
+  auto ac = nntrainer::AppContext();
+
+  EXPECT_THROW(ac.registerLayer("wrong_name.so"), std::invalid_argument);
+}
+
+TEST(AppContext, DlRegisterDirectory_p) {
+  ASSERT_NE(NNTRAINER_PATH, nullptr)
+    << "NNTRAINER_PATH environment value must be set";
+  auto ac = nntrainer::AppContext();
+
+  ac.registerPluggableFromDirectory(NNTRAINER_PATH);
+
+  auto layer = ac.createObject<nntrainer::LayerV1>("pow");
+
+  EXPECT_EQ(layer->getType(), "pow");
+}
+
+TEST(AppContext, DlRegisterDirectory_n) {
+  auto ac = nntrainer::AppContext();
+
+  EXPECT_THROW(ac.registerPluggableFromDirectory("wrong path"),
+               std::invalid_argument);
+}
+
+TEST(AppContext, DefaultEnvironmentPath_p) {
+  /// as NNTRAINER_PATH is fed to the test, this should success without an
+  /// error
+  std::shared_ptr<ml::train::Layer> l = ml::train::createLayer("pow");
+  EXPECT_EQ(l->getType(), "pow");
+
+  auto layer = nntrainer::getLayerDevel(l);
+
+  std::ifstream input_file("does_not_exist");
+  EXPECT_NO_THROW(layer->read(input_file));
+  if (remove("does_not_exist")) {
+    std::cerr << "failed to remove file\n";
+  }
+
+  std::ofstream output_file("does_not_exist");
+  EXPECT_NO_THROW(layer->save(output_file));
+  if (remove("does_not_exist")) {
+    std::cerr << "failed to remove file\n";
+  }
+
+  EXPECT_NO_THROW(layer->getType());
+  EXPECT_NE(layer->setProperty({"invalid_values"}), ML_ERROR_NONE);
+  EXPECT_EQ(layer->checkValidation(), ML_ERROR_NONE);
+  EXPECT_EQ(layer->getOutputDimension()[0], nntrainer::TensorDim());
+  EXPECT_EQ(layer->getInputDimension()[0], nntrainer::TensorDim());
+}
+
+TEST(AppContext, DefaultEnvironmentPath_n) {
+  /// pow2 does not exist
+  EXPECT_THROW(ml::train::createLayer("pow2"), std::invalid_argument);
+}