ARMNN: fix unittest fail
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 6 Jul 2021 09:55:37 +0000 (18:55 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 8 Jul 2021 01:59:23 +0000 (10:59 +0900)
1. Fix segmentation fault.

nnstreamerFilterArmnn.invoke02_n tests armnn_invoke() where
private_data == NULL, which incurs segmentation fault
of armnn subplugin.

2. Fix -EPERM of open()

If a Caffe/TFLite parser was not available at build time,
opening Caffe/TFLite file results in -EPERM.
Such cases should not be regarded as test-fail.

3. Fix error handling of armnn subplugin

Use the proper error codes!

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
ext/nnstreamer/tensor_filter/tensor_filter_armnn.cc
tests/nnstreamer_filter_armnn/unittest_filter_armnn.cc

index c058aa1..bbbdcb4 100644 (file)
@@ -150,19 +150,20 @@ ArmNNCore::~ArmNNCore ()
 int
 ArmNNCore::init (const GstTensorFilterProperties *prop)
 {
-  if (loadModel (prop)) {
+  int err;
+  if ((err = loadModel (prop))) {
     ml_loge ("Failed to load model\n");
-    return -1;
+    return err;
   }
 
-  if (setInputTensorProp ()) {
+  if ((err = setInputTensorProp ())) {
     ml_loge ("Failed to initialize input tensor\n");
-    return -2;
+    return err;
   }
 
-  if (setOutputTensorProp ()) {
+  if ((err = setOutputTensorProp ())) {
     ml_loge ("Failed to initialize output tensor\n");
-    return -3;
+    return err;
   }
   return 0;
 }
@@ -377,7 +378,7 @@ ArmNNCore::loadModel (const GstTensorFilterProperties *prop)
 #endif
   std::vector<std::string> output_vec;
   std::map<std::string, armnn::TensorShape> input_map;
-  int err;
+  int err = 0;
   armnn::Status status;
 
   if (!g_file_test (model_path, G_FILE_TEST_IS_REGULAR)) {
@@ -417,6 +418,8 @@ ArmNNCore::loadModel (const GstTensorFilterProperties *prop)
       throw;
     } catch (const std::runtime_error &re) {
       ml_loge ("Runtime error while loading the network: %s", re.what ());
+      if (err != 0)
+        return err;
       return -EINVAL;
     } catch (const std::exception &ex) {
       ml_loge ("Exception while loading the network : %s", ex.what ());
@@ -650,6 +653,7 @@ armnn_open (const GstTensorFilterProperties *prop, void **private_data)
 {
   ArmNNCore *core;
   accl_hw hw;
+  int err;
 
   core = static_cast<ArmNNCore *> (*private_data);
 
@@ -669,12 +673,12 @@ armnn_open (const GstTensorFilterProperties *prop, void **private_data)
     core = new ArmNNCore (prop->model_files[0], hw);
   } catch (const std::bad_alloc &ex) {
     g_printerr ("Failed to allocate memory for filter subplugin.");
-    return -1;
+    return -ENOMEM;
   }
 
-  if (core->init (prop) != 0) {
+  if ((err = core->init (prop)) != 0) {
     g_printerr ("failed to initialize the object for armnn");
-    return -2;
+    return err;
   }
 
   *private_data = core;
@@ -695,6 +699,7 @@ armnn_invoke (const GstTensorFilterProperties *prop, void **private_data,
 {
   ArmNNCore *core;
 
+  g_return_val_if_fail (private_data != NULL, -EINVAL);
   g_return_val_if_fail (*private_data != NULL, -EINVAL);
   g_return_val_if_fail (input != NULL, -EINVAL);
   g_return_val_if_fail (output != NULL, -EINVAL);
index 804470e..27c5256 100644 (file)
@@ -510,6 +510,10 @@ TEST (nnstreamerFilterArmnn, invokeAdvanced)
   info.info[0].dimension[3] = 1;
 
   ret = sp->open (&prop, &data);
+  if (ret == -EPERM) { /** TFLite Parser is not included in this instance */
+    g_free (model_file);
+    return;
+  }
   EXPECT_EQ (ret, 0);
 
   /** get input/output dimension successfully */
@@ -631,6 +635,16 @@ TEST (nnstreamerFilterArmnn, invoke01)
   output.data = g_malloc (output.size);
 
   ret = sp->open (&prop, &data);
+  if (ret == -EPERM) { /** Caffe Parser Not Included in This System */
+    g_free (data_file);
+    g_free (input.data);
+    g_free (input_uint8_data);
+    g_free (output.data);
+    g_free (prop.output_meta.info[0].name);
+    g_free (prop.input_meta.info[0].name);
+    g_free (model_file);
+    return;
+  }
   EXPECT_EQ (ret, 0);
 
   /** invoke successful */