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)
    # Return value is a 3- or 4-element tuple
    #   element#1 - exit code
    #   element#2 - stdout
    #   element#3 - stderr
    #   element#4 - exception infor
    # Some other scripts need these detailed information.
    ret = (1, '', '')
    try:
        executer.SetupTestingDir()
        executer.PrepareTestingRsaKeys()
        executer.PrepareTestFiles()
        executer.PrepareGcc()
        executer.MakeCheck()
        ret = executer.ValidateFailures()
    except Exception as e:
        # At least log the exception on console.
        print e
        # The #4 element encodes the runtime exception.
        ret = (1, '', '', 'Exception happened during execution: \n' + str(e))
    finally:
        available_machine.Unlock(exclusive=True)
        executer.CleanupIntermediateFiles()
        executer.Cleanup()
        return ret
示例#2
0
 def __init__(self):
     # Get the Crosperf directory; that is where the defaults
     # file should be.
     dirname, __ = misc.GetRoot(__file__)
     fullname = os.path.join(dirname, self.DEFAULTS_FILE_NAME)
     self._filename = fullname
     self._defaults = {}
示例#3
0
def CreateSymlink(target, link_name):
    logger.GetLogger().LogFatalIf(target.startswith('/'),
                                  "Can't create symlink to absolute path!")
    real_from_file = misc.GetRoot(link_name)[0] + '/' + target
    if os.path.realpath(real_from_file) != os.path.realpath(link_name):
        if os.path.exists(link_name):
            command = 'rm -rf ' + link_name
            command_executer.GetCommandExecuter().RunCommand(command)
        os.symlink(target, link_name)
    def GetNewKeyvals(self, keyvals_dict):
        # Initialize 'units' dictionary.
        units_dict = {}
        for k in keyvals_dict:
            units_dict[k] = ''
        results_files = self.GetDataMeasurementsFiles()
        for f in results_files:
            # Make sure we can find the results file
            if os.path.exists(f):
                data_filename = f
            else:
                # Otherwise get the base filename and create the correct
                # path for it.
                _, f_base = misc.GetRoot(f)
                data_filename = os.path.join(self.chromeos_root, 'chroot/tmp',
                                             self.temp_dir, f_base)
            if data_filename.find('.json') > 0:
                raw_dict = dict()
                if os.path.exists(data_filename):
                    with open(data_filename, 'r') as data_file:
                        raw_dict = json.load(data_file)

                if 'charts' in raw_dict:
                    raw_dict = raw_dict['charts']
                for k1 in raw_dict:
                    field_dict = raw_dict[k1]
                    for k2 in field_dict:
                        result_dict = field_dict[k2]
                        key = k1 + '__' + k2
                        if 'value' in result_dict:
                            keyvals_dict[key] = result_dict['value']
                        elif 'values' in result_dict:
                            values = result_dict['values']
                            if ('type' in result_dict and result_dict['type']
                                    == 'list_of_scalar_values' and values
                                    and values != 'null'):
                                keyvals_dict[key] = sum(values) / float(
                                    len(values))
                            else:
                                keyvals_dict[key] = values
                        units_dict[key] = result_dict['units']
            else:
                if os.path.exists(data_filename):
                    with open(data_filename, 'r') as data_file:
                        lines = data_file.readlines()
                        for line in lines:
                            tmp_dict = json.loads(line)
                            graph_name = tmp_dict['graph']
                            graph_str = (graph_name +
                                         '__') if graph_name else ''
                            key = graph_str + tmp_dict['description']
                            keyvals_dict[key] = tmp_dict['value']
                            units_dict[key] = tmp_dict['units']

        return keyvals_dict, units_dict
 def CleanUp(self, rm_chroot_tmp):
     if rm_chroot_tmp and self.results_dir:
         dirname, basename = misc.GetRoot(self.results_dir)
         if basename.find('test_that_results_') != -1:
             command = 'rm -rf %s' % self.results_dir
         else:
             command = 'rm -rf %s' % dirname
         self.ce.RunCommand(command)
     if self.temp_dir:
         command = 'rm -rf %s' % self.temp_dir
         self.ce.RunCommand(command)
def _ReadSummaryFile(filename):
    """Reads the summary file at filename."""
    dirname, _ = misc.GetRoot(filename)
    fullname = os.path.join(dirname, _TELEMETRY_RESULT_DEFAULTS_FILE)
    try:
        # Slurp the summary file into a dictionary. The keys in the dictionary are
        # the benchmark names. The value for a key is a list containing the names
        # of all the result fields that should be returned in a 'default' report.
        with open(fullname) as in_file:
            return json.load(in_file)
    except IOError as e:
        # ENOENT means "no such file or directory"
        if e.errno == errno.ENOENT:
            return {}
        raise
def Main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--chromeos_root',
                        dest='chromeos_root',
                        help='ChromeOS root checkout directory')
    parser.add_argument('-r',
                        '--remote',
                        dest='remote',
                        help='Remote chromeos device.')
    options = parser.parse_args(argv)
    if options.chromeos_root is None:
        Usage(parser, 'chromeos_root must be given')

    if options.remote is None:
        Usage(parser, 'remote must be given')

    options.chromeos_root = os.path.expanduser(options.chromeos_root)

    command = 'ls -lt /'
    ce = command_executer.GetCommandExecuter()
    ce.CrosRunCommand(command,
                      chromeos_root=options.chromeos_root,
                      machine=options.remote)

    version_dir_path, script_name = misc.GetRoot(sys.argv[0])
    version_dir = misc.GetRoot(version_dir_path)[1]

    # Tests to copy directories and files to the chromeos box.
    ce.CopyFiles(version_dir_path,
                 '/tmp/' + version_dir,
                 dest_machine=options.remote,
                 dest_cros=True,
                 chromeos_root=options.chromeos_root)
    ce.CopyFiles(version_dir_path,
                 '/tmp/' + version_dir + '1',
                 dest_machine=options.remote,
                 dest_cros=True,
                 chromeos_root=options.chromeos_root)
    ce.CopyFiles(sys.argv[0],
                 '/tmp/' + script_name,
                 recursive=False,
                 dest_machine=options.remote,
                 dest_cros=True,
                 chromeos_root=options.chromeos_root)
    ce.CopyFiles(sys.argv[0],
                 '/tmp/' + script_name + '1',
                 recursive=False,
                 dest_machine=options.remote,
                 dest_cros=True,
                 chromeos_root=options.chromeos_root)

    # Test to copy directories and files from the chromeos box.
    ce.CopyFiles('/tmp/' + script_name,
                 '/tmp/hello',
                 recursive=False,
                 src_machine=options.remote,
                 src_cros=True,
                 chromeos_root=options.chromeos_root)
    ce.CopyFiles('/tmp/' + script_name,
                 '/tmp/' + script_name,
                 recursive=False,
                 src_machine=options.remote,
                 src_cros=True,
                 chromeos_root=options.chromeos_root)
    board = ce.CrosLearnBoard(options.chromeos_root, options.remote)
    print(board)
    return 0
示例#8
0
def Main(argv, return_output=False):
    """The main function."""

    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--chromeos_root',
                        dest='chromeos_root',
                        default='../..',
                        help='ChromeOS root checkout directory.')
    parser.add_argument('-t',
                        '--toolchain_root',
                        dest='toolchain_root',
                        help='Toolchain root directory.')
    parser.add_argument('-o',
                        '--output',
                        dest='output',
                        help='Toolchain output directory')
    parser.add_argument('--sudo',
                        dest='sudo',
                        action='store_true',
                        default=False,
                        help='Run the command with sudo.')
    parser.add_argument('-r',
                        '--third_party',
                        dest='third_party',
                        help='The third_party directory to mount.')
    parser.add_argument('-m',
                        '--other_mounts',
                        dest='other_mounts',
                        help='Other mount points in the form: '
                        'dir:mounted_dir:options')
    parser.add_argument(
        '-s',
        '--mount-scripts-only',
        dest='mount_scripts_only',
        action='store_true',
        default=False,
        help='Mount only the scripts dir, and not the sources.')
    parser.add_argument('passthrough_argv',
                        nargs='*',
                        help='Command to be executed inside the chroot.')

    options = parser.parse_args(argv)

    chromeos_root = options.chromeos_root

    chromeos_root = os.path.expanduser(chromeos_root)
    if options.toolchain_root:
        options.toolchain_root = os.path.expanduser(options.toolchain_root)

    chromeos_root = os.path.abspath(chromeos_root)

    tc_dirs = []
    if options.toolchain_root is None or options.mount_scripts_only:
        m = 'toolchain_root not specified. Will not mount toolchain dirs.'
        logger.GetLogger().LogWarning(m)
    else:
        tc_dirs = [
            options.toolchain_root + '/google_vendor_src_branch/gcc',
            options.toolchain_root + '/google_vendor_src_branch/binutils'
        ]

    for tc_dir in tc_dirs:
        if not os.path.exists(tc_dir):
            logger.GetLogger().LogError('toolchain path ' + tc_dir +
                                        ' does not exist!')
            parser.print_help()
            sys.exit(1)

    if not os.path.exists(chromeos_root):
        logger.GetLogger().LogError('chromeos_root ' + options.chromeos_root +
                                    ' does not exist!')
        parser.print_help()
        sys.exit(1)

    if not os.path.exists(chromeos_root + '/src/scripts/build_packages'):
        logger.GetLogger().LogError(options.chromeos_root +
                                    '/src/scripts/build_packages'
                                    ' not found!')
        parser.print_help()
        sys.exit(1)

    version_dir = os.path.realpath(
        os.path.expanduser(os.path.dirname(__file__)))

    mounted_tc_root = '/usr/local/toolchain_root'
    full_mounted_tc_root = chromeos_root + '/chroot/' + mounted_tc_root
    full_mounted_tc_root = os.path.abspath(full_mounted_tc_root)

    mount_points = []
    for tc_dir in tc_dirs:
        last_dir = misc.GetRoot(tc_dir)[1]
        mount_point = MountPoint(tc_dir, full_mounted_tc_root + '/' + last_dir,
                                 getpass.getuser(), 'ro')
        mount_points.append(mount_point)

    # Add the third_party mount point if it exists
    if options.third_party:
        third_party_dir = options.third_party
        logger.GetLogger().LogFatalIf(
            not os.path.isdir(third_party_dir),
            '--third_party option is not a valid dir.')
    else:
        third_party_dir = os.path.abspath('%s/../../../third_party' %
                                          os.path.dirname(__file__))

    if os.path.isdir(third_party_dir):
        mount_point = MountPoint(
            third_party_dir,
            ('%s/%s' %
             (full_mounted_tc_root, os.path.basename(third_party_dir))),
            getpass.getuser())
        mount_points.append(mount_point)

    output = options.output
    if output is None and options.toolchain_root:
        # Mount the output directory at /usr/local/toolchain_root/output
        output = options.toolchain_root + '/output'

    if output:
        mount_points.append(
            MountPoint(output, full_mounted_tc_root + '/output',
                       getpass.getuser()))

    # Mount the other mount points
    mount_points += CreateMountPointsFromString(options.other_mounts,
                                                chromeos_root + '/chroot/')

    last_dir = misc.GetRoot(version_dir)[1]

    # Mount the version dir (v14) at /usr/local/toolchain_root/v14
    mount_point = MountPoint(version_dir,
                             full_mounted_tc_root + '/' + last_dir,
                             getpass.getuser())
    mount_points.append(mount_point)

    for mount_point in mount_points:
        retv = mount_point.DoMount()
        if retv != 0:
            return retv

    # Finally, create the symlink to build-gcc.
    command = 'sudo chown ' + getpass.getuser() + ' ' + full_mounted_tc_root
    retv = command_executer.GetCommandExecuter().RunCommand(command)

    try:
        CreateSymlink(last_dir + '/build-gcc',
                      full_mounted_tc_root + '/build-gcc')
        CreateSymlink(last_dir + '/build-binutils',
                      full_mounted_tc_root + '/build-binutils')
    except Exception as e:
        logger.GetLogger().LogError(str(e))

    # Now call cros_sdk --enter with the rest of the arguments.
    command = 'cd %s/src/scripts && cros_sdk --enter' % chromeos_root

    if len(options.passthrough_argv) > 1:
        inner_command = ' '.join(options.passthrough_argv[1:])
        inner_command = inner_command.strip()
        if inner_command.startswith('-- '):
            inner_command = inner_command[3:]
        command_file = 'tc_enter_chroot.cmd'
        command_file_path = chromeos_root + '/src/scripts/' + command_file
        retv = command_executer.GetCommandExecuter().RunCommand(
            'sudo rm -f ' + command_file_path)
        if retv != 0:
            return retv
        f = open(command_file_path, 'w')
        f.write(inner_command)
        f.close()
        logger.GetLogger().LogCmd(inner_command)
        retv = command_executer.GetCommandExecuter().RunCommand(
            'chmod +x ' + command_file_path)
        if retv != 0:
            return retv

        if options.sudo:
            command += ' sudo ./' + command_file
        else:
            command += ' ./' + command_file
        retv = command_executer.GetCommandExecuter().RunCommandGeneric(
            command, return_output)
        return retv
    else:
        os.chdir('%s/src/scripts' % chromeos_root)
        ce = command_executer.GetCommandExecuter()
        _, out, _ = ce.RunCommandWOutput('which cros_sdk')
        cros_sdk_binary = out.split()[0]
        return os.execv(cros_sdk_binary, ['', '--enter'])