Improve sessiond integration tests 93/283493/1
authorAdam Michalski <a.michalski2@partner.samsung.com>
Thu, 27 Oct 2022 14:41:10 +0000 (16:41 +0200)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Thu, 27 Oct 2022 15:10:20 +0000 (17:10 +0200)
This commit:
* fixes permision check error that incorrectly assumed `owner` as
  the only user that can create a subsession
* adds more verbose messages when comparing files, so that it's
  much easier to identify the file reponsible for the error
* adds proper subsessions clean-up when something goes wrong in
  the middle of the test
* removes an unused global variable.

Change-Id: I5fbdd965e367442d9bce85e065d7e1bb0c475341

tests/integration/sessiond-integration-tests.sh

index b511e74ae73ae8adeb04859d08e90ccdf601f734..0d55d966a80e9ad99ba23ed90257fa805d3424b1 100755 (executable)
@@ -2,7 +2,6 @@
 
 readonly TESTUSER=owner
 readonly TEST_SUBSESSIONS=("TestSuite_sub1" "TestSuite_sub2" "TestSuite_sub3" "TestSuite_sub4" "TestSuite_sub5")
-readonly GROUP=users
 
 # Setting it to `true` makes the script more verbose, making debugging easier.
 VERBOSE=
@@ -50,7 +49,7 @@ create_test_users()
                        sleep "$DELAYVAL"
                done
 
-               if [ "$created" != "true" ]; then
+               if [ "$1" == "true" ] && [ "$created" != "true" ]; then
                        echo "Creating user $subsession failed. Bailing out!"
                        exit 1
                fi
@@ -78,7 +77,7 @@ remove_test_users()
                        sleep "$DELAYVAL"
                done
 
-               if [ "$removed" != "true" ]; then
+               if [ "$1" == "true" ] && [ "$removed" != "true" ]; then
                        echo "Removing user $subsession failed. Bailing out!"
                        exit 1
                fi
@@ -114,7 +113,7 @@ apps_rwdir="${homedir}/apps_rw"
 
 verbose_echo "User id: $userid, home directory: $homedir, apps_rw user directory: $apps_rwdir"
 
-create_test_users
+create_test_users true
 
 # Compare directories.
 skeldir="/etc/skel/apps_rw"
@@ -138,9 +137,12 @@ for subsession in "${TEST_SUBSESSIONS[@]}"; do
                u_usergroup=$(stat --format '%U:%G:%A' "$userf")
                u_user=$(echo "$u_usergroup" | cut -d: -f1)
                u_group=$(echo "$u_usergroup" | cut -d: -f2)
+               verbose_echo "subsession file/dir = $f; home file/dir = $userf"
+               verbose_echo "subsession file/dir [user, group] = [$user, $group], home dir file/dir [user, group] = [$u_user, $u_group]"
 
-               if [ "$user" != "$TESTUSER" ] || [ "$group" != "$u_group" ]; then
+               if [ "$user" != "$u_user" ] || [ "$group" != "$u_group" ]; then
                        echo "$f: incorrect permissions set!"
+                       remove_test_users false
                        exit 1
                fi
 
@@ -152,6 +154,7 @@ for subsession in "${TEST_SUBSESSIONS[@]}"; do
 
                if [ "$fattrs" != "$tattrs" ]; then
                        echo "$f: SMACK attributes differ from the template!"
+                       remove_test_users false
                        exit 1
                fi
 
@@ -165,6 +168,7 @@ for subsession in "${TEST_SUBSESSIONS[@]}"; do
                        copiedl=$(readlink "$templf" | sha256sum | cut -d' ' -f1)
                        if [ "$origl" != "$copiedl" ]; then
                                echo "$f: link points to a different file than the one from the template!"
+                               remove_test_users false
                                exit 1
                        fi
                elif [ -f "$f" ]; then
@@ -173,6 +177,7 @@ for subsession in "${TEST_SUBSESSIONS[@]}"; do
                        copiedf=$(sha256sum "$templf" | cut -d' ' -f1)
                        if [ "$origf" != "$copiedf" ]; then
                                echo "$f: file content differs from the template!"
+                               remove_test_users false
                                exit 1
                        fi
                fi
@@ -188,11 +193,12 @@ for subsession in "${TEST_SUBSESSIONS[@]}"; do
        # in the two directories.
        if [ "$templatefiles" != "$totalfiles" ]; then
                echo "Number of files in subsession $subsession vary from the number of files in the template!"
+               remove_test_users false
                exit 1
        fi
 done
 
-remove_test_users
+remove_test_users true
 
 exit 0