def TestApps(options, work_dir):
    """Test a browser on a corpus of crxs.

  Args:
    options: bag of options.
    work_dir: directory to operate in.
  """
    profile_path = os.path.join(work_dir, 'profile_temp')
    app_path = os.path.join(work_dir, 'app_temp')

    list_filename = os.path.join(work_dir, 'naclapps.all')
    filenames = corpus_utils.DownloadCorpusList(list_filename)
    filenames = [f for f in filenames if f.endswith('.crx')]
    progress = corpus_utils.Progress(len(filenames))
    for filename in filenames:
        progress.Tally()
        corpus_utils.PrimeCache(options.cache_dir, filename)
        # Stop here if downloading only.
        if options.download_only:
            continue
        # Stop here if isn't a bad app but testing only bad apps.
        if options.bad_only and corpus_errors.ExpectedCrxResult(
                filename) == 'GOOD':
            continue
        # Unzip the app.
        corpus_utils.ExtractFromCache(options.cache_dir, filename, app_path)
        try:
            progress.Result(
                TestAppStartup(options, filename, app_path, profile_path))
        finally:
            pynacl.file_tools.RemoveDirectoryIfPresent(app_path)
            pynacl.file_tools.RemoveDirectoryIfPresent(profile_path)
    progress.Summary()
예제 #2
0
def TestValidators(options, work_dir):
    """Test x86 validators on current snapshot.

  Args:
    options: bag of options.
    work_dir: directory to operate in.
  """
    nexe_filename = os.path.join(work_dir, 'test.nexe')
    list_filename = os.path.join(work_dir, 'naclapps.all')
    filenames = corpus_utils.DownloadCorpusList(list_filename)
    filenames = [
        f for f in filenames if f.endswith('.nexe') or f.endswith('.so')
    ]
    progress = corpus_utils.Progress(len(filenames))
    for filename in filenames:
        progress.Tally()
        corpus_utils.PrimeCache(options.cache_dir, filename)
        # Stop here if downloading only.
        if options.download_only:
            continue
        # Skip if not the right architecture.
        architecture = corpus_utils.NexeArchitecture(
            corpus_utils.CachedPath(options.cache_dir, filename))
        if architecture != options.architecture:
            continue
        if corpus_errors.NexeShouldBeSkipped(filename):
            print 'Skipped, sha1: %s' % corpus_utils.Sha1FromFilename(filename)
            progress.Skip()
            continue
        # Validate a copy in case validator is mutating.
        corpus_utils.CopyFromCache(options.cache_dir, filename, nexe_filename)
        try:
            result = ValidateNexe(options, nexe_filename, filename,
                                  corpus_errors.NexeShouldValidate(filename))
            progress.Result(result)
            if not result and not options.keep_going:
                break
        finally:
            try:
                os.remove(nexe_filename)
            except OSError:
                print 'ERROR - unable to remove %s' % nexe_filename
    progress.Summary(warn_only=options.warn_only)