From cbb65b01278b39789e69c6de888b3e0e78b3e5db Mon Sep 17 00:00:00 2001 From: Wook Song Date: Fri, 10 Jan 2020 20:08:01 +0900 Subject: [PATCH] [Tests/FilterExtCommon] Generate test cases using meson In order to generate test cases from the template file to which the most recent modification has been applied, this patch changes the approach for the test case generation from the existing bash script to the meson build script. Signed-off-by: Wook Song --- .../nnstreamer_filter_extensions_common/deploy.sh | 27 ---------- .../meson.build | 45 ++++++++++------ ...n_template.cc => unittest_tizen_template.cc.in} | 60 +++++++++++----------- 3 files changed, 59 insertions(+), 73 deletions(-) delete mode 100644 tests/nnstreamer_filter_extensions_common/deploy.sh rename tests/nnstreamer_filter_extensions_common/{unittest_tizen_template.cc => unittest_tizen_template.cc.in} (86%) diff --git a/tests/nnstreamer_filter_extensions_common/deploy.sh b/tests/nnstreamer_filter_extensions_common/deploy.sh deleted file mode 100644 index 09e31e7..0000000 --- a/tests/nnstreamer_filter_extensions_common/deploy.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -## -## @file deploy.sh -## @author Parichay Kapoor -## @date Dec 19 2019 -## @brief This creates failure test cases for tensor filter extensions. -BASEPATH=`dirname "$0"` - -ext_name=$1 -ext_nick_name=$2 -model_file=$3 -ext_test_gen_dir=$4 - -pushd $BASEPATH - -mkdir -p ${ext_test_gen_dir} -target_file=${ext_test_gen_dir}/unittest_tizen_${ext_name}.cc - -if [ ! -f "${target_file}" ]; then - cp unittest_tizen_template.cc ${target_file} - - sed -i "s|EXT_NAME|${ext_name}|" ${target_file} - sed -i "s|EXT_NICK_NAME|${ext_nick_name}|" ${target_file} - sed -i "s|MODEL_FILE|${model_file}|" ${target_file} -fi - -popd diff --git a/tests/nnstreamer_filter_extensions_common/meson.build b/tests/nnstreamer_filter_extensions_common/meson.build index dbd117b..5c2cddb 100644 --- a/tests/nnstreamer_filter_extensions_common/meson.build +++ b/tests/nnstreamer_filter_extensions_common/meson.build @@ -6,7 +6,7 @@ tizen_apptest_deps = [ # TODO: enable for python # Format for adding subplugin into extensions - -# [name, nick name, dependencies, model file name/folder path/file path] +# [name, extension abbreviation, dependencies, model file name/folder path/file path] extensions = [] extensions += [['custom', 'custom', nnstreamer_unittest_deps, '../build/nnstreamer_example/custom_example_passthrough/libnnstreamer_customfilter_passthrough.so']] @@ -39,21 +39,34 @@ if have_python3 extensions += [['python3', 'python3', nnstreamer_filter_python3_deps, 'passthrough.py']] endif -ext_test_gen_dir = join_paths(meson.current_build_dir(), 'gen') +sed_command = find_program('sed', required: true) +ext_test_template_prefix = 'unittest_tizen_' +ext_test_template = files (ext_test_template_prefix + 'template.cc.in') foreach ext : extensions - gen_test_src = run_command('deploy.sh', ext[0], ext[1], ext[3], ext_test_gen_dir) - - if gen_test_src.returncode() == 0 - exec = executable('unittest_tizen_' + ext[0], - join_paths(ext_test_gen_dir, 'unittest_tizen_' + ext[0] + '.cc'), - dependencies: [tizen_apptest_deps, ext[2]], - install: get_option('install-test'), - install_dir: unittest_install_dir - ) - - test('unittest_tizen_' + ext[0], exec, args: ['--gst-plugin-path=../..']) - else - warning('Failed to generate basic unittest for ' + ext[0]) - endif + ext_test_path_each = ext_test_template_prefix + ext[0] + '.cc' + + sed_ext_name_option = 's|@EXT_NAME@|' + ext[0] + '|' + sed_ext_abbrv_option = 's|@EXT_ABBRV@|' + ext[1] + '|' + sed_ext_mf_option = 's|@MODEL_FILE@|' + ext[3] + '|' + + ext_test_each = custom_target ( + ext_test_path_each, + input : ext_test_template, + output : ext_test_path_each, + command : [copy, '-f', '@INPUT@', '@OUTPUT@', \ + '&&', 'sed', '-i', sed_ext_name_option, '@OUTPUT@', \ + '&&', 'sed', '-i', sed_ext_abbrv_option, '@OUTPUT@', \ + '&&', 'sed', '-i', sed_ext_mf_option, '@OUTPUT@'] + ) + + exec = executable( + ext_test_template_prefix + ext[0], + ext_test_each, + dependencies: [tizen_apptest_deps, ext[2]], + install: get_option('install-test'), + install_dir: unittest_install_dir + ) + + test(ext_test_template_prefix + ext[0], exec, args: ['--gst-plugin-path=../..']) endforeach diff --git a/tests/nnstreamer_filter_extensions_common/unittest_tizen_template.cc b/tests/nnstreamer_filter_extensions_common/unittest_tizen_template.cc.in similarity index 86% rename from tests/nnstreamer_filter_extensions_common/unittest_tizen_template.cc rename to tests/nnstreamer_filter_extensions_common/unittest_tizen_template.cc.in index 95bd488..71e411f 100644 --- a/tests/nnstreamer_filter_extensions_common/unittest_tizen_template.cc +++ b/tests/nnstreamer_filter_extensions_common/unittest_tizen_template.cc.in @@ -1,7 +1,7 @@ /** - * @file unittest_tizen_EXT_NAME.cc + * @file unittest_tizen_@EXT_NAME@.cc * @date 19 Dec 2019 - * @brief Failure Unit tests for tensor filter extension (EXT_NAME). + * @brief Failure Unit tests for tensor filter extension (@EXT_NAME@). * @see https://github.com/nnsuite/nnstreamer * @author Parichay Kapoor * @bug No known bugs @@ -14,32 +14,32 @@ #include /** - * @brief Test EXT_NICK_NAME subplugin existence. + * @brief Test @EXT_ABBRV@ subplugin existence. */ -TEST (nnstreamer_EXT_NICK_NAME_basic_functions, check_existence) +TEST (nnstreamer_@EXT_ABBRV@_basic_functions, check_existence) { - const GstTensorFilterFramework *sp = nnstreamer_filter_find ("EXT_NAME"); + const GstTensorFilterFramework *sp = nnstreamer_filter_find ("@EXT_NAME@"); EXPECT_NE (sp, (void *) NULL); } /** - * @brief Test EXT_NICK_NAME subplugin with failing open/close (no model file) + * @brief Test @EXT_ABBRV@ subplugin with failing open/close (no model file) */ -TEST (nnstreamer_EXT_NICK_NAME_basic_functions, open_close_00_n) +TEST (nnstreamer_@EXT_ABBRV@_basic_functions, open_close_00_n) { int ret; const gchar *model_files[] = { - "null.EXT_NICK_NAME", NULL, + "null.@EXT_ABBRV@", NULL, }; GstTensorFilterProperties prop = { - .fwname = "EXT_NAME", + .fwname = "@EXT_NAME@", .fw_opened = 0, .model_files = model_files, .num_models = 1, }; void *data = NULL; - const GstTensorFilterFramework *sp = nnstreamer_filter_find ("EXT_NAME"); + const GstTensorFilterFramework *sp = nnstreamer_filter_find ("@EXT_NAME@"); EXPECT_NE (sp, (void *) NULL); ret = sp->open (&prop, &data); @@ -103,9 +103,9 @@ ret: } /** - * @brief Test EXT_NICK_NAME subplugin with successful open/close + * @brief Test @EXT_ABBRV@ subplugin with successful open/close */ -TEST (nnstreamer_EXT_NICK_NAME_basic_functions, open_close_01_n) +TEST (nnstreamer_@EXT_ABBRV@_basic_functions, open_close_01_n) { int ret; void *data = NULL; @@ -115,13 +115,13 @@ TEST (nnstreamer_EXT_NICK_NAME_basic_functions, open_close_01_n) ASSERT_TRUE (model_files != nullptr); GstTensorFilterProperties prop = { - .fwname = "EXT_NAME", + .fwname = "@EXT_NAME@", .fw_opened = 0, .model_files = const_cast(model_files), .num_models = (int) g_strv_length (model_files), }; - const GstTensorFilterFramework *sp = nnstreamer_filter_find ("EXT_NAME"); + const GstTensorFilterFramework *sp = nnstreamer_filter_find ("@EXT_NAME@"); EXPECT_NE (sp, (void *) NULL); /** close without open, should not crash */ @@ -138,9 +138,9 @@ TEST (nnstreamer_EXT_NICK_NAME_basic_functions, open_close_01_n) } /** - * @brief Get input/output dimensions with EXT_NICK_NAME subplugin + * @brief Get input/output dimensions with @EXT_ABBRV@ subplugin */ -TEST (nnstreamer_EXT_NICK_NAME_basic_functions, get_dimension_fail_n) +TEST (nnstreamer_@EXT_ABBRV@_basic_functions, get_dimension_fail_n) { int ret; void *data = NULL; @@ -151,13 +151,13 @@ TEST (nnstreamer_EXT_NICK_NAME_basic_functions, get_dimension_fail_n) ASSERT_TRUE (model_files != nullptr); GstTensorFilterProperties prop = { - .fwname = "EXT_NAME", + .fwname = "@EXT_NAME@", .fw_opened = 0, .model_files = const_cast(model_files), .num_models = (int) g_strv_length (model_files), }; - const GstTensorFilterFramework *sp = nnstreamer_filter_find ("EXT_NAME"); + const GstTensorFilterFramework *sp = nnstreamer_filter_find ("@EXT_NAME@"); EXPECT_NE (sp, (void *) NULL); /** get input/output dimension without open */ @@ -181,9 +181,9 @@ TEST (nnstreamer_EXT_NICK_NAME_basic_functions, get_dimension_fail_n) } /** - * @brief Get input/output dimensions with EXT_NICK_NAME subplugin + * @brief Get input/output dimensions with @EXT_ABBRV@ subplugin */ -TEST (nnstreamer_EXT_NICK_NAME_basic_functions, get_dimension) +TEST (nnstreamer_@EXT_ABBRV@_basic_functions, get_dimension) { int ret; void *data = NULL; @@ -194,13 +194,13 @@ TEST (nnstreamer_EXT_NICK_NAME_basic_functions, get_dimension) ASSERT_TRUE (model_files != nullptr); GstTensorFilterProperties prop = { - .fwname = "EXT_NAME", + .fwname = "@EXT_NAME@", .fw_opened = 0, .model_files = const_cast(model_files), .num_models = (int) g_strv_length (model_files), }; - const GstTensorFilterFramework *sp = nnstreamer_filter_find ("EXT_NAME"); + const GstTensorFilterFramework *sp = nnstreamer_filter_find ("@EXT_NAME@"); EXPECT_NE (sp, (void *) NULL); ret = sp->open (&prop, &data); @@ -218,9 +218,9 @@ TEST (nnstreamer_EXT_NICK_NAME_basic_functions, get_dimension) } /** - * @brief Test EXT_NICK_NAME subplugin with unsuccessful invoke + * @brief Test @EXT_ABBRV@ subplugin with unsuccessful invoke */ -TEST (nnstreamer_EXT_NICK_NAME_basic_functions, invoke_fail_n) +TEST (nnstreamer_@EXT_ABBRV@_basic_functions, invoke_fail_n) { int ret; void *data = NULL; @@ -231,13 +231,13 @@ TEST (nnstreamer_EXT_NICK_NAME_basic_functions, invoke_fail_n) ASSERT_TRUE (model_files != nullptr); GstTensorFilterProperties prop = { - .fwname = "EXT_NAME", + .fwname = "@EXT_NAME@", .fw_opened = 0, .model_files = const_cast(model_files), .num_models = (int) g_strv_length (model_files), }; - const GstTensorFilterFramework *sp = nnstreamer_filter_find ("EXT_NAME"); + const GstTensorFilterFramework *sp = nnstreamer_filter_find ("@EXT_NAME@"); EXPECT_NE (sp, (void *) NULL); /** invoke without open */ @@ -268,9 +268,9 @@ TEST (nnstreamer_EXT_NICK_NAME_basic_functions, invoke_fail_n) } /** - * @brief Test EXT_NICK_NAME subplugin with successful invoke + * @brief Test @EXT_ABBRV@ subplugin with successful invoke */ -TEST (nnstreamer_EXT_NICK_NAME_basic_functions, invoke) +TEST (nnstreamer_@EXT_ABBRV@_basic_functions, invoke) { int ret; void *data = NULL; @@ -283,13 +283,13 @@ TEST (nnstreamer_EXT_NICK_NAME_basic_functions, invoke) ASSERT_TRUE (model_files != nullptr); GstTensorFilterProperties prop = { - .fwname = "EXT_NAME", + .fwname = "@EXT_NAME@", .fw_opened = 0, .model_files = const_cast(model_files), .num_models = (int) g_strv_length (model_files), }; - const GstTensorFilterFramework *sp = nnstreamer_filter_find ("EXT_NAME"); + const GstTensorFilterFramework *sp = nnstreamer_filter_find ("@EXT_NAME@"); EXPECT_NE (sp, (void *) NULL); ret = sp->open (&prop, &data); -- 2.7.4