From 4e02961a1ff349834bc75c881276691c111d28c6 Mon Sep 17 00:00:00 2001 From: Wook Song Date: Tue, 28 Jan 2020 08:43:41 +0900 Subject: [PATCH] [Tests/Filter/MvNCSDK2] Add a basic test case This patch adds a basic test case for the most basic execution flow testing. Signed-off-by: Wook Song --- .../unittest_filter_mvncsdk2.cc | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 tests/nnstreamer_filter_mvncsdk2/unittest_filter_mvncsdk2.cc diff --git a/tests/nnstreamer_filter_mvncsdk2/unittest_filter_mvncsdk2.cc b/tests/nnstreamer_filter_mvncsdk2/unittest_filter_mvncsdk2.cc new file mode 100644 index 0000000..05dd297 --- /dev/null +++ b/tests/nnstreamer_filter_mvncsdk2/unittest_filter_mvncsdk2.cc @@ -0,0 +1,117 @@ +/** + * @file unittest_filter_mvncsdk2.cc + * @date 10 Jan 2020 + * @brief Unit test for the tensor filter sub-plugin for MVNCSDK2 + * @see https://github.com/nnsuite/nnstreamer + * @author Wook Song + * @bug No known bugs. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "NCSDKTensorFilterTestHelper.hh" + +/** + * @brief Testing valid pipeline launching and its state changing + */ +TEST (pipeline_mvncsdk2_filter, launch_normal) +{ + const gchar *root_path = g_getenv ("NNSTREAMER_BUILD_ROOT_PATH"); + gchar *pipeline; + gchar *test_model; + GstElement *gstpipe; + GError *err = NULL; + int status = 0; + + if (root_path == NULL) { + root_path = ".."; + } + test_model = g_build_filename (root_path, "tests", "test_models", "models", + "google_lenet_ncsdk_caffe_1.graph", NULL); + /* Create a nnstreamer pipeline */ + pipeline = g_strdup_printf ("videotestsrc ! videoconvert ! videoscale ! videorate ! video/x-raw,format=BGR,width=224,height=224 " + "! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-104.0069877 " + "! tensor_filter framework=movidius-ncsdk2 model=\"%s\" ! fakesink", + test_model); + + NCSDKTensorFilterTestHelper::getInstance ().init (GOOGLE_LENET); + + gstpipe = gst_parse_launch (pipeline, &err); + if (gstpipe) { + GstState state; + GstStateChangeReturn ret; + bool test = false; + + ret = gst_element_get_state (gstpipe, &state, nullptr, GST_SECOND); + EXPECT_EQ (ret, GST_STATE_CHANGE_SUCCESS); + EXPECT_EQ (state, GST_STATE_NULL); + + ret = gst_element_set_state (gstpipe, GST_STATE_READY); + EXPECT_EQ (ret, GST_STATE_CHANGE_SUCCESS); + + ret = gst_element_get_state (gstpipe, &state, nullptr, GST_SECOND); + EXPECT_EQ (ret, GST_STATE_CHANGE_SUCCESS); + EXPECT_EQ (state, GST_STATE_READY); + + ret = gst_element_set_state (gstpipe, GST_STATE_PLAYING); + /* Run the pipeline for three seconds */ + g_usleep (3 * G_USEC_PER_SEC); + if ((ret == GST_STATE_CHANGE_ASYNC) || (ret == GST_STATE_CHANGE_SUCCESS)) { + test = true; + } + EXPECT_EQ (test, true); + + ret = gst_element_set_state (gstpipe, GST_STATE_NULL); + EXPECT_EQ (ret, GST_STATE_CHANGE_SUCCESS); + + ret = gst_element_get_state (gstpipe, &state, nullptr, GST_SECOND); + EXPECT_EQ (ret, GST_STATE_CHANGE_SUCCESS); + EXPECT_EQ (state, GST_STATE_NULL); + + gst_object_unref (gstpipe); + } else { + status = -1; + g_printerr("Failed to launch the pipeline, %s : %s\n", pipeline, + (err) ? err->message : "unknown reason"); + g_clear_error (&err); + } + EXPECT_EQ (status, 0); + g_free (test_model); + g_free (pipeline); + + NCSDKTensorFilterTestHelper::getInstance ().release (); +} + +/** + * @brief Main function for unit test. + */ +int +main (int argc, char **argv) +{ + int ret = -1; + + try { + testing::InitGoogleTest (&argc, argv); + } catch (...) { + g_warning ("catch 'testing::internal::::ClassUniqueToAlwaysTrue'"); + } + + gst_init (&argc, &argv); + + + try { + ret = RUN_ALL_TESTS (); + } catch (...) { + g_warning ("catch `testing::internal::GoogleTestFailureException`"); + } + + return ret; +} -- 2.7.4