fix for hang, when trying to use BatchExecutor in tests in non-ui mode 56/212356/3
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Tue, 20 Aug 2019 14:00:15 +0000 (16:00 +0200)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Wed, 21 Aug 2019 12:16:13 +0000 (12:16 +0000)
In some tests UniversalSwitch tried to create MainWindow to retrieve
screen size, which in non-ui mode causes hang. Algo ui_app_exit
can't be called from app_create callback.

Change-Id: I3178c233dbb44bff4ce06a36bf419033f79d6aeb

src/batch/BatchRunner.cpp
tests/ui-scenarios/main.cpp

index 120d5df..2eec093 100644 (file)
@@ -1044,8 +1044,42 @@ void BatchExecutor::insertMethods()
        variables["DOUBLE_TAP"] = generateTapFunction(2);
        variables["TRIPLE_TAP"] = generateTapFunction(3);
 
-       auto generateFlickFunction = [&](int dx, int dy, int steps) {
-               return EvaluationValueFunction{ [ &, dx, dy, steps](EvaluationValue fingers) -> EvaluationValue {
+       enum class FlickKind {
+               down, up, left, right
+       };
+       auto generateFlickFunction = [&](FlickKind kind, int steps) {
+               return EvaluationValueFunction{ [ &, kind, steps](EvaluationValue fingers) -> EvaluationValue {
+                               int dx, dy;
+                               auto size = executeOnMainThread([&]()
+                               {
+                                       return Singleton<UniversalSwitch>::instance().getMainWindow()->getDimensions().size;
+                               });
+
+                               //      280 = 360 - 2 * 40 ( 40 - left margin to emulate regular flick but not flick from side of the screen )
+                               //      250 = 360 - 2 * 55 ( 55 - top margin to emulate regular flick but not flick from side of the screen )
+                               //      360 x 360 - dimensions of wearable screen
+                               auto width = size.width * 280 / 360;
+                               auto height = size.height *  250 / 360;
+
+                               switch (kind)
+                               {
+                               case FlickKind::right:
+                                       dx = width;
+                                       dy = 0;
+                                       break;
+                               case FlickKind::left:
+                                       dx = -width;
+                                       dy = 0;
+                                       break;
+                               case FlickKind::up:
+                                       dx = 0;
+                                       dy = -height;
+                                       break;
+                               case FlickKind::down:
+                                       dx = 0;
+                                       dy = height;
+                                       break;
+                               }
                                auto root = getVisibleRoot();
                                if (!root) throw EvaluationFailure{} << "no visible root (context changed didn't happen)";
                                ASSERT(root->getObject());
@@ -1069,25 +1103,17 @@ void BatchExecutor::insertMethods()
                        }, { { "fingers", 1 } } };
        };
 
-       auto size = Singleton<UniversalSwitch>::instance().getMainWindow()->getDimensions().size;
-
-       //      280 = 360 - 2 * 40 ( 40 - left margin to emulate regular flick but not flick from side of the screen )
-       //      250 = 360 - 2 * 55 ( 55 - top margin to emulate regular flick but not flick from side of the screen )
-       //      360 x 360 - dimensions of wearable screen
-       auto width = size.width * 280 / 360;
-       auto height = size.height *  250 / 360;
-
        // For flick gesture we set the step value to 20.
-       variables["FLICK_RIGHT"] = generateFlickFunction(width, 0, 20);
-       variables["FLICK_LEFT"] = generateFlickFunction(-width, 0, 20);
-       variables["FLICK_UP"] = generateFlickFunction(0, -height, 20);
-       variables["FLICK_DOWN"] = generateFlickFunction(0, height, 20);
+       variables["FLICK_RIGHT"] = generateFlickFunction(FlickKind::right, 20);
+       variables["FLICK_LEFT"] = generateFlickFunction(FlickKind::left, 20);
+       variables["FLICK_UP"] = generateFlickFunction(FlickKind::up, 20);
+       variables["FLICK_DOWN"] = generateFlickFunction(FlickKind::down, 20);
 
        // For drag gesture we set the step value to 60.
-       variables["DRAG_RIGHT"] = generateFlickFunction(width, 0, 60);
-       variables["DRAG_LEFT"] = generateFlickFunction(-width, 0, 60);
-       variables["DRAG_UP"] = generateFlickFunction(0, -height, 60);
-       variables["DRAG_DOWN"] = generateFlickFunction(0, height, 60);
+       variables["DRAG_RIGHT"] = generateFlickFunction(FlickKind::right, 60);
+       variables["DRAG_LEFT"] = generateFlickFunction(FlickKind::left, 60);
+       variables["DRAG_UP"] = generateFlickFunction(FlickKind::up, 60);
+       variables["DRAG_DOWN"] = generateFlickFunction(FlickKind::down, 60);
 
        auto generateWheelTurnFunction = [&]() {
                return EvaluationValueFunction{ [&](bool clockwise, int multiplicity) -> EvaluationValue {
index 35a89ff..b907d8c 100644 (file)
@@ -34,14 +34,22 @@ static void _setting_time_lang_changed(app_event_info_h event_info, void *data)
        }
 }
 
+
+static Eina_Bool callback_exit(void *data)
+{
+       ui_app_exit();
+       return EINA_FALSE;
+}
+
 bool app_create(void *data)
 {
        DEBUG("App create");
        int r = RUN_ALL_TESTS();
+       DEBUG("Tests resulted in %d", r);
        if (r != 0)
                ERROR("RUN_ALL_TESTS() failed");
 
-       ui_app_exit();
+       ecore_timer_add(0.0, callback_exit, NULL);
        return true;
 }