Ejemplo n.º 1
0
def TestAppStartup(options, crx_path, app_path, profile_path):
    """Run the validator on a nexe, check if the result is expected.

  Args:
    options: bag of options.
    crx_path: path to the crx.
    app_path: path to the extracted crx.
    profile_path: path to a temporary profile dir.
  """
    expected_result = corpus_errors.ExpectedCrxResult(crx_path)
    try:
        manifest = corpus_utils.LoadManifest(app_path)
        start_path = manifest.get('app').get('launch').get('local_path')
    except:
        if expected_result.Matches(corpus_errors.BAD_MANIFEST):
            return True
        else:
            print "'%s': %s," % (corpus_utils.Sha1FromFilename(crx_path),
                                 corpus_errors.BAD_MANIFEST)
            return False
    start_url = 'chrome-extension://%s/%s' % (
        corpus_utils.ChromeAppIdFromPath(app_path), start_path)
    cmd = [
        options.browser, '--disable-web-resources', '--disable-preconnect',
        '--no-first-run', '--no-default-browser-check', '--enable-logging',
        '--log-level=1', '--safebrowsing-disable-auto-update', '--enable-nacl',
        '--load-extension=' + app_path, '--user-data-dir=' + profile_path,
        start_url
    ]
    process_stdout, process_stderr, retcode = corpus_utils.RunWithTimeout(
        cmd, options.duration)
    # Check for errors we don't like.
    result = corpus_errors.GOOD
    errs = re.findall(':ERROR:[^\n]+', process_stderr)
    for err in errs:
        if 'extension_prefs.cc' in err or 'gles2_cmd_decoder.cc' in err:
            continue
        if 'Extension error: Could not load extension from' in err:
            result = result.Merge(corpus_errors.COULD_NOT_LOAD)
            continue
        if 'NaCl process exited with' in process_stderr:
            result = result.Merge(corpus_errors.MODULE_CRASHED)
            continue
        result = result.Merge(
            corpus_errors.CrxResult('custom', custom=err, precidence=20))
    if 'NaClMakePcrelThunk:' not in process_stderr:
        result = result.Merge(corpus_errors.MODULE_DIDNT_START)
    # Check if result is what we expect.
    if not expected_result.Matches(result):
        print "'%s': %s," % (corpus_utils.Sha1FromFilename(crx_path), result)
        if options.verbose:
            print '-' * 70
            print 'Return code: %s' % retcode
            print '>>> STDOUT'
            print process_stdout
            print '>>> STDERR'
            print process_stderr
            print '-' * 70
        return False
    return True
Ejemplo n.º 2
0
def NexeShouldValidate(path):
    """Checks a blacklist to decide if a nexe should validate.

  Args:
    path: path to the nexe.
  Returns:
    Boolean indicating if the nexe should validate.
  """
    return corpus_utils.Sha1FromFilename(path) not in BAD_NEXES
Ejemplo n.º 3
0
def ExpectedCrxResult(path):
    """Checks what the expected result for this app is.

  Args:
    path: path to the crx.
  Returns:
    Reg-ex that matches the expected status.
  """
    return BAD_CRXS.get(corpus_utils.Sha1FromFilename(path), GOOD)
Ejemplo n.º 4
0
def NexeShouldBeSkipped(path):
    """Checks if nexe is in the skip list.

  Args:
    path: path to the nexe.
  Returns:
    Boolean indicating if the nexe should be skipped.
  """
    return corpus_utils.Sha1FromFilename(path) in NEXES_TO_SKIP
Ejemplo n.º 5
0
def ValidateNexe(options, path, src_path, expect_pass):
  """Run the validator on a nexe, check if the result is expected.

  Args:
    options: bag of options.
    path: path to the nexe.
    src_path: path to nexe on server.
    expect_pass: boolean indicating if the nexe is expected to validate.
  Returns:
    True if validation matches expectations.
  """
  process = subprocess.Popen(
      [options.validator, path],
      stdout=subprocess.PIPE,
      stderr=subprocess.PIPE)
  process_stdout, process_stderr = process.communicate()
  # Check if result is what we expect.
  did_pass = (process.returncode == 0)
  if expect_pass != did_pass:
    if options.verbose:
      print('-' * 70)
      print('Validating: %s' % path)
      print('From: %s' % src_path)
      print('Size: %d' % os.path.getsize(path))
      print('SHA1: %s' % corpus_utils.Sha1FromFilename(src_path))
      print('Validator: %s' % options.validator)
      print('Unexpected return code: %s' % process.returncode)
      print('>>> STDOUT')
      print(process_stdout)
      print('>>> STDERR')
      print(process_stderr)
      print('-' * 70)
    else:
      print('Unexpected return code %d on sha1: %s' %
            (process.returncode, corpus_utils.Sha1FromFilename(src_path)))
    return False
  return True
Ejemplo n.º 6
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)