• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging
6import os
7
8from autotest_lib.client.bin import test, utils
9from autotest_lib.client.common_lib import file_utils
10from autotest_lib.client.common_lib import logging_manager
11
12
13class platform_Crouton(test.test):
14    """
15    Tests crouton
16    """
17    version = 1
18
19
20    def _parse_args(self, args):
21        self._repo = "dnschneid/crouton"
22        self._branch = "master"
23        self._runargs = "00"
24        self._env = ""
25
26        for option_name, value in args.iteritems():
27            if option_name == 'repo':
28                self._repo = value
29            elif option_name == 'branch':
30                self._branch = value
31            elif option_name == 'runargs':
32                self._runargs = value
33            elif option_name == 'env':
34                self._env = value
35
36
37    def run_once(self, args={}):
38        self._parse_args(args)
39
40        logging.info("Running crouton test:")
41        logging.info(" - repo: %s", self._repo);
42        logging.info(" - branch: %s", self._branch);
43        logging.info(" - runargs: %s", self._runargs);
44        logging.info(" - env:%s", self._env);
45        logging.debug(" - resultsdir: %s", self.resultsdir)
46        logging.debug(' - tmpdir: %s', self.tmpdir)
47
48        crouton_temp_file = os.path.join(self.tmpdir, "archive.tar.gz")
49        crouton_url = 'https://github.com/%s/archive/%s.tar.gz' \
50                                            % (self._repo, self._branch)
51
52        logging.info('Downloading crouton tarball: "%s".', crouton_url)
53        file_utils.download_file(crouton_url, crouton_temp_file)
54
55        os.chdir(self.tmpdir)
56        utils.system('tar xvf %s --strip-components 1' % crouton_temp_file)
57
58        # Set environment. Only allow setting CROUTON_MIRROR_* variables
59        for env_pair in self._env.split(";"):
60            keyval = env_pair.split("=")
61            if len(keyval) == 2 and keyval[0].find("CROUTON_MIRROR_") == 0:
62                logging.debug('Setting env %s=%s', keyval[0], keyval[1])
63                os.environ[keyval[0]] = keyval[1]
64
65        # Pass arguments separately to avoid problems with Little Bobby Tables.
66        args = ['test/run.sh', '-l', self.resultsdir] + self._runargs.split()
67        utils.run('sh', args=args,
68                  timeout=None, ignore_status=False,
69                  stderr_tee=logging_manager.LoggingFile(level=logging.INFO))
70
71
72    def cleanup(self):
73        # Reset hung task panic, see crbug.com/420094
74        utils.system('echo 1 > /proc/sys/kernel/hung_task_panic')
75