summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/devkit/tests')
-rwxr-xr-xcleopatre/devkit/tests/fw_wd/run-test38
1 files changed, 31 insertions, 7 deletions
diff --git a/cleopatre/devkit/tests/fw_wd/run-test b/cleopatre/devkit/tests/fw_wd/run-test
index 5008933233..ce1d77218e 100755
--- a/cleopatre/devkit/tests/fw_wd/run-test
+++ b/cleopatre/devkit/tests/fw_wd/run-test
@@ -5,6 +5,7 @@ from os import symlink, mkdir, chmod
import sys
import subprocess
import gzip
+import time
busybox_path = '../common/busybox/busybox'
fw_wd_path = '../../../application/fw_wd'
@@ -35,6 +36,16 @@ echo "fw_wd run"
exit %(retcode)s
"""
+fw_wd_wait_stub = """\
+#!/bin/sh
+echo "fw_wd run"
+trap : TERM
+sleep 100 &
+pid=$!
+wait $pid
+kill $pid
+"""
+
reboot_stub = """\
#!/bin/sh
echo "reboot run"
@@ -70,6 +81,7 @@ class TestParams:
self.trace_cmds_test = False
self.trace_dir = True
self.old_traces = [ ]
+ self.kill = False
self.__dict__.update(kw)
def chroot_call(root_path, command):
@@ -100,10 +112,15 @@ def create_rootfs(root_path, test_params):
symlink('/bin/busybox', root_path + '/proc/self/exe')
chroot_call(root_path, [ '/bin/busybox', '--install', '-s' ])
copy(fw_wd_path + '/fwwatchd', root_path + '/usr/bin')
+ create_file(root_path, '/dev/null', '')
# Create test stubs.
- create_file(root_path, '/usr/bin/fw_wd',
- fw_wd_stub % { 'retcode': test_params.fw_wd_retcode },
- executable=True)
+ if not test_params.kill:
+ create_file(root_path, '/usr/bin/fw_wd',
+ fw_wd_stub % { 'retcode': test_params.fw_wd_retcode },
+ executable=True)
+ else:
+ create_file(root_path, '/usr/bin/fw_wd', fw_wd_wait_stub,
+ executable=True)
create_file(root_path, '/sbin/reboot',
reboot_stub % { 'retcode': test_params.reboot_retcode },
executable=True)
@@ -135,7 +152,7 @@ def check(root_path, test_params, stdout):
expected_stdout = ''
else:
expected_stdout = 'fw_wd run\n'
- if test_params.fw_wd_retcode == 0:
+ if test_params.fw_wd_retcode == 0 and not test_params.kill:
if test_params.reboot:
expected_stdout += 'reboot run\n'
if test_params.reboot_retcode == 0:
@@ -147,7 +164,8 @@ def check(root_path, test_params, stdout):
# Check trace file.
expected_trace = ''
expected_last_head_trace = ''
- if test_params.trace_enabled and test_params.fw_wd_retcode == 0:
+ if test_params.trace_enabled and test_params.fw_wd_retcode == 0 \
+ and not test_params.kill:
if test_params.trace_present:
expected_last_head_trace = \
'\n'.join(trace_content.split('\n')[0:3]) + '\n'
@@ -188,9 +206,13 @@ def run_test(root_path, test_params):
"""Run FW watch daemon in a chrooted environment and check result. Return
a number of failed test."""
create_rootfs('root', test_params)
- stdout = subprocess.Popen([ 'fakechroot', '/usr/sbin/chroot', root_path,
+ proc = subprocess.Popen([ 'fakechroot', '/usr/sbin/chroot', root_path,
'/usr/bin/fwwatchd' ], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- env=chroot_env).communicate()[0]
+ env=chroot_env)
+ if test_params.kill:
+ time.sleep(0.1)
+ proc.terminate()
+ stdout = proc.communicate()[0]
result = check('root', test_params, stdout)
return 0 if result else 1
@@ -201,6 +223,8 @@ if __name__ == '__main__':
# Watchdog test.
tp = TestParams("fw_wd fail", fw_wd_retcode=1)
failed += run_test('root', tp)
+ tp = TestParams("kill script", kill=True)
+ failed += run_test('root', tp)
# Trace tests.
tp = TestParams("trace disabled", trace_enabled=False)
failed += run_test('root', tp)