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