diff --git a/tests/harmattan/testscripts/test-func-launcher.py b/tests/harmattan/testscripts/test-func-launcher.py index 574795c..0802a1f 100644 --- a/tests/harmattan/testscripts/test-func-launcher.py +++ b/tests/harmattan/testscripts/test-func-launcher.py @@ -282,41 +282,70 @@ class launcher_tests (unittest.TestCase): """ File descriptor test for booster-m """ - count = get_file_descriptor("booster-m", "m", "fala_ft_hello") - self.assert_(count != 0, "None of the file descriptors were changed") - if(sighup): - self.sighup_applauncherd() - self.test_fd_booster_m(False) + self._check_changed_fd_count("m", PREFERED_APP) def test_fd_booster_q(self, sighup = True): """ File descriptor test for booster-q """ - count = get_file_descriptor("booster-q", "qt", "fala_ft_hello") - self.assert_(count != 0, "None of the file descriptors were changed") - if(sighup): - self.sighup_applauncherd() - self.test_fd_booster_q(False) + self._check_changed_fd_count("q", PREFERED_APP) def test_fd_booster_d(self, sighup = True): """ File descriptor test for booster-d """ - count = get_file_descriptor("booster-d", "d", "fala_qml_helloworld") - self.assert_(count != 0, "None of the file descriptors were changed") - if(sighup): - self.sighup_applauncherd() - self.test_fd_booster_d(False) + self._check_changed_fd_count("d", PREFERED_APP_QML) def test_fd_booster_e(self, sighup = True): """ File descriptor test for booster-e """ - count = get_file_descriptor("booster-e", "e", "fala_ft_hello") + self._check_changed_fd_count("e", PREFERED_APP) + + def _check_changed_fd_count(self, btype, app_name, sighup = True): + """ + To test that file descriptors are closed before calling application main + """ + #get fd of booster before launching application + debug("get fd of booster before launching application") + pid = get_pid('booster-%s'%btype) + init = get_fd_dict(pid) + debug("\nThe initial file descriptors are : %s\n" %init) + + #launch application using booster + debug("kill %s if it already exists" % app_name) + kill_process(app_name) + time.sleep(1) # give sometime for app to get killed + debug("launch %s using booster" % app_name) + st = os.system('invoker --type=%s --no-wait %s' % (btype, app_name)) + self.assert_(st == 0, "failed to start %s,%s" % (app_name,st)) + + # wait for new booster and app to start + wait_for_app(app_name) + + #get fd of booster after launching the application + debug("get fd of booster after launching the application") + final = get_fd_dict(pid) + debug("\nThe final file descriptors are : %s\n" %final) + pid = get_pid(app_name) + + mykeys = init.keys() + count = 0 + + for key in mykeys: + try: + if init[key] != final[key]: + count = count + 1 + except KeyError: + print "some key in init is not in final" + + debug("The number of changed file descriptors %d" %count) + kill_process(apppid=pid) self.assert_(count != 0, "None of the file descriptors were changed") + if(sighup): self.sighup_applauncherd() - self.test_fd_booster_e(False) + self._check_changed_fd_count(btype, app_name, False) def test_restart_booster(self, sighup = True): """ @@ -974,11 +1003,11 @@ class launcher_tests (unittest.TestCase): """ Test that applaucher-d is reinitilized afret sighup has been resived. This means - - applaucherd is not killed just reinitilized + - applauncherd is not killed just reinitilized - killing old boosters and creating new one - not other child processes should be killed """ - daemonPid = wait_for_app('applauncherd', 10) + daemonPid = wait_for_single_applauncherd() appList = [] @@ -987,22 +1016,23 @@ class launcher_tests (unittest.TestCase): p = run_app_as_user_with_invoker(app, booster = btype) pid = wait_for_app(app, timeout = 10, sleep = 1) if pid == None: - self.fail("%s was not launched using applauncherd") + self.fail("%s was not launched using applauncherd" % app) appList.append((pid, app)) boosterPid = wait_for_app("booster-%s" %(btype)) # send SIGHUP signal to applaucherd: + oldBoosters = get_pid('booster') kill_process(apppid=daemonPid, signum=1) - time.sleep(5) + wait_for_new_boosters(oldBoosters) - self.assertNotEqual(wait_for_app("booster-%s" %(btype)), boosterPid, "Booster should be restarted by applaucherd with SIGHUP.") - self.assertEqual(wait_for_app('applauncherd', 10), daemonPid, "applaucherd shouldn't be restarted after reciving SIGHUP.") + self.assertNotEqual(wait_for_app("booster-%s" %(btype)), boosterPid, "Booster should be restarted by applauncherd with SIGHUP.") + self.assertEqual(wait_for_single_applauncherd(), daemonPid, "applauncherd shouldn't be restarted after reciving SIGHUP.") for pid in appList : state = process_state(pid[0]) self.assertNotEqual(state, None, - "Child process '%s' PID=%s has been killed after applaucherd recived SIGHUP!" %(pid[1], pid[0])) + "Child process '%s' PID=%s has been killed after applauncherd recived SIGHUP!" %(pid[1], pid[0])) finally: for pid in appList: kill_process(apppid = pid[0]) @@ -1016,9 +1046,13 @@ class launcher_tests (unittest.TestCase): debug('Uninstallation of "%s" was successful' %(packageName)) def _wait_and_check_for_new_boosters(self, oldBoosterPids, oldApplauncherPid): - wait_for_new_boosters(oldBoosterPids) - wait_for_single_applauncherd() - newBoosterPids = get_booster_pid() + oldBoosters = set(oldBoosterPids) + newBoosterPids = None + for i in range(3) : + tmp = get_booster_pid() + if len(oldBoosters & set(tmp))==0 : + newBoosterPids = tmp + time.sleep(1) num_of_same_pids = len(set(oldBoosterPids) & set(newBoosterPids)) self.assertEqual(num_of_same_pids, 0, "Boosters pids did not change") diff --git a/tests/harmattan/testscripts/test-invoker.py b/tests/harmattan/testscripts/test-invoker.py index 4ef16f8..a8a7495 100644 --- a/tests/harmattan/testscripts/test-invoker.py +++ b/tests/harmattan/testscripts/test-invoker.py @@ -557,7 +557,7 @@ class InvokerTests(unittest.TestCase): Test that invoker searches the application through relative path """ os.system("(cd /usr;export PATH=bin;/usr/bin/invoker --type=m fala_wl&)") - pid = get_pid("fala_wl") + pid = wait_for_app("fala_wl") kill_process("fala_wl") self.assert_(pid != None ,"The application was not launched") diff --git a/tests/harmattan/testscripts/utils.py b/tests/harmattan/testscripts/utils.py index 786343a..46088a0 100644 --- a/tests/harmattan/testscripts/utils.py +++ b/tests/harmattan/testscripts/utils.py @@ -298,53 +298,15 @@ def launch_and_get_creds(path): return creds -def get_file_descriptor(booster, type, app_name): - """ - To test that file descriptors are closed before calling application main - """ - #get fd of booster before launching application - debug("get fd of booster before launching application") - pid = commands.getoutput("pgrep '%s$'" %booster) - fd_info = commands.getoutput('ls -l /proc/%s/fd/' % str(pid)) - fd_info = fd_info.split('\n') - init = {} - final = {} - +# returns the fd list of a process as a dict +def get_fd_dict(pid): + fd_dict = {} + fd_info = commands.getoutput('ls -l /proc/%s/fd/' % pid).splitlines() for fd in fd_info: if "->" in fd: - init[fd.split(" -> ")[0].split(' ')[-1]] = fd.split(" -> ")[-1] - debug("\nThe initial file descriptors are : %s\n" %init) - - #launch application using booster - debug("launch %s using booster" % app_name) - st = os.system('invoker --type=%s --no-wait /usr/bin/%s' % (type, app_name)) - time.sleep(4) - - #get fd of booster after launching the application - debug("get fd of booster after launching the application") - if st == 0: - fd_info = commands.getoutput('ls -l /proc/%s/fd/' % str(pid)) - fd_info = fd_info.split('\n') - for fd in fd_info: - if "->" in fd: - final[fd.split(" -> ")[0].split(' ')[-1]] = fd.split(" -> ")[-1] - debug("\nThe final file descriptors are : %s\n" %final) - pid = commands.getoutput('pgrep %s' % app_name) - - mykeys = init.keys() - count = 0 - - for key in mykeys: - try: - if init[key] != final[key]: - count = count + 1 - except KeyError: - print "some key in init is not in final" - time.sleep(4) - debug("The number of changed file descriptors %d" %count) - kill_process(apppid=pid) - return count - + fd_dict[fd.split(" -> ")[0].split(' ')[-1]] = fd.split(" -> ")[-1] + return fd_dict + def get_groups_for_user(): # get supplementary groups user belongs to (doesn't return # the gid group) @@ -356,6 +318,7 @@ def get_groups_for_user(): return groups #checks if there is a change in booster pids until 5 seconds +# the param must be a string - output of get_pid('booster') def wait_for_new_boosters(old_booster_pids): new_booster_pids = old_booster_pids for count in range(4):