Optimize the testing time of root_minimization.sh 51/121251/1
authorjin-gyu.kim <jin-gyu.kim@samsung.com>
Mon, 27 Mar 2017 10:04:22 +0000 (19:04 +0900)
committerjin-gyu.kim <jin-gyu.kim@samsung.com>
Mon, 27 Mar 2017 10:04:26 +0000 (19:04 +0900)
Change-Id: I5db5bcf93deabd583062c5fff505ec88b1276c9d

test/root_test/root_minimization.sh

index 19a09ac3b50880aeb0b31e755e7ac4ba9046ed34..98f0067d8e73483d1cab32dbbc991a5757d4b670 100755 (executable)
@@ -328,63 +328,43 @@ checkServiceFile(){
        fi
 
        # Try to find root service
-       for line in $(/bin/cat $ROOT_LIST)
-       do
-               # awk filters 1st value from "," e.g alarm-server.service,systemd
-               service_name=`/bin/echo $line | /usr/bin/awk -F "," '{print $1}'`
-               # compare $1 to service_name in root_daemon_list
-               if [ $1 = $service_name ]; then
-                       /bin/echo "## $service_path is in root_daemon_list"
-                       /bin/echo "======================================================================="
-                       # stop below code lines and return success to find
-                       return 0
-               fi
-       done
-
+       temp=$(cat $ROOT_LIST | grep $service_name)
+       if [ -n "$temp" ]
+       then
+               /bin/echo "## $service_path is in root_daemon_list"
+               /bin/echo "======================================================================="
+               return 0
+       fi
        # Try to find non-daemon service
-       for line in $(/bin/cat $NON_DAEMON_LIST)
-       do
-               service_name=`/bin/echo $line | /usr/bin/awk -F "," '{print $1}'`
-               if [ $1 = $service_name ]; then
-                       /bin/echo "## $service_path is in non_daemon_list"
-                       /bin/echo "======================================================================="
-                       # stop below code lines and retrun success to find
-                       return 0
-               fi
-       done
+       temp=$(cat $NON_DAEMON_LIST | grep $service_name)
+       if [ -n "$temp" ]
+       then
+               /bin/echo "## $service_path is in non_daemon_list"
+               /bin/echo "======================================================================="
+               return 0
+       fi
 
        # Try to find exception case
-       for line in $(/bin/cat $EXCEPTION_LIST)
-       do
-               service_name=`/bin/echo $line | /usr/bin/awk -F "," '{print $1}'`
-               exception_case=`/bin/echo $line | /usr/bin/awk -F "," '{print $3}'`
-               if [ $1 = $service_name ]; then
-                       if [ "$exception_case" = "EXCEPTED" ]; then
-                               /bin/echo "## $service_path is in exception_list"
-                               /bin/echo "======================================================================="
-                               # stop below code lines and retrun success to find
-                               return 0
-                       fi
-               fi
-       done
+       temp=$(cat $EXCEPTION_LIST | grep $service_name | grep "EXCEPTED")
+       if [ -n "$temp" ]
+       then
+               /bin/echo "## $service_path is in exception_list"
+               /bin/echo "======================================================================="
+               return 0
+       fi
 
        # Try to find non-root daemon service
-       for line in $(/bin/cat $NON_ROOT_LIST)
-       do
-               service_name=`/bin/echo $line | /usr/bin/awk -F "," '{print $1}'`
-               if [ $1 = $service_name ]; then
-                       /bin/echo "## $service_path is in non_root_list"
-                       # Found,
-                       # 1st extract service type, uid, gid from our list
-                       service_type=`/bin/echo $line | /usr/bin/awk -F "," '{print $2}'`
-                       expected_uid=`/bin/echo $line | /usr/bin/awk -F "," '{print $3}'`
-                       expected_gid=`/bin/echo $line | /usr/bin/awk -F "," '{print $4}'`
-                       # 2nd call checkNonRootList (pass service name, service type, uid, gid)
-                       checkNonRootList $service_name $service_type $expected_uid $expected_gid
-                       # If found non-Root, then should  retrun success to find
-                       return 0
-               fi
-       done
+       temp=$(cat $NON_ROOT_LIST | grep $service_name)
+       if [ -n "$temp" ]
+       then
+               /bin/echo "## $service_path is in non_root_list"
+               service_name=`/bin/echo $temp | /usr/bin/awk -F "," '{print $1}'`
+               service_type=`/bin/echo $temp | /usr/bin/awk -F "," '{print $2}'`
+               expected_uid=`/bin/echo $temp | /usr/bin/awk -F "," '{print $3}'`
+               expected_gid=`/bin/echo $temp | /usr/bin/awk -F "," '{print $4}'`
+               checkNonRootList $service_name $service_type $expected_uid $expected_gid
+               return 0
+       fi
 
        # ## This service would be new daemon / service ##
        checkWhetherNewRoot $1 $2