summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/tests/fw_wd/run-test
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/devkit/tests/fw_wd/run-test')
-rwxr-xr-xcleopatre/devkit/tests/fw_wd/run-test67
1 files changed, 65 insertions, 2 deletions
diff --git a/cleopatre/devkit/tests/fw_wd/run-test b/cleopatre/devkit/tests/fw_wd/run-test
index ce1d77218e..1116bfe391 100755
--- a/cleopatre/devkit/tests/fw_wd/run-test
+++ b/cleopatre/devkit/tests/fw_wd/run-test
@@ -1,7 +1,7 @@
#!/usr/bin/python
"""Test FW watch daemon."""
from shutil import copy, rmtree
-from os import symlink, mkdir, chmod
+from os import symlink, mkdir, chmod, listdir
import sys
import subprocess
import gzip
@@ -52,12 +52,28 @@ echo "reboot run"
exit %(retcode)s
"""
+df_stub = """\
+#!/bin/sh
+fs=%(fs_size_kb)d
+if test -d /usr/local/trace; then
+ set -- $(du -sk /usr/local/trace)
+ trace=$1
+else
+ trace=0
+fi
+free=$(expr $fs - $trace)
+echo "Filesystem 1k-blocks Used Available Use%% Mounted on"
+echo "/dev/mtdblock2 xxxx $trace $free yy%% /usr/local"
+"""
+
default_content = """\
REBOOT=%(reboot)s
TRACE_ENABLED=%(trace_enabled)s
TRACE_FOLDER="/usr/local/trace/"
TRACE_FILES="%(trace_files)s"
TRACE_CMDS="%(trace_cmds)s"
+TRACE_SIZE_LIMIT_KB=%(size_limit_kb)s
+TRACE_FREE_LIMIT_KB=%(free_limit_kb)s
"""
chroot_env = {
@@ -81,6 +97,11 @@ class TestParams:
self.trace_cmds_test = False
self.trace_dir = True
self.old_traces = [ ]
+ self.big_traces = [ ]
+ self.size_limit_kb = None
+ self.free_limit_kb = None
+ self.fs_size_kb = 1024
+ self.after_clean = None
self.kill = False
self.__dict__.update(kw)
@@ -112,6 +133,7 @@ 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')
+ copy(fw_wd_path + '/fwwatchd-clean', root_path + '/usr/bin')
create_file(root_path, '/dev/null', '')
# Create test stubs.
if not test_params.kill:
@@ -124,6 +146,9 @@ def create_rootfs(root_path, test_params):
create_file(root_path, '/sbin/reboot',
reboot_stub % { 'retcode': test_params.reboot_retcode },
executable=True)
+ create_file(root_path, '/bin/df',
+ df_stub % { 'fs_size_kb': test_params.fs_size_kb },
+ executable=True)
if test_params.trace_present:
create_file(root_path, '/dev/trace', trace_content)
for f in test_params.trace_files:
@@ -133,9 +158,13 @@ def create_rootfs(root_path, test_params):
for i in test_params.old_traces:
create_file(root_path, '/usr/local/trace/trace_%d.gz' % i,
'Old trace %d' % i)
+ for i, size in test_params.big_traces:
+ create_file(root_path, '/usr/local/trace/trace_%d.gz' % i, 'B' * size)
# Create default file.
def bool_value(b):
return 'true' if b else 'false'
+ def int_value(i):
+ return str(i) if i is not None else ''
def list_value(l):
return ':'.join(l)
create_file(root_path, '/etc/default/fwwatchd', default_content % {
@@ -143,6 +172,8 @@ def create_rootfs(root_path, test_params):
'trace_enabled': bool_value(test_params.trace_enabled),
'trace_files': list_value(test_params.trace_files),
'trace_cmds': list_value(trace_cmds[test_params.trace_cmds_test]),
+ 'size_limit_kb': int_value(test_params.size_limit_kb),
+ 'free_limit_kb': int_value(test_params.free_limit_kb),
})
def check(root_path, test_params, stdout):
@@ -179,7 +210,10 @@ def check(root_path, test_params, stdout):
expected_trace += "==== %s ====\n" % cmd
expected_trace += result
expected_trace += "\n"
- expected_trace_nb = max(test_params.old_traces + [ 0 ] ) + 1
+ max_big_trace = (max(test_params.big_traces, key=lambda x: x[0])[0]
+ if test_params.big_traces else 0)
+ expected_trace_nb = max(test_params.old_traces
+ + [ max_big_trace, 0 ]) + 1
expected_file_name = '/usr/local/trace/trace_%d.gz' % expected_trace_nb
try:
f = gzip.open(root_path + expected_file_name)
@@ -200,12 +234,26 @@ def check(root_path, test_params, stdout):
print test_params.test_name, \
"failed (can not open %s)" % expected_file_name
return False
+ if test_params.after_clean is not None:
+ traces = set(listdir(root_path + '/usr/local/trace'))
+ expected_traces = set('trace_%d.gz' % i
+ for i in test_params.after_clean)
+ if traces < expected_traces:
+ print test_params.test_name, \
+ "failed (should not be cleaned: %s)" % ' '.join(
+ expected_traces - traces)
+ elif traces > expected_traces:
+ print test_params.test_name, \
+ "failed (should be cleaned: %s)" % ' '.join(
+ traces - expected_traces)
return True
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)
+ subprocess.check_call([ 'fakechroot', '/usr/sbin/chroot', root_path,
+ '/usr/bin/fwwatchd-clean' ], env=chroot_env)
proc = subprocess.Popen([ 'fakechroot', '/usr/sbin/chroot', root_path,
'/usr/bin/fwwatchd' ], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=chroot_env)
@@ -238,6 +286,21 @@ if __name__ == '__main__':
failed += run_test('root', tp)
tp = TestParams("old traces", old_traces=[ 1, 2, 8 ])
failed += run_test('root', tp)
+ # Clean tests.
+ big_traces = [ (3, 2 * 1024), (4, 40 * 1024), (5, 50 * 1024),
+ (6, 2 * 1024) ]
+ tp = TestParams("clean: no limit", big_traces=big_traces, kill=True,
+ after_clean=[ 3, 4, 5, 6 ])
+ failed += run_test('root', tp)
+ tp = TestParams("clean: size limit", big_traces=big_traces, kill=True,
+ size_limit_kb=80, after_clean=[ 5, 6 ])
+ failed += run_test('root', tp)
+ tp = TestParams("clean: free limit", big_traces=big_traces, kill=True,
+ free_limit_kb=1024 - 80, after_clean=[ 5, 6 ])
+ failed += run_test('root', tp)
+ tp = TestParams("clean: can not help", big_traces=big_traces, kill=True,
+ free_limit_kb=2048, after_clean=[ ])
+ failed += run_test('root', tp)
# Reboot tests.
tp = TestParams("no reboot", reboot=False)
failed += run_test('root', tp)