mbligh | 2bbfa96 | 2009-03-17 17:55:32 +0000 | [diff] [blame^] | 1 | import os, shutil, glob |
| 2 | from autotest_lib.client.bin import test, utils |
| 3 | from autotest_lib.client.common_lib import error |
| 4 | |
| 5 | |
| 6 | class cerberus(test.test): |
| 7 | """ |
| 8 | This autotest module runs CTCS (Cerberus Test Control System). This test |
| 9 | suite was developed for the now extinct VA Linux's manufacturing system |
| 10 | it has several hardware and software stress tests that can be run in |
| 11 | parallel. It does have a control file system that allows testers to specify |
| 12 | the sorts of tests that they want to see executed. It's an excelent stress |
| 13 | test for hardware and kernel. |
| 14 | |
| 15 | @author Manas Kumar Nayak (maknayak@in.ibm.com) (original code) |
| 16 | @author Lucas Meneghel Rodrigues (lucasmr@br.ibm.com) (rewrite) |
| 17 | """ |
| 18 | |
| 19 | version = 1 |
| 20 | def initialize(self): |
| 21 | """ |
| 22 | Sets the overall failure counter for the test. |
| 23 | """ |
| 24 | self.nfail = 0 |
| 25 | |
| 26 | |
| 27 | def setup(self, tarball='ctcs-1.3.1pre1.tar.bz2', length = '4h', |
| 28 | tcf_contents=None): |
| 29 | """ |
| 30 | Builds the test suite, and sets up the control file that is going to |
| 31 | be processed by the ctcs engine. |
| 32 | @param tarball: CTCS tarball |
| 33 | @param length: The amount of time we'll run the test suite |
| 34 | @param tcf_contents: If the user wants to specify the contents of |
| 35 | the CTCS control file, he could do so trough this parameter. If |
| 36 | this parameter is provided, length is ignored. |
| 37 | """ |
| 38 | cerberus_tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) |
| 39 | utils.extract_tarball_to_dir(cerberus_tarball, self.srcdir) |
| 40 | |
| 41 | os.chdir(self.srcdir) |
| 42 | # Apply patch to fix build problems on newer distros (absence of |
| 43 | # asm/page.h include. |
| 44 | utils.system('patch -p1 < ../fix-ctcs-build.patch') |
| 45 | utils.system('make') |
| 46 | |
| 47 | # Here we define the cerberus suite control file that will be used. |
| 48 | # It will be kept on the debug directory for further analysis. |
| 49 | self.tcf_path = os.path.join(self.debugdir, 'autotest.tcf') |
| 50 | |
| 51 | if not tcf_contents: |
| 52 | print 'Generating cerberus control file' |
| 53 | # Note about the control file generation command - we are creating |
| 54 | # a control file with the default tests, except for the kernel |
| 55 | # compilation test (flag -k). |
| 56 | g_cmd = './newburn-generator -k %s> %s' % (length, self.tcf_path) |
| 57 | utils.system(g_cmd) |
| 58 | else: |
| 59 | print 'TCF file contents supplied, ignoring test length altogether' |
| 60 | tcf = open(self.tcf_path, 'w') |
| 61 | tcf.write(tcf_contents) |
| 62 | |
| 63 | print "Contents of the control file that will be passed to ctcs:" |
| 64 | tcf = open(self.tcf_path, 'r') |
| 65 | buf = tcf.read() |
| 66 | print buf |
| 67 | |
| 68 | |
| 69 | def run_once(self): |
| 70 | """ |
| 71 | Runs the test, with the appropriate control file. |
| 72 | """ |
| 73 | os.chdir(self.srcdir) |
| 74 | try: |
| 75 | utils.system('./run %s' % self.tcf_path) |
| 76 | except: |
| 77 | self.nfail += 1 |
| 78 | # After we are done with this iterations, we move the log files to |
| 79 | # the results dir |
| 80 | log_base_path = os.path.join(self.srcdir, 'log') |
| 81 | log_dir = glob.glob(os.path.join(log_base_path, |
| 82 | 'autotest.tcf.log.*'))[0] |
| 83 | print 'Copying %s log directory to results dir' % log_dir |
| 84 | dst = os.path.join(self.resultsdir, os.path.basename(log_dir)) |
| 85 | shutil.move(log_dir, dst) |
| 86 | |
| 87 | |
| 88 | def cleanup(self): |
| 89 | """ |
| 90 | Cleans up source directory and raises on failure. |
| 91 | """ |
| 92 | if os.path.isdir(self.srcdir): |
| 93 | shutil.rmtree(self.srcdir) |
| 94 | if self.nfail != 0: |
| 95 | raise error.TestFail('Cerberus test suite failed.') |