From: Jihoon Lee Date: Tue, 15 Jun 2021 07:43:08 +0000 (+0900) Subject: [Refactor] s/Layer/LayerV1 X-Git-Tag: accepted/tizen/unified/20210829.234903~265 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8074aa4a05673b4a158805a5ea660176e14e7994;p=platform%2Fcore%2Fml%2Fnntrainer.git [Refactor] s/Layer/LayerV1 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 --- diff --git a/Applications/Custom/LayerPlugin/layer_plugin_test.cpp b/Applications/Custom/LayerPlugin/layer_plugin_test.cpp new file mode 100644 index 0000000..4c97dfc --- /dev/null +++ b/Applications/Custom/LayerPlugin/layer_plugin_test.cpp @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: Apache-2.0 +/** + * Copyright (C) 2020 Jihoon Lee + * + * @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 + * @bug No known bugs except for NYI items + * + */ +#include + +#include +#include +#include +#include + +#include +#include +#include + +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("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("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 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); +}