• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import os, shutil, glob, logging
2from autotest_lib.client.bin import test, utils
3from autotest_lib.client.common_lib import error
4
5
6class ctcs(test.test):
7    """
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.
11
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)
22    @author Lucas Meneghel Rodrigues (lmr@redhat.com) (use ctcs new source repo)
23    @see: https://github.com/autotest/ctcs
24    """
25    version = 3
26
27    def initialize(self):
28        """
29        Sets the overall failure counter for the test.
30        """
31        self.nfail = 0
32
33
34    def setup(self, tarball='ctcs.tar.bz2', length='4h', tc_opt='-k',
35              tcf_contents=None):
36        """
37        Builds the test suite, and sets up the control file that is going to
38        be processed by the ctcs engine.
39        @param tarball: CTCS tarball
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
42                the CTCS control file, he could do so trough this parameter.
43                If this parameter is provided, length is ignored.
44        """
45        ctcs_tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
46        utils.extract_tarball_to_dir(ctcs_tarball, self.srcdir)
47
48        os.chdir(self.srcdir)
49        utils.make()
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:
56            logging.info('Generating CTCS control file')
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).
60            g_cmd = ('./newburn-generator %s %s> %s' %
61                     (tc_opt, length, self.tcf_path))
62            utils.system(g_cmd)
63        else:
64            logging.debug('TCF file contents supplied, ignoring test length'
65                          ' altogether')
66            tcf = open(self.tcf_path, 'w')
67            tcf.write(tcf_contents)
68
69        logging.debug('Contents of the control file that will be passed to '
70                      'CTCS:')
71        tcf = open(self.tcf_path, 'r')
72        buf = tcf.read()
73        logging.debug(buf)
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
85        log_base_path = os.path.join(self.srcdir, 'log')
86        log_dir = glob.glob(os.path.join(log_base_path,
87                                         'autotest.tcf.log.*'))[0]
88        logging.debug('Copying %s log directory to results dir', log_dir)
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:
100            raise error.TestFail('CTCS execution failed')
101