[unittest] migrate unittest from unittest_nntrainer_layers to unittest_layers
authorhyeonseok lee <hs89.lee@samsung.com>
Tue, 27 Sep 2022 03:00:20 +0000 (12:00 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Sun, 23 Oct 2022 22:14:48 +0000 (07:14 +0900)
 - Migrate unittest for test negative property from unittest_nntrainer_layer to
   unittest_layers
 - Added LayerPropertySemantics which is inherited from LayerSemantics
   to test negative property only
 - Added LayerPropertySemantics in Simpleshot and pow layer unittest

Signed-off-by: hyeonseok lee <hs89.lee@samsung.com>
Applications/Custom/LayerPlugin/layer_plugin_pow_test.cpp
Applications/SimpleShot/test/simpleshot_layer_common_tests.cpp
test/unittest/layers/layers_common_tests.h
test/unittest/layers/layers_dependent_common_tests.cpp
test/unittest/layers/layers_standalone_common_tests.cpp
test/unittest/layers/unittest_layers_input.cpp
test/unittest/layers/unittest_layers_permute.cpp
test/unittest/layers/unittest_layers_pooling2d.cpp
test/unittest/layers/unittest_layers_preprocess_flip.cpp

index 54533ed5759f4b72cab795d4d01b67f6cefbbd7e..37cd463bbd274ad69103585ebaec9ba23a81fc1b 100644 (file)
@@ -27,4 +27,21 @@ auto semantic_pow =
   LayerSemanticsParamType(nntrainer::createLayer<custom::PowLayer>,
                           custom::PowLayer::type, {}, 0, false, 1);
 
-GTEST_PARAMETER_TEST(PowLayer, LayerSemantics, ::testing::Values(semantic_pow));
+auto semantic_pow_exponent = LayerSemanticsParamType(
+  nntrainer::createLayer<custom::PowLayer>, custom::PowLayer::type,
+  {"exponent=2.0"}, 0, false, 1);
+
+GTEST_PARAMETER_TEST(PowLayer, LayerSemantics,
+                     ::testing::Values(semantic_pow, semantic_pow_exponent));
+
+auto semantic_pow_exp =
+  LayerSemanticsParamType(nntrainer::createLayer<custom::PowLayer>,
+                          custom::PowLayer::type, {"exp=2.0"}, 0, false, 1);
+
+auto semantic_pow_exponential = LayerSemanticsParamType(
+  nntrainer::createLayer<custom::PowLayer>, custom::PowLayer::type,
+  {"exponential=2.0"}, 0, false, 1);
+
+GTEST_PARAMETER_TEST(PowLayer, LayerPropertySemantics,
+                     ::testing::Values(semantic_pow_exp,
+                                       semantic_pow_exponential));
index 1437a06bd9883a2e838ae6cb91306b030eec4c80..6c283155d89aedcb74b54306eb79d05711b01bba 100644 (file)
@@ -42,3 +42,11 @@ GTEST_PARAMETER_TEST(CentroidKNN, LayerSemantics,
 
 GTEST_PARAMETER_TEST(CenteringLayer, LayerSemantics,
                      ::testing::Values(semantic_activation_centering));
+
+auto semantic_activation_centroid_knn_prop_n = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::CentroidKNN>, nntrainer::CentroidKNN::type,
+  {"class_num=1"}, 0, false, 1);
+
+GTEST_PARAMETER_TEST(
+  Input, LayerPropertySemantics,
+  ::testing::Values(semantic_activation_centroid_knn_prop_n));
index 7ccfb9d94a9ffaf6a8d0252ba718efc59cd04ae9..0d2c5d4a1a1452692af886cd4c3ce6465ea73e74 100644 (file)
@@ -84,6 +84,12 @@ protected:
   unsigned int num_inputs;
 };
 
+/**
+ * @brief LayerPropertySemantics
+ * @details Inherit LayerSemantics to solely test negative property cases
+ */
+class LayerPropertySemantics : public LayerSemantics {};
+
 typedef enum {
   SKIP_CALC_GRAD = 1 << 0,  /**< skip calculating gradient and compare */
   SKIP_CALC_DERIV = 1 << 1, /**< skip calculating derivative and compare */
index e2ee521ed755719d0025be8cded515bedb43efaf..d4127b2ebb2930e38ca6175fc4250ec81d309621 100644 (file)
@@ -33,6 +33,11 @@ TEST_P(LayerSemantics, createFromAppContext_pn) {
             expected_type);
 }
 
+TEST_P(LayerPropertySemantics, setPropertiesInvalid_n) {
+  auto lnode = nntrainer::createLayerNode(expected_type);
+  EXPECT_THROW(layer->setProperty({valid_properties}), std::invalid_argument);
+}
+
 TEST_P(LayerSemantics, setPropertiesInvalid_n) {
   auto lnode = nntrainer::createLayerNode(expected_type);
   /** must not crash */
index a828c36ed5e728727cdb2aa6233b409c8f8af4ab..9bca086292b7041db884024e9b84777318c9eb6a 100644 (file)
@@ -34,8 +34,18 @@ TEST_P(LayerSemantics, DISABLED_setPropertiesValidWithInvalid_n) {
   EXPECT_EQ(1, 1); /**< no assert tc from TCM, this is disabled test */
 }
 
-TEST_P(LayerSemantics, DISABLED_setPropertiesValidInvalidOnly_n) {
-  EXPECT_EQ(1, 1); /**< no assert tc from TCM, this is disabled test */
+TEST_P(LayerPropertySemantics, setPropertiesValidInvalidOnly_n) {
+  EXPECT_THROW(layer->setProperty(valid_properties), std::invalid_argument);
+}
+
+TEST_P(LayerSemantics, gettersValidate_p) {
+  std::string type;
+
+  EXPECT_NO_THROW(type = layer->getType());
+  EXPECT_GT(type.size(), size_t(0));
+  EXPECT_NO_THROW(layer->supportInPlace());
+  EXPECT_NO_THROW(layer->requireLabel());
+  EXPECT_NO_THROW(layer->supportBackwarding());
 }
 
 TEST_P(LayerSemantics, finalizeValidate_p) {
@@ -63,19 +73,6 @@ TEST_P(LayerSemantics, finalizeValidate_p) {
   }
 }
 
-TEST_P(LayerSemantics, getTypeValidate_p) {
-  std::string type;
-
-  EXPECT_NO_THROW(type = layer->getType());
-  EXPECT_GT(type.size(), size_t(0));
-}
-
-TEST_P(LayerSemantics, gettersValidate_p) {
-  EXPECT_NO_THROW(layer->supportInPlace());
-  EXPECT_NO_THROW(layer->requireLabel());
-  EXPECT_NO_THROW(layer->supportBackwarding());
-}
-
 TEST_P(LayerSemantics, setBatchValidate_p) {
   ml::train::TensorDim in_dim({1, 1, 1, 1});
   std::vector<ml::train::TensorDim> input_dims(num_inputs, in_dim);
index a2e98e3bba4fb64d9ae0e4a99415e6e39bf9ed64..234cc93d8cc90cbae619044fd6cf4e9c1301f843 100644 (file)
@@ -21,3 +21,11 @@ auto semantic_input =
                           nntrainer::InputLayer::type, {}, 0, false, 1);
 
 GTEST_PARAMETER_TEST(Input, LayerSemantics, ::testing::Values(semantic_input));
+
+auto input_prop_n = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::InputLayer>, nntrainer::InputLayer::type,
+  {"input_shape=0:3:2:1"},
+  LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
+
+GTEST_PARAMETER_TEST(Input, LayerPropertySemantics,
+                     ::testing::Values(input_prop_n));
index 6f55ad901f04082ffc26bbeae1d7aa5373fa201d..f367361c24ac61ac83043a100d8d5b5b301e1ef5 100644 (file)
@@ -22,3 +22,33 @@ auto semantic_permute = LayerSemanticsParamType(
 
 GTEST_PARAMETER_TEST(Permute, LayerSemantics,
                      ::testing::Values(semantic_permute));
+
+auto permute_prop1 = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::PermuteLayer>,
+  nntrainer::PermuteLayer::type, {"direction=random_string"},
+  LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
+
+auto permute_prop2 = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::PermuteLayer>,
+  nntrainer::PermuteLayer::type, {"direction=1,2,4"},
+  LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
+
+auto permute_prop3 = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::PermuteLayer>,
+  nntrainer::PermuteLayer::type, {"direction=1,2,3,0"},
+  LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
+
+auto permute_prop4 = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::PermuteLayer>,
+  nntrainer::PermuteLayer::type, {"direction=3:1:2"},
+  LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
+
+auto permute_prop5 = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::PermuteLayer>,
+  nntrainer::PermuteLayer::type, {"direction=3|1|2"},
+  LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
+
+GTEST_PARAMETER_TEST(Permute, LayerPropertySemantics,
+                     ::testing::Values(permute_prop1, permute_prop2,
+                                       permute_prop3, permute_prop4,
+                                       permute_prop5));
index c806776e3bd0cbae3026d191f3b51f3159403d17..3d32cf49673f5b109d0484e65627d42e810d9d4b 100644 (file)
@@ -39,3 +39,11 @@ GTEST_PARAMETER_TEST(Pooling2DMax, LayerSemantics,
                                        semantic_pooling2d_avg,
                                        semantic_pooling2d_global_max,
                                        semantic_pooling2d_global_avg));
+
+auto pooling2d_prop = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::Pooling2DLayer>,
+  nntrainer::Pooling2DLayer::type, {"pool_size="},
+  LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
+
+GTEST_PARAMETER_TEST(Pooling2DMax, LayerPropertySemantics,
+                     ::testing::Values(pooling2d_prop));
index 3ef3feb4ae464abebd37ff033a90dd3eecaee21b..6d6f2af1792e033f210e6d302d4e4025f6e7e52a 100644 (file)
@@ -22,3 +22,33 @@ auto semantic_flip = LayerSemanticsParamType(
 
 GTEST_PARAMETER_TEST(PreprocessFlip, LayerSemantics,
                      ::testing::Values(semantic_flip));
+
+auto flip_prop1 = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::PreprocessFlipLayer>,
+  nntrainer::PreprocessFlipLayer::type,
+  {"flip_direction=vertical_and_horizontal"},
+  LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
+
+auto flip_prop2 = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::PreprocessFlipLayer>,
+  nntrainer::PreprocessFlipLayer::type, {"flip_direction=flip"},
+  LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
+
+auto flip_prop3 = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::PreprocessFlipLayer>,
+  nntrainer::PreprocessFlipLayer::type, {"flip_direction=horizontal&vertical"},
+  LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
+
+auto flip_prop4 = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::PreprocessFlipLayer>,
+  nntrainer::PreprocessFlipLayer::type, {"flip_direction=horizontal&&vertical"},
+  LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
+
+auto flip_prop5 = LayerSemanticsParamType(
+  nntrainer::createLayer<nntrainer::PreprocessFlipLayer>,
+  nntrainer::PreprocessFlipLayer::type, {"flip_direction=horizontal+vertical"},
+  LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
+
+GTEST_PARAMETER_TEST(PreprocessFlip, LayerPropertySemantics,
+                     ::testing::Values(flip_prop1, flip_prop2, flip_prop3,
+                                       flip_prop4, flip_prop5));