[SPEC][UT] Add conditions to unit test build and run 77/254477/3
authorRafal Walczyna <r.walczyna@samsung.com>
Wed, 3 Mar 2021 10:30:09 +0000 (11:30 +0100)
committerRafal Walczyna <r.walczyna@samsung.com>
Fri, 5 Mar 2021 11:21:01 +0000 (12:21 +0100)
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 <r.walczyna@samsung.com>
packaging/webapi-plugins.spec
src/bluetooth/ut/main.cc
src/bluetooth/ut/uuid.cc
src/ml/ut/main.cc
src/tizen-wrt.gyp

index dbfdebc..b59e143 100644 (file)
@@ -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
index b209c4a..20fe74e 100644 (file)
 
 #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();
 }
index a7081f6..111ea63 100644 (file)
@@ -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_};
 
index e0463d8..40f1dd7 100644 (file)
  */
 #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
index 882ff72..19cea2f 100755 (executable)
       ],
       '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', {