[filter] Remove assert and throw exception
authorYongjoo Ahn <yongjoo1.ahn@samsung.com>
Mon, 11 Sep 2023 08:01:41 +0000 (17:01 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Tue, 12 Sep 2023 02:44:31 +0000 (11:44 +0900)
- Remove excessive asserts.
- Throw exception when input or output buffer is NULL in invoke method

Signed-off-by: Yongjoo Ahn <yongjoo1.ahn@samsung.com>
ext/nnstreamer/tensor_filter/tensor_filter_snpe.cc
tests/nnstreamer_filter_snpe/unittest_filter_snpe.cc

index 484a735..4dddc90 100644 (file)
@@ -419,8 +419,6 @@ snpe_subplugin::configure_instance (const GstTensorFilterProperties *prop)
     throw std::invalid_argument (err_msg);
   }
 
-  assert (model_path == nullptr);
-
   model_path = g_strdup (prop->model_files[0]);
 
   container = zdl::DlContainer::IDlContainer::open (model_path);
@@ -485,14 +483,16 @@ snpe_subplugin::configure_instance (const GstTensorFilterProperties *prop)
 void
 snpe_subplugin::invoke (const GstTensorMemory *input, GstTensorMemory *output)
 {
-  assert (!empty_model);
-  assert (snpe);
-
 #if (DBG)
   gint64 start_time = g_get_real_time ();
 #endif
   GstTensorInfo *_info;
 
+  if (!input)
+    throw std::runtime_error ("Invalid input buffer, it is NULL.");
+  if (!output)
+    throw std::runtime_error ("Invalid output buffer, it is NULL.");
+
   if (use_user_buffer) {
     for (unsigned int i = 0; i < inputInfo.num_tensors; ++i) {
       _info = gst_tensors_info_get_nth_info (std::addressof (inputInfo), i);
index 4c51b46..2ae0274 100644 (file)
@@ -288,9 +288,9 @@ TEST (nnstreamerFilterSnpe, invoke01_n)
   ret = sp->open (&prop, &data);
   EXPECT_EQ (ret, 0);
 
-  /* catching assertion error */
-  EXPECT_DEATH (sp->invoke (NULL, NULL, data, NULL, &output), "");
-  EXPECT_DEATH (sp->invoke (NULL, NULL, data, &input, NULL), "");
+  /* catching exception */
+  EXPECT_NE (sp->invoke (NULL, NULL, data, NULL, &output), 0);
+  EXPECT_NE (sp->invoke (NULL, NULL, data, &input, NULL), 0);
 
   g_free (input.data);
   g_free (output.data);