[test] Fix filter_reload_test
authorYongjoo Ahn <yongjoo1.ahn@samsung.com>
Tue, 29 Aug 2023 08:47:48 +0000 (17:47 +0900)
committerwooksong <wook16.song@samsung.com>
Fri, 1 Sep 2023 00:54:30 +0000 (09:54 +0900)
- The mutex used in the filter is effected by invoke and reload both.
- Set GST_STATE_PAUSED before reloading models, to guarantee that mutex
  is unlocked

Signed-off-by: Yongjoo Ahn <yongjoo1.ahn@samsung.com>
tests/meson.build
tests/nnstreamer_filter_reload/meson.build
tests/nnstreamer_filter_reload/tensor_filter_reload_test.c

index 70a5221..6e26557 100644 (file)
@@ -25,6 +25,20 @@ if libpng_dep.found()
   )
 endif
 
+# Shared library of internal APIs for nnstreamer-test
+unittest_util_shared = shared_library('nnstreamer_unittest_util',
+  join_paths(meson.current_source_dir(), 'unittest_util.c'),
+  dependencies: nnstreamer_dep,
+  include_directories: nnstreamer_inc,
+  install: get_option('install-test'),
+  install_dir: nnstreamer_libdir
+)
+unittest_util_dep = declare_dependency(link_with: unittest_util_shared,
+  dependencies: nnstreamer_dep,
+  compile_args: ['-DFAKEDLOG=1'],
+  include_directories: include_directories('.')
+)
+
 # ssat repo_dynamic
 subdir('nnstreamer_repo_dynamicity')
 
@@ -38,20 +52,6 @@ gtest_dep = dependency('gtest', required: false)
 if gtest_dep.found()
   lesser_code_quality_accepted_for_unittest_code = declare_dependency(compile_args: ['-Wno-unused-parameter', '-Wno-missing-field-initializers', '-Wno-maybe-uninitialized'])
 
-  # Shared library of internal APIs for nnstreamer-gtest
-  unittest_util_shared = shared_library('nnstreamer_unittest_util',
-    join_paths(meson.current_source_dir(), 'unittest_util.c'),
-    dependencies: nnstreamer_dep,
-    include_directories: nnstreamer_inc,
-    install: get_option('install-test'),
-    install_dir: nnstreamer_libdir
-  )
-  unittest_util_dep = declare_dependency(link_with: unittest_util_shared,
-    dependencies: nnstreamer_dep,
-    compile_args: ['-DFAKEDLOG=1'],
-    include_directories: include_directories('.')
-  )
-
   nnstreamer_unittest_deps = [
     unittest_util_dep,
     glib_dep,
index 09be087..5c8b66b 100644 (file)
@@ -1,6 +1,6 @@
 executable('unittest_filter_reload',
   'tensor_filter_reload_test.c',
-  dependencies: [nnstreamer_dep, gst_dep, glib_dep],
+  dependencies: [unittest_util_dep, gst_dep, glib_dep],
   install: get_option('install-test'),
   install_dir: unittest_install_dir
 )
index 06132ed..7e76005 100644 (file)
@@ -13,8 +13,8 @@
 #include <stdlib.h>
 #include <gst/gst.h>
 #include <nnstreamer_util.h>
+#include <unittest_util.h>
 
-#define _print_log(...) if (!silent) g_message (__VA_ARGS__)
 #define make_gst_element(element) do{\
   element = gst_element_factory_make(#element, #element);\
   if (!element) {\
@@ -28,7 +28,6 @@
 #define EVENT_INTERVAL (1000)
 #define EVENT_TIMEOUT (10000)
 
-static gboolean silent = TRUE;
 static gchar *input_img_path = NULL;
 static gchar *first_model_path = NULL;
 static gchar *second_model_path = NULL;
@@ -134,24 +133,35 @@ check_output (GstElement * sink, void *data __attribute__ ((unused)))
  * @brief Reload a tensor filter's model (v1 <-> v2)
  */
 static gboolean
-reload_model (GstElement * tensor_filter)
+reload_model (GstElement * pipeline)
 {
   static gboolean is_first = TRUE;
   const gchar *model_path;
+  GstElement *tensor_filter;
 
-  if (!tensor_filter)
+  if (!pipeline)
     return FALSE;
 
-  model_path = is_first ? second_model_path : first_model_path;
+  tensor_filter = gst_bin_get_by_name (GST_BIN (pipeline), "tfilter");
+  if (!tensor_filter) {
+    return FALSE;
+  }
 
+  model_path = is_first ? second_model_path : first_model_path;
+  setPipelineStateSync (pipeline, GST_STATE_PAUSED, UNITTEST_STATECHANGE_TIMEOUT);
+  g_usleep (TEST_DEFAULT_SLEEP_TIME);
   g_object_set (G_OBJECT (tensor_filter), "model", model_path, NULL);
 
   _print_log ("Model %s is just reloaded\n", model_path);
 
   is_first = !is_first;
-
+  setPipelineStateSync (pipeline, GST_STATE_PLAYING, UNITTEST_STATECHANGE_TIMEOUT);
+  g_usleep (TEST_DEFAULT_SLEEP_TIME);
   /* repeat if it's playing */
-  return (GST_STATE (GST_ELEMENT (tensor_filter)) == GST_STATE_PLAYING);
+
+  gst_object_unref (tensor_filter);
+
+  return (GST_STATE (GST_ELEMENT (pipeline)) == GST_STATE_PLAYING);
 }
 
 /**
@@ -200,8 +210,6 @@ main (int argc, char *argv[])
           &second_model_path,
           "The path of second model file",
         "e.g., models/mobilenet_v2_1.0_224_quant.tflite"},
-    {"silent", 's', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &silent,
-        "Hide debug message", "TRUE (default)"},
     {NULL}
   };
 
@@ -246,6 +254,7 @@ main (int argc, char *argv[])
   g_object_set (G_OBJECT (capsfilter), "caps", caps, NULL);
   gst_caps_unref (caps);
 
+  g_object_set (G_OBJECT (tensor_filter), "name", "tfilter", NULL);
   g_object_set (G_OBJECT (tensor_filter), "framework", "tensorflow-lite", NULL);
   g_object_set (G_OBJECT (tensor_filter), "model", first_model_path, NULL);
   g_object_set (G_OBJECT (tensor_filter), "is-updatable", TRUE, NULL);
@@ -269,7 +278,7 @@ main (int argc, char *argv[])
   gst_element_set_state (pipeline, GST_STATE_PLAYING);
 
   /* add timeout events */
-  g_timeout_add (EVENT_INTERVAL, (GSourceFunc) reload_model, tensor_filter);
+  g_timeout_add (EVENT_INTERVAL, (GSourceFunc) reload_model, pipeline);
   g_timeout_add (EVENT_TIMEOUT, (GSourceFunc) stop_loop, loop);
 
   g_main_loop_run (loop);