tests: Also wait for fixed image to be created 16/325116/7
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 3 Jun 2025 15:37:14 +0000 (17:37 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Mon, 9 Jun 2025 14:28:15 +0000 (16:28 +0200)
The process can take very long on low-end hardware, print progress.

Change-Id: I8dfb7c98fe99b1269e583c7c7e07c201ced7c614

tests/integration/sessiond-integration-tests.sh

index 1114ec15bd423ad95938168c697bd1923bab0c85..58e260c507f2de431cf10419e8fc4aae998cda72 100755 (executable)
@@ -7,16 +7,6 @@ readonly TEST_SUBSESSIONS_FIXED=("TestSuite_sub4" "TestSuite_sub5" "TestSuite_su
 # Setting it to `true` makes the script more verbose, making debugging easier.
 VERBOSE=
 
-# Default value of waiting time (in seconds) for the completion of the
-# add/remove subsession operation.
-DELAYVAL=0.1
-
-# Default value of the number of times the waiting loop for the completion of
-# the add/remove subsession operation is repeated.
-# 5 x 0.1s = 0.5s which should be enough even on a moderately loaded system,
-# but if it's not, one can always increase it with the `-m` parameter.
-MAXTRIES=5
-
 verbose_echo()
 {
        if [ "$VERBOSE" = "true" ]; then
@@ -24,64 +14,51 @@ verbose_echo()
        fi
 }
 
+wait_for_user()
+{
+       # Return from the DBus call does not necessarily mean the completion of
+       # the AddUser operation. Since we're not listening to the AddUserCompletion
+       # signal here, the easiest way is to poll and check for the existence of
+       # the subsession directory. `sessiond` guarantees atomicity by copying
+       # subsession files and subdirectories to a temporary directory and
+       # renaming it after the copying operation is completed.
+       local action="$1"
+       local subsession="$2"
+       local subsession_dir="$homedir/subsession/$subsession/apps_rw"
+
+       local elapsed_secs=0
+       local wait_secs=1
+
+       while : ; do
+               echo "waiting for subsession dir to be ${action}-d ($subsession_dir): ${elapsed_secs} seconds"
+               if test "${action}" = "create"; then
+                  if test -d "$subsession_dir"; then break; fi
+               else
+                  if ! test -d "$subsession_dir"; then break; fi
+               fi
+
+               elapsed_secs=$(($elapsed_secs + $wait_secs))
+               sleep $wait_secs
+       done
+}
+
 create_test_users()
 {
        for subsession in "${TEST_SUBSESSIONS[@]}"; do
                echo "Creating test user (regular dir): $subsession"
                # Make a direct request to the server for adding a subsession.
-               busctl call -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager AddUser "is" "$userid" "$subsession"
-
-               # Return from the DBus call does not necessarily mean the completion of
-               # the AddUser operation. Since we're not listening to the AddUserCompletion
-               # signal here, the easiest way is to poll and check for the existence of
-               # the subsession directory. `sessiond` guarantees atomicity by copying
-               # subsession files and subdirectories to a temporary directory and
-               # renaming it after the copying operation is completed.
-               delay=0
-               created=
-               subsession_dir="$homedir/subsession/$subsession/apps_rw"
-               while [ $delay -lt $MAXTRIES ]
-               do
-                       if [ -d "$subsession_dir" ]; then
-                               created=true
-                               break
-                       fi
-                       ((delay=delay+1))
-                       sleep "$DELAYVAL"
-               done
-
-               if [ "$1" == "true" ] && [ "$created" != "true" ]; then
-                       echo "Creating user $subsession (regular dir) failed. Bailing out!"
-                       exit 1
-               fi
+               busctl call --expect-reply=no -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager AddUser "is" "$userid" "$subsession"
+               wait_for_user "create" "$subsession"
        done
 
        for subsession in "${TEST_SUBSESSIONS_FIXED[@]}"; do
                echo "Creating test user (fixed size): $subsession"
-               busctl call -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager AddUserFixedSize "isu" "$userid" "$subsession" 10240
-               sleep $delay
-               echo "Switching into user: $subsession"
-               busctl call -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager SwitchUser "is" "$userid" "$subsession"
-               sleep $delay
-
-
-               delay=0
-               created=
-               subsession_dir="$homedir/subsession/$subsession/apps_rw"
-               while [ $delay -lt $MAXTRIES ]
-               do
-                       if [ -d "$subsession_dir" ]; then
-                               created=true
-                               break
-                       fi
-                       ((delay=delay+1))
-                       sleep "$DELAYVAL"
-               done
+               busctl call --expect-reply=no -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager AddUserFixedSize "isu" "$userid" "$subsession" 10240
+               wait_for_user "create" "$subsession"
 
-               if [ "$1" == "true" ] && [ "$created" != "true" ]; then
-                       echo "Creating user $subsession (fixed size) failed. Bailing out!"
-                       exit 1
-               fi
+               echo "Switching into user: $subsession"
+               busctl call --expect-reply=no -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager SwitchUser "is" "$userid" "$subsession"
+               # waiting not needed as add_user will leaver subsession mounted anyway
        done
 }
 
@@ -92,49 +69,14 @@ remove_test_users()
        for subsession in "${TEST_SUBSESSIONS[@]}"; do
                echo "Removing user (regular dir): $subsession"
                # Make a direct request to the server for removing a subsession.
-               busctl call -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager RemoveUser "is" "$userid" "$subsession"
-
-               # See the remark to the `create_test_users()` function above.
-               delay=0
-               removed=
-               subsession_dir="$homedir/subsession/$subsession/apps_rw"
-               while [ $delay -lt $MAXTRIES ]
-               do
-                       if [ ! -d "$subsession_dir" ]; then
-                               removed=true
-                               break
-                       fi
-                       ((delay=delay+1))
-                       sleep "$DELAYVAL"
-               done
-
-               if [ "$1" == "true" ] && [ "$removed" != "true" ]; then
-                       echo "Removing user $subsession failed (regular dir). Bailing out!"
-                       exit 1
-               fi
+               busctl call --expect-reply=no -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager RemoveUser "is" "$userid" "$subsession"
+               wait_for_user "remove" "$subsession"
        done
 
        for subsession in "${TEST_SUBSESSIONS_FIXED[@]}"; do
                echo "Removing user (fixed size): $subsession"
-               busctl call -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager RemoveUser "is" "$userid" "$subsession"
-
-               delay=0
-               removed=
-               subsession_dir="$homedir/subsession/$subsession/apps_rw"
-               while [ $delay -lt $MAXTRIES ]
-               do
-                       if [ ! -d "$subsession_dir" ]; then
-                               removed=true
-                               break
-                       fi
-                       ((delay=delay+1))
-                       sleep "$DELAYVAL"
-               done
-
-               if [ "$1" == "true" ] && [ "$removed" != "true" ]; then
-                       echo "Removing user $subsession failed (fixed size). Bailing out!"
-                       exit 1
-               fi
+               busctl call --expect-reply=no -- org.tizen.sessiond /org/tizen/sessiond org.tizen.sessiond.subsession.Manager RemoveUser "is" "$userid" "$subsession"
+               wait_for_user "remove" "$subsession"
        done
 }
 
@@ -142,15 +84,9 @@ remove_test_users()
 while [ $# -gt 0 ]
 do
        case $1 in
-       -h) printf "Usage: %s [-d delay_value] [-m max_delay] [-v verbose]\n" "$0"
+       -h) printf "Usage: %s [-v verbose]\n" "$0"
                exit 1
                ;;
-       -d) DELAYVAL=$2
-               shift
-               ;;
-       -m) MAXTRIES=$2
-               shift
-               ;;
        -v) VERBOSE=true
                shift
                ;;
@@ -183,6 +119,7 @@ for subsession in "${TEST_SUBSESSIONS[@]}" "${TEST_SUBSESSIONS_FIXED[@]}"; do
        subsession_dir="$homedir/subsession/$subsession/apps_rw"
        totalfiles=0
 
+       echo "Checking file and directory permissions: $subsession"
        while IFS= read -r -d '' f
        do
                verbose_echo "Checking $f..."