diff options
author | lmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4> | 2009-10-13 19:41:48 +0000 |
---|---|---|
committer | lmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4> | 2009-10-13 19:41:48 +0000 |
commit | ab1c591d757b17ebb7dc45f4c5d12f8ced375db4 (patch) | |
tree | 3ca0863090e3f7408536c099d3374a3b2ece1438 | |
parent | bfa93c279d74ef681e3878db9f611c03b7fefa30 (diff) |
Crash handling system: Move it to client side code
It's undesirable to have crash handling setup on server
side testing, hence make the methods that do the actual
work as empty stubs in the common test code, and move
these methods to the client test definition, this way
setup will happen only on client side tests.
Thanks for jadmanski for helping me to figure out how
to do this properly.
Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
git-svn-id: svn://test.kernel.org/autotest/trunk@3841 592f7852-d20e-0410-864c-8624ca9c26a4
-rwxr-xr-x | client/bin/test.py | 63 | ||||
-rw-r--r-- | client/common_lib/test.py | 56 |
2 files changed, 63 insertions, 56 deletions
diff --git a/client/bin/test.py b/client/bin/test.py index ba51e56d..13e1458d 100755 --- a/client/bin/test.py +++ b/client/bin/test.py @@ -18,7 +18,7 @@ # src eg. tests/<test>/src # tmpdir eg. tmp/<testname.tag> -import os, traceback, sys, shutil +import os, traceback, sys, shutil, logging, resource, glob from autotest_lib.client.common_lib import error, utils from autotest_lib.client.common_lib import test as common_test @@ -26,7 +26,66 @@ from autotest_lib.client.bin import sysinfo class test(common_test.base_test): - pass + # Segmentation fault handling is something that is desirable only for + # client side tests. + def configure_crash_handler(self): + """ + Configure the crash handler by: + * Setting up core size to unlimited + * Putting an appropriate crash handler on /proc/sys/kernel/core_pattern + * Create files that the crash handler will use to figure which tests + are active at a given moment + + The crash handler will pick up the core file and write it to + self.debugdir, and perform analysis on it to generate a report. The + program also outputs some results to syslog. + + If multiple tests are running, an attempt to verify if we still have + the old PID on the system process table to determine whether it is a + parent of the current test execution. If we can't determine it, the + core file and the report file will be copied to all test debug dirs. + """ + self.pattern_file = '/proc/sys/kernel/core_pattern' + try: + # Enable core dumps + resource.setrlimit(resource.RLIMIT_CORE, (-1, -1)) + # Trying to backup core pattern and register our script + self.core_pattern_backup = open(self.pattern_file, 'r').read() + pattern_file = open(self.pattern_file, 'w') + tools_dir = os.path.join(self.autodir, 'tools') + crash_handler_path = os.path.join(tools_dir, 'crash_handler.py') + pattern_file.write('|' + crash_handler_path + ' %p %t %u %s %h %e') + # Writing the files that the crash handler is going to use + self.debugdir_tmp_file = ('/tmp/autotest_results_dir.%s' % + os.getpid()) + utils.open_write_close(self.debugdir_tmp_file, self.debugdir + "\n") + except Exception, e: + self.crash_handling_enabled = False + logging.error('Crash handling system disabled: %s' % e) + else: + self.crash_handling_enabled = True + logging.debug('Crash handling system enabled.') + + + def crash_handler_report(self): + """ + If core dumps are found on the debugdir after the execution of the + test, let the user know. + """ + if self.crash_handling_enabled: + core_dirs = glob.glob('%s/crash.*' % self.debugdir) + if core_dirs: + logging.warning('Programs crashed during test execution:') + for dir in core_dirs: + logging.warning('Please verify %s for more info', dir) + # Remove the debugdir info file + os.unlink(self.debugdir_tmp_file) + # Restore the core pattern backup + try: + utils.open_write_close(self.pattern_file, + self.core_pattern_backup) + except EnvironmentError: + pass def runtest(job, url, tag, args, dargs): diff --git a/client/common_lib/test.py b/client/common_lib/test.py index e948e1c8..b99c853f 100644 --- a/client/common_lib/test.py +++ b/client/common_lib/test.py @@ -55,63 +55,11 @@ class base_test: def configure_crash_handler(self): - """ - Configure the crash handler by: - * Setting up core size to unlimited - * Putting an appropriate crash handler on /proc/sys/kernel/core_pattern - * Create files that the crash handler will use to figure which tests - are active at a given moment - - The crash handler will pick up the core file and write it to - self.debugdir, and perform analysis on it to generate a report. The - program also outputs some results to syslog. - - If multiple tests are running, an attempt to verify if we still have - the old PID on the system process table to determine whether it is a - parent of the current test execution. If we can't determine it, the - core file and the report file will be copied to all test debug dirs. - """ - self.pattern_file = '/proc/sys/kernel/core_pattern' - try: - # Enable core dumps - resource.setrlimit(resource.RLIMIT_CORE, (-1, -1)) - # Trying to backup core pattern and register our script - self.core_pattern_backup = open(self.pattern_file, 'r').read() - pattern_file = open(self.pattern_file, 'w') - tools_dir = os.path.join(self.autodir, 'tools') - crash_handler_path = os.path.join(tools_dir, 'crash_handler.py') - pattern_file.write('|' + crash_handler_path + ' %p %t %u %s %h %e') - # Writing the files that the crash handler is going to use - self.debugdir_tmp_file = ('/tmp/autotest_results_dir.%s' % - os.getpid()) - utils.open_write_close(self.debugdir_tmp_file, self.debugdir + "\n") - except Exception, e: - self.crash_handling_enabled = False - logging.error('Crash handling system disabled: %s' % e) - else: - self.crash_handling_enabled = True - logging.debug('Crash handling system enabled.') + pass def crash_handler_report(self): - """ - If core dumps are found on the debugdir after the execution of the - test, let the user know. - """ - if self.crash_handling_enabled: - core_dirs = glob.glob('%s/crash.*' % self.debugdir) - if core_dirs: - logging.warning('Programs crashed during test execution:') - for dir in core_dirs: - logging.warning('Please verify %s for more info', dir) - # Remove the debugdir info file - os.unlink(self.debugdir_tmp_file) - # Restore the core pattern backup - try: - utils.open_write_close(self.pattern_file, - self.core_pattern_backup) - except EnvironmentError: - pass + pass def assert_(self, expr, msg='Assertion failed.'): |