From 5bf41de7cf01492a602afd6a45fbecdf10b721eb Mon Sep 17 00:00:00 2001 From: Rafal Walczyna Date: Wed, 3 Mar 2021 11:30:09 +0100 Subject: [PATCH] [SPEC][UT] Add conditions to unit test build and run Unit tests can be run inside GBS - by setting flag in spec file. [Verification] Built successful with unified, profile mobile, profile wearable both with ut flags on and off. Change-Id: I2a89562893182cf35cd41f8b396a19c4777fe580 Signed-off-by: Rafal Walczyna --- packaging/webapi-plugins.spec | 45 +++++++++++++++++++++++++++++++---- src/bluetooth/ut/main.cc | 7 ++++++ src/bluetooth/ut/uuid.cc | 7 ++++++ src/ml/ut/main.cc | 9 +++++++ src/tizen-wrt.gyp | 28 ++++++++++++++++------ 5 files changed, 84 insertions(+), 12 deletions(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index dbfdebc6..b59e1438 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -6,7 +6,8 @@ %define crosswalk_extensions tizen-extensions-crosswalk %define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions} -%define tizen_ut_build 0 +%define tizen_ut_build 0 +%define tizen_ut_build_and_run_in_gbs 0 Name: webapi-plugins @@ -698,6 +699,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_pat # ut flags GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build=%{tizen_ut_build}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build_and_run_in_gbs=%{tizen_ut_build_and_run_in_gbs}" # feature flags GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_mobile_feature_account_support}" @@ -789,6 +791,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_pat # ut flags GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build=%{tizen_ut_build}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build_and_run_in_gbs=%{tizen_ut_build_and_run_in_gbs}" # feature flags GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_mobile_feature_account_support}" @@ -868,6 +871,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_pat # ut flags GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build=%{tizen_ut_build}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build_and_run_in_gbs=%{tizen_ut_build_and_run_in_gbs}" # feature flags GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_wearable_feature_account_support}" @@ -954,6 +958,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_pat # ut flags GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build=%{tizen_ut_build}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build_and_run_in_gbs=%{tizen_ut_build_and_run_in_gbs}" # feature flags GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_wearable_feature_account_support}" @@ -1033,6 +1038,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_pat # ut flags GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build=%{tizen_ut_build}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build_and_run_in_gbs=%{tizen_ut_build_and_run_in_gbs}" # feature flags GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_tv_feature_account_support}" @@ -1110,6 +1116,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_pat # ut flags GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build=%{tizen_ut_build}" +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_ut_build_and_run_in_gbs=%{tizen_ut_build_and_run_in_gbs}" # feature flags GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_account_support=%{?tizen_common_feature_account_support}" @@ -1189,6 +1196,18 @@ popd %endif # COMMON or IVI %endif # UNIFIED / COMMON or IVI +# run ut +%if "%{?tizen_ut_build_and_run_in_gbs}" == "1" +export LD_LIBRARY_PATH=out/Default/ +out/Default/webapi_common_tests +%if "%{tizen_%{?profile}_feature_bluetooth_support}" == "1" +out/Default/webapi_bluetooth_tests gbs +%endif +%if "%{tizen_%{?profile}_feature_ml_support}" == "1" +out/Default/webapi_ml_tests gbs +%endif +%endif + %install # Extensions. @@ -1210,12 +1229,16 @@ install -p -m 644 plugins.json %{buildroot}%{crosswalk_extensions_path}/common/p mkdir -p %{buildroot}%{crosswalk_extensions_path}/mobile # tizen ut mobile -%if "%{?tizen_ut_build}" == "1" +%if "%{?tizen_ut_build}" == "1" || "%{?tizen_ut_build_and_run_in_gbs}" == "1" mkdir -p %{buildroot}/usr/bin install -p -m 755 out/bin_mobile/webapi_common_tests %{buildroot}/usr/bin/ +%if "%{tizen_mobile_feature_bluetooth_support}" == "1" install -p -m 755 out/bin_mobile/webapi_bluetooth_tests %{buildroot}/usr/bin/ +%endif +%if "%{tizen_mobile_feature_ml_support}" == "1" install -p -m 755 out/bin_mobile/webapi_ml_tests %{buildroot}/usr/bin/ %endif +%endif install -p -m 644 out/bin_mobile/libtizen*.so %{buildroot}%{crosswalk_extensions_path}/mobile # execute desc_gentool @@ -1245,12 +1268,16 @@ install -p -m 644 plugins.json %{buildroot}%{crosswalk_extensions_path}/mobile_e mkdir -p %{buildroot}%{crosswalk_extensions_path}/wearable # tizen ut wearable -%if "%{?tizen_ut_build}" == "1" +%if "%{?tizen_ut_build}" == "1" || "%{?tizen_ut_build_and_run_in_gbs}" == "1" mkdir -p %{buildroot}/usr/bin install -p -m 755 out/bin_wearable/webapi_common_tests %{buildroot}/usr/bin/ +%if "%{tizen_wearable_feature_bluetooth_support}" == "1" install -p -m 755 out/bin_wearable/webapi_bluetooth_tests %{buildroot}/usr/bin/ +%endif +%if "%{tizen_wearable_feature_ml_support}" == "1" install -p -m 755 out/bin_wearable/webapi_ml_tests %{buildroot}/usr/bin/ %endif +%endif install -p -m 644 out/bin_wearable/libtizen*.so %{buildroot}%{crosswalk_extensions_path}/wearable # execute desc_gentool @@ -1358,12 +1385,16 @@ fi %manifest webapi-plugins.manifest # UT files -%if "%{?tizen_ut_build}" == "1" +%if "%{?tizen_ut_build}" == "1" || "%{?tizen_ut_build_and_run_in_gbs}" == "1" %license GTEST.BSD-3-Clause /usr/bin/webapi_common_tests +%if "%{tizen_mobile_feature_bluetooth_support}" == "1" /usr/bin/webapi_bluetooth_tests +%endif +%if "%{tizen_mobile_feature_ml_support}" == "1" /usr/bin/webapi_ml_tests %endif +%endif # mobile-extension-emulator %ifarch %{ix86} x86_64 @@ -1407,12 +1438,16 @@ fi %manifest webapi-plugins.manifest # UT files -%if "%{?tizen_ut_build}" == "1" +%if "%{?tizen_ut_build}" == "1" || "%{?tizen_ut_build_and_run_in_gbs}" == "1" %license GTEST.BSD-3-Clause /usr/bin/webapi_common_tests +%if "%{tizen_wearable_feature_bluetooth_support}" == "1" /usr/bin/webapi_bluetooth_tests +%endif +%if "%{tizen_wearable_feature_ml_support}" == "1" /usr/bin/webapi_ml_tests %endif +%endif # wearable-extension-emulator %ifarch %{ix86} x86_64 diff --git a/src/bluetooth/ut/main.cc b/src/bluetooth/ut/main.cc index b209c4a5..20fe74ef 100644 --- a/src/bluetooth/ut/main.cc +++ b/src/bluetooth/ut/main.cc @@ -16,10 +16,17 @@ #include "gtest/gtest.h" +bool is_run_inside_gbs = false; + #include "bluetooth/ut/uuid.h" #include "bluetooth/ut/uuid.h" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); + if (argc > 1) { + if (strcmp("gbs", argv[1]) == 0) { + is_run_inside_gbs = true; + } + } return RUN_ALL_TESTS(); } diff --git a/src/bluetooth/ut/uuid.cc b/src/bluetooth/ut/uuid.cc index a7081f68..111ea63f 100644 --- a/src/bluetooth/ut/uuid.cc +++ b/src/bluetooth/ut/uuid.cc @@ -47,6 +47,8 @@ using testing::internal::GTestColor; using namespace extension::bluetooth; using namespace extension::bluetooth::util; +extern bool is_run_inside_gbs; + class UUIDTest : public testing::Test { protected: virtual void SetUp() override { @@ -231,6 +233,11 @@ TEST_F(UUIDTest, CreateFromCString) { TEST_F(UUIDTest, CreateFromGATTHandle) { ScopeLogger("CreateFromGATTHandle"); + // this test is not valid for running inside gbs + if (true == is_run_inside_gbs) { + printf("This test has to be run on real device.\n"); + return; + } BTHelper bt_helper{valid_uuids_}; diff --git a/src/ml/ut/main.cc b/src/ml/ut/main.cc index e0463d82..40f1dd75 100644 --- a/src/ml/ut/main.cc +++ b/src/ml/ut/main.cc @@ -15,7 +15,16 @@ */ #include "gtest/gtest.h" +/* MachineLearning Unit Tests package will not work inside gbs. + It has to be run on physical device. */ int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); + if (argc > 1) { + if (strcmp("gbs", argv[1]) == 0) { + printf("WARNING: ML unit tests are not suitable to run inside GBS. " + "Please run these tests on real device.\n"); + return 0; + } + } return RUN_ALL_TESTS(); } \ No newline at end of file diff --git a/src/tizen-wrt.gyp b/src/tizen-wrt.gyp index 882ff726..19cea2f7 100755 --- a/src/tizen-wrt.gyp +++ b/src/tizen-wrt.gyp @@ -15,13 +15,27 @@ ], 'conditions': [ [ - 'tizen_ut_build==1', { - 'dependencies': [ - 'common/common_ut.gyp:*', - 'bluetooth/bluetooth_ut.gyp:*', - 'ml/ml_ut.gyp:*' - ] - } + 'tizen_ut_build==1 or tizen_ut_build_and_run_in_gbs==1', { + 'dependencies': [ + 'common/common_ut.gyp:*' + ], + 'conditions': [ + [ + 'tizen_feature_bluetooth_support==1', { + 'dependencies': [ + 'bluetooth/bluetooth_ut.gyp:*', + ], + }, + ], + [ + 'tizen_feature_ml_support==1', { + 'dependencies': [ + 'ml/ml_ut.gyp:*' + ], + }, + ], + ], + }, ], [ 'tizen_feature_account_support==1', { -- 2.34.1