aboutsummaryrefslogtreecommitdiff
path: root/dejagnu/run_dejagnu.py
diff options
context:
space:
mode:
Diffstat (limited to 'dejagnu/run_dejagnu.py')
-rwxr-xr-xdejagnu/run_dejagnu.py141
1 files changed, 79 insertions, 62 deletions
diff --git a/dejagnu/run_dejagnu.py b/dejagnu/run_dejagnu.py
index 5506d0c0..1aea31a7 100755
--- a/dejagnu/run_dejagnu.py
+++ b/dejagnu/run_dejagnu.py
@@ -1,7 +1,6 @@
#!/usr/bin/python
#
# Copyright 2010 Google Inc. All Rights Reserved.
-
"""Tool script for auto dejagnu."""
__author__ = 'shenhan@google.com (Han Shen)'
@@ -31,9 +30,13 @@ def ProcessArguments(argv):
'Launches gcc dejagnu test in chroot for chromeos toolchain, compares '
'the test result with a repository baseline and prints out the result.'),
usage='run_dejagnu options')
- parser.add_option('-c', '--chromeos_root', dest='chromeos_root',
+ parser.add_option('-c',
+ '--chromeos_root',
+ dest='chromeos_root',
help='Required. Specify chromeos root')
- parser.add_option('-m', '--mount', dest='mount',
+ parser.add_option('-m',
+ '--mount',
+ dest='mount',
help=('Specify gcc source to mount instead of "auto". '
'Under "auto" mode, which is the default - gcc is '
'checked out and built automatically at default '
@@ -45,25 +48,39 @@ def ProcessArguments(argv):
'"${gcc_source_dir}-build-${ctarget}". In this mode, '
'a complete gcc build must be performed in the '
'computed gcc-build-dir beforehand.'))
- parser.add_option('-b', '--board', dest='board',
+ parser.add_option('-b',
+ '--board',
+ dest='board',
help=('Required. Specify board.'))
- parser.add_option('-r', '--remote', dest='remote',
+ parser.add_option('-r',
+ '--remote',
+ dest='remote',
help=('Required. Specify addresses/names of the board, '
'seperate each address/name using comma(\',\').'))
- parser.add_option('-f', '--flags', dest='flags',
+ parser.add_option('-f',
+ '--flags',
+ dest='flags',
help='Optional. Extra run test flags to pass to dejagnu.')
- parser.add_option('-k', '--keep', dest='keep_intermediate_files',
- action='store_true', default=False,
+ parser.add_option('-k',
+ '--keep',
+ dest='keep_intermediate_files',
+ action='store_true',
+ default=False,
help=('Optional. Default to false. Do not remove dejagnu '
'intermediate files after test run.'))
- parser.add_option('--cleanup', dest='cleanup', default=None,
+ parser.add_option('--cleanup',
+ dest='cleanup',
+ default=None,
help=('Optional. Values to this option could be '
'\'mount\' (unmount gcc source and '
'directory directory, '
'only valid when --mount is given), '
'\'chroot\' (delete chroot) and '
'\'chromeos\' (delete the whole chromeos tree).'))
- parser.add_option('-t', '--tools', dest='tools', default='gcc,g++',
+ parser.add_option('-t',
+ '--tools',
+ dest='tools',
+ default='gcc,g++',
help=('Optional. Specify which tools to check, using '
'","(comma) as separator. A typical value would be '
'"g++" so that only g++ tests are performed. '
@@ -92,8 +109,8 @@ def ProcessArguments(argv):
class DejagnuExecuter(object):
"""The class wrapper for dejagnu test executer."""
- def __init__(self, base_dir, mount, chromeos_root, remote, board,
- flags, keep_intermediate_files, tools, cleanup):
+ def __init__(self, base_dir, mount, chromeos_root, remote, board, flags,
+ keep_intermediate_files, tools, cleanup):
self._l = logger.GetLogger()
self._chromeos_root = chromeos_root
self._chromeos_chroot = path.join(chromeos_root, 'chroot')
@@ -118,8 +135,9 @@ class DejagnuExecuter(object):
self._cleanup = cleanup
def SetupTestingDir(self):
- self._tmp_abs = tempfile.mkdtemp(prefix='dejagnu_', dir=path.join(
- self._chromeos_chroot, 'tmp'))
+ self._tmp_abs = tempfile.mkdtemp(
+ prefix='dejagnu_',
+ dir=path.join(self._chromeos_chroot, 'tmp'))
self._tmp = self._tmp_abs[len(self._chromeos_chroot):]
self._tmp_testing_rsa = path.join(self._tmp, 'testing_rsa')
self._tmp_testing_rsa_abs = path.join(self._tmp_abs, 'testing_rsa')
@@ -131,15 +149,15 @@ class DejagnuExecuter(object):
if self._tmp_abs and path.isdir(self._tmp_abs):
if self._keep_intermediate_files:
self._l.LogOutput(
- 'Your intermediate dejagnu files are kept, you can re-run '
- 'inside chroot the command:')
+ 'Your intermediate dejagnu files are kept, you can re-run '
+ 'inside chroot the command:')
self._l.LogOutput(
' DEJAGNU={0} make -C {1} {2} RUNTESTFLAGS="--target_board={3} {4}"' \
.format(path.join(self._tmp, 'site.exp'), self._gcc_build_dir,
self.MakeCheckString(), self._board, self._flags))
else:
- self._l.LogOutput(
- '[Cleanup] - Removing temp dir - {0}'.format(self._tmp_abs))
+ self._l.LogOutput('[Cleanup] - Removing temp dir - {0}'.format(
+ self._tmp_abs))
shutil.rmtree(self._tmp_abs)
def Cleanup(self):
@@ -158,20 +176,20 @@ class DejagnuExecuter(object):
if self._cleanup == 'chroot' or self._cleanup == 'chromeos':
self._l.LogOutput('[Cleanup]: Deleting chroot inside \'{0}\''.format(
- self._chromeos_root))
- command = "cd %s; cros_sdk --delete" % self._chromeos_root
+ self._chromeos_root))
+ command = 'cd %s; cros_sdk --delete' % self._chromeos_root
rv = self._executer.RunCommand(command)
if rv:
self._l.LogWarning('Warning - failed to delete chroot.')
# Delete .cache - crosbug.com/34956
- command = "sudo rm -fr %s" % os.path.join(self._chromeos_root, ".cache")
+ command = 'sudo rm -fr %s' % os.path.join(self._chromeos_root, '.cache')
rv = self._executer.RunCommand(command)
if rv:
self._l.LogWarning('Warning - failed to delete \'.cache\'.')
if self._cleanup == 'chromeos':
self._l.LogOutput('[Cleanup]: Deleting chromeos tree \'{0}\' ...'.format(
- self._chromeos_root))
+ self._chromeos_root))
command = 'rm -fr {0}'.format(self._chromeos_root)
rv = self._executer.RunCommand(command)
if rv:
@@ -179,10 +197,10 @@ class DejagnuExecuter(object):
def PrepareTestingRsaKeys(self):
if not path.isfile(self._tmp_testing_rsa_abs):
- shutil.copy(path.join(
- self._chromeos_root,
- 'src/scripts/mod_for_test_scripts/ssh_keys/testing_rsa'),
- self._tmp_testing_rsa_abs)
+ shutil.copy(
+ path.join(self._chromeos_root,
+ 'src/scripts/mod_for_test_scripts/ssh_keys/testing_rsa'),
+ self._tmp_testing_rsa_abs)
os.chmod(self._tmp_testing_rsa_abs, stat.S_IRUSR)
def PrepareTestFiles(self):
@@ -197,7 +215,8 @@ class DejagnuExecuter(object):
'__boardname__': self._board,
'__board_hostname__': self._remote,
'__tmp_testing_rsa__': self._tmp_testing_rsa,
- '__tmp_dir__': self._tmp})
+ '__tmp_dir__': self._tmp
+ })
for pat, sub in substitutions.items():
content = content.replace(pat, sub)
@@ -233,9 +252,9 @@ class DejagnuExecuter(object):
'sudo mkdir -p {0}'.format(self._gcc_source_dir_abs)):
raise Exception("Failed to create \'{0}\' inside chroot.".format(
self._gcc_source_dir))
- if not (path.isdir(self._gcc_source_dir_to_mount) and path.isdir(
- path.join(self._gcc_source_dir_to_mount, 'gcc'))):
- raise Exception("{0} is not a valid gcc source tree.".format(
+ if not (path.isdir(self._gcc_source_dir_to_mount) and
+ path.isdir(path.join(self._gcc_source_dir_to_mount, 'gcc'))):
+ raise Exception('{0} is not a valid gcc source tree.'.format(
self._gcc_source_dir_to_mount))
# We have these build directories -
@@ -254,7 +273,7 @@ class DejagnuExecuter(object):
self._gcc_build_dir_to_mount = '{0}-build-{1}'.format(
self._gcc_source_dir_to_mount, self._target)
self._gcc_top_build_dir_abs = path.join(self._chromeos_chroot,
- self._gcc_top_build_dir.lstrip('/'))
+ self._gcc_top_build_dir.lstrip('/'))
if not path.isdir(self._gcc_top_build_dir_abs) and \
self._executer.RunCommand(
'sudo mkdir -p {0}'.format(self._gcc_top_build_dir_abs)):
@@ -271,8 +290,7 @@ class DejagnuExecuter(object):
def PrepareGccDefault(self):
"""Auto emerging gcc for building purpose only."""
ret = self._executer.ChrootRunCommandWOutput(
- self._chromeos_root,
- 'equery w cross-%s/gcc' % self._target)[1]
+ self._chromeos_root, 'equery w cross-%s/gcc' % self._target)[1]
ret = path.basename(ret.strip())
# ret is expected to be something like 'gcc-4.6.2-r11.ebuild' or
# 'gcc-9999.ebuild' parse it.
@@ -285,19 +303,18 @@ class DejagnuExecuter(object):
else:
raise Exception('Failed to get gcc version.')
- gcc_portage_dir = '/var/tmp/portage/cross-%s/%s/work' % (
- self._target, gccrevision)
+ gcc_portage_dir = '/var/tmp/portage/cross-%s/%s/work' % (self._target,
+ gccrevision)
self._gcc_source_dir = path.join(gcc_portage_dir, gccversion)
self._gcc_top_build_dir = (gcc_portage_dir + '/%s-build-%s') % (
gccversion, self._target)
self._gcc_build_dir = path.join(self._gcc_top_build_dir, 'gcc')
- gcc_build_dir_abs = path.join(
- self._chromeos_root, 'chroot', self._gcc_build_dir.lstrip('/'))
+ gcc_build_dir_abs = path.join(self._chromeos_root, 'chroot',
+ self._gcc_build_dir.lstrip('/'))
if not path.isdir(gcc_build_dir_abs):
- ret = self._executer.ChrootRunCommand(
- self._chromeos_root,
- ('ebuild $(equery w cross-%s/gcc) clean prepare compile' % (
- self._target)))
+ ret = self._executer.ChrootRunCommand(self._chromeos_root, (
+ 'ebuild $(equery w cross-%s/gcc) clean prepare compile' % (
+ self._target)))
if ret:
raise Exception('ebuild gcc failed.')
@@ -313,11 +330,10 @@ class DejagnuExecuter(object):
validate_failures_py = path.join(
self._gcc_source_dir,
'contrib/testsuite-management/validate_failures.py')
- cmd = 'cd {0} ; {1} --build_dir={0}'.format(
- self._gcc_top_build_dir, validate_failures_py)
+ cmd = 'cd {0} ; {1} --build_dir={0}'.format(self._gcc_top_build_dir,
+ validate_failures_py)
self.MountGccSourceAndBuildDir()
- ret = self._executer.ChrootRunCommandWOutput(
- self._chromeos_root, cmd)
+ ret = self._executer.ChrootRunCommandWOutput(self._chromeos_root, cmd)
if ret[0] != 0:
self._l.LogWarning('*** validate_failures.py exited with non-zero code,'
'please run it manually inside chroot - \n'
@@ -326,12 +342,12 @@ class DejagnuExecuter(object):
# This method ensures necessary mount points before executing chroot comamnd.
def MountGccSourceAndBuildDir(self, unmount=False):
- mount_points = [tc_enter_chroot.MountPoint(
- self._gcc_source_dir_to_mount, self._gcc_source_dir_abs,
- getpass.getuser(), "ro"),
- tc_enter_chroot.MountPoint(
- self._gcc_build_dir_to_mount, self._gcc_top_build_dir_abs,
- getpass.getuser(), "rw"),]
+ mount_points = [tc_enter_chroot.MountPoint(self._gcc_source_dir_to_mount,
+ self._gcc_source_dir_abs,
+ getpass.getuser(), 'ro'),
+ tc_enter_chroot.MountPoint(self._gcc_build_dir_to_mount,
+ self._gcc_top_build_dir_abs,
+ getpass.getuser(), 'rw')]
for mp in mount_points:
if unmount:
if mp.UnMount():
@@ -339,13 +355,14 @@ class DejagnuExecuter(object):
else:
self._l.LogOutput('{0} unmounted successfully.'.format(mp.mount_dir))
elif mp.DoMount():
- raise Exception('Failed to mount {0} onto {1}'.format(
- mp.external_dir, mp.mount_dir))
+ raise Exception('Failed to mount {0} onto {1}'.format(mp.external_dir,
+ mp.mount_dir))
else:
self._l.LogOutput('{0} mounted successfully.'.format(mp.mount_dir))
# The end of class DejagnuExecuter
+
def TryAcquireMachine(remotes):
available_machine = None
for r in remotes.split(','):
@@ -355,21 +372,20 @@ def TryAcquireMachine(remotes):
break
else:
logger.GetLogger().LogWarning(
- '*** Failed to lock machine \'{0}\'.'.format(r))
+ '*** Failed to lock machine \'{0}\'.'.format(r))
if not available_machine:
- raise Exception(
- "Failed to acquire one machine from \'{0}\'.".format(remotes))
+ raise Exception("Failed to acquire one machine from \'{0}\'.".format(
+ remotes))
return available_machine
+
def Main(argv):
opts = ProcessArguments(argv)
available_machine = TryAcquireMachine(opts.remote)
- executer = DejagnuExecuter(misc.GetRoot(argv[0])[0],
- opts.mount, opts.chromeos_root,
- available_machine._name,
- opts.board, opts.flags,
- opts.keep_intermediate_files, opts.tools,
- opts.cleanup)
+ executer = DejagnuExecuter(
+ misc.GetRoot(argv[0])[0], opts.mount, opts.chromeos_root,
+ available_machine._name, opts.board, opts.flags,
+ opts.keep_intermediate_files, opts.tools, opts.cleanup)
# Return value is a 3- or 4-element tuple
# element#1 - exit code
# element#2 - stdout
@@ -395,6 +411,7 @@ def Main(argv):
executer.Cleanup()
return ret
+
if __name__ == '__main__':
retval = Main(sys.argv)[0]
sys.exit(retval)