def test_native_case_alternate_datastream(self):
            # Create the file manually, since tempfile doesn't support ADS.
            tempdir = unicode(tempfile.mkdtemp(prefix='trace_inputs'))
            try:
                tempdir = trace_inputs.get_native_path_case(tempdir)
                basename = 'foo.txt'
                filename = basename + ':Zone.Identifier'
                filepath = os.path.join(tempdir, filename)
                open(filepath, 'w').close()
                self.assertEqual(filepath,
                                 trace_inputs.get_native_path_case(filepath))
                data_suffix = ':$DATA'
                self.assertEqual(
                    filepath + data_suffix,
                    trace_inputs.get_native_path_case(filepath + data_suffix))

                open(filepath + '$DATA', 'w').close()
                self.assertEqual(
                    filepath + data_suffix,
                    trace_inputs.get_native_path_case(filepath + data_suffix))
                # Ensure the ADS weren't created as separate file. You love NTFS, don't
                # you?
                self.assertEqual([basename], os.listdir(tempdir))
            finally:
                shutil.rmtree(tempdir)
 def test_native_case_windows(self):
     if sys.platform != 'win32':
         return
     windows_path = os.environ['SystemRoot']
     self.assertEquals(
         trace_inputs.get_native_path_case(windows_path.lower()),
         trace_inputs.get_native_path_case(windows_path.upper()))
Example #3
0
 def test_native_case_windows(self):
   if sys.platform != 'win32':
     return
   windows_path = os.environ['SystemRoot']
   self.assertEquals(
       trace_inputs.get_native_path_case(windows_path.lower()),
       trace_inputs.get_native_path_case(windows_path.upper()))
Example #4
0
 def test_native_case_non_existing(self):
   # Make sure it doesn't throw on non-existing files.
   non_existing = 'trace_input_test_this_file_should_not_exist'
   path = os.path.expanduser('~/' + non_existing)
   self.assertFalse(os.path.exists(path))
   path = trace_inputs.get_native_path_case(ROOT_DIR) + os.path.sep
   self.assertEqual(trace_inputs.get_native_path_case(path), path)
Example #5
0
        def test_native_case_symlink_wrong_case(self):
            actual = trace_inputs.get_native_path_case(
                os.path.join(ROOT_DIR, 'data', 'trace_inputs'))
            self.assertEquals('trace_inputs', os.path.basename(actual))

            # Make sure the symlink is not resolved.
            actual = trace_inputs.get_native_path_case(
                os.path.join(ROOT_DIR, 'data', 'trace_inputs', 'Files2'))
            self.assertEquals('files2', os.path.basename(actual))
Example #6
0
    def test_native_case_symlink_right_case(self):
      actual = trace_inputs.get_native_path_case(
          os.path.join(BASE_DIR, 'trace_inputs'))
      self.assertEqual('trace_inputs', os.path.basename(actual))

      # Make sure the symlink is not resolved.
      actual = trace_inputs.get_native_path_case(
          os.path.join(BASE_DIR, 'trace_inputs', 'files2'))
      self.assertEqual('files2', os.path.basename(actual))
Example #7
0
    def test_native_case_symlink_wrong_case(self):
      actual = trace_inputs.get_native_path_case(
          os.path.join(ROOT_DIR, 'data', 'trace_inputs'))
      self.assertEquals('trace_inputs', os.path.basename(actual))

      # Make sure the symlink is not resolved.
      actual = trace_inputs.get_native_path_case(
          os.path.join(ROOT_DIR, 'data', 'trace_inputs', 'Files2'))
      self.assertEquals('files2', os.path.basename(actual))
Example #8
0
 def test_native_case_not_sensitive(self):
     # The home directory is almost guaranteed to have mixed upper/lower case
     # letters on both Windows and OSX.
     # This test also ensures that the output is independent on the input
     # string case.
     path = os.path.expanduser('~')
     self.assertTrue(os.path.isdir(path))
     # This test assumes the variable is in the native path case on disk, this
     # should be the case. Verify this assumption:
     self.assertEquals(path, trace_inputs.get_native_path_case(path))
     self.assertEquals(trace_inputs.get_native_path_case(path.lower()),
                       trace_inputs.get_native_path_case(path.upper()))
Example #9
0
 def test_native_case_not_sensitive_non_existent(self):
   # This test also ensures that the output is independent on the input
   # string case.
   non_existing = os.path.join(
       'trace_input_test_this_dir_should_not_exist', 'really not', '')
   path = os.path.expanduser(os.path.join('~', non_existing))
   self.assertFalse(os.path.exists(path))
   lower = trace_inputs.get_native_path_case(path.lower())
   upper = trace_inputs.get_native_path_case(path.upper())
   # Make sure non-existing element is not modified:
   self.assertTrue(lower.endswith(non_existing.lower()))
   self.assertTrue(upper.endswith(non_existing.upper()))
   self.assertEquals(lower[:-len(non_existing)], upper[:-len(non_existing)])
Example #10
0
 def test_native_case_not_sensitive(self):
   # The home directory is almost guaranteed to have mixed upper/lower case
   # letters on both Windows and OSX.
   # This test also ensures that the output is independent on the input
   # string case.
   path = os.path.expanduser('~')
   self.assertTrue(os.path.isdir(path))
   # This test assumes the variable is in the native path case on disk, this
   # should be the case. Verify this assumption:
   self.assertEquals(path, trace_inputs.get_native_path_case(path))
   self.assertEquals(
       trace_inputs.get_native_path_case(path.lower()),
       trace_inputs.get_native_path_case(path.upper()))
Example #11
0
 def test_native_case_not_sensitive_non_existent(self):
   # This test also ensures that the output is independent on the input
   # string case.
   non_existing = os.path.join(
       'trace_input_test_this_dir_should_not_exist', 'really not', '')
   path = os.path.expanduser(os.path.join(u'~', non_existing))
   path = path.replace('/', os.path.sep)
   self.assertFalse(os.path.exists(path))
   lower = trace_inputs.get_native_path_case(path.lower())
   upper = trace_inputs.get_native_path_case(path.upper())
   # Make sure non-existing element is not modified:
   self.assertTrue(lower.endswith(non_existing.lower()))
   self.assertTrue(upper.endswith(non_existing.upper()))
   self.assertEqual(lower[:-len(non_existing)], upper[:-len(non_existing)])
 def test_native_case_not_sensitive(self):
     # The home directory is almost guaranteed to have mixed upper/lower case
     # letters on both Windows and OSX.
     # This test also ensures that the output is independent on the input
     # string case.
     path = os.path.expanduser(u'~')
     self.assertTrue(os.path.isdir(path))
     path = path.replace('/', os.path.sep)
     if sys.platform == 'win32':
         # Make sure the drive letter is upper case for consistency.
         path = path[0].upper() + path[1:]
     # This test assumes the variable is in the native path case on disk, this
     # should be the case. Verify this assumption:
     self.assertEqual(path, trace_inputs.get_native_path_case(path))
     self.assertEqual(trace_inputs.get_native_path_case(path.lower()),
                      trace_inputs.get_native_path_case(path.upper()))
Example #13
0
  def parse_args(self, *args, **kwargs):
    """Makes sure the paths make sense.

    On Windows, / and \ are often mixed together in a path.
    """
    options, args = OptionParserWithLogging.parse_args(self, *args, **kwargs)
    if not self.allow_interspersed_args and args:
      self.error('Unsupported argument: %s' % args)

    options.variables = dict(options.variables)

    if self.require_result and not options.result:
      self.error('--result is required.')
    if options.result and not options.result.endswith('.results'):
      self.error('--result value must end with \'.results\'')

    if options.result:
      options.result = os.path.abspath(options.result.replace('/', os.path.sep))

    if options.isolate:
      options.isolate = trace_inputs.get_native_path_case(
          os.path.abspath(
              options.isolate.replace('/', os.path.sep)))

    if options.outdir:
      options.outdir = os.path.abspath(
          options.outdir.replace('/', os.path.sep))

    return options, args
Example #14
0
  def setUp(self):
    self.temp_file = None

    self.initial_cwd = ROOT_DIR
    if sys.platform == 'win32':
      # Windows has no kernel mode concept of current working directory.
      self.initial_cwd = None

    # There's 2 kinds of references to python, self.executable,
    # self.real_executable. It depends how python was started and on which OS.
    self.executable = unicode(sys.executable)
    if sys.platform == 'darwin':
      # /usr/bin/python is a thunk executable that decides which version of
      # python gets executed.
      suffix = '.'.join(map(str, sys.version_info[0:2]))
      if os.access(self.executable + suffix, os.X_OK):
        # So it'll look like /usr/bin/python2.7
        self.executable += suffix

    self.real_executable = trace_inputs.get_native_path_case(
        self.executable)

    if sys.platform == 'darwin':
      # Interestingly, only OSX does resolve the symlink manually before
      # starting the executable.
      if os.path.islink(self.real_executable):
        self.real_executable = os.path.normpath(
            os.path.join(
                os.path.dirname(self.real_executable),
                os.readlink(self.real_executable)))
Example #15
0
 def test_native_case_not_sensitive(self):
   # The home directory is almost guaranteed to have mixed upper/lower case
   # letters on both Windows and OSX.
   # This test also ensures that the output is independent on the input
   # string case.
   path = os.path.expanduser(u'~')
   self.assertTrue(os.path.isdir(path))
   path = path.replace('/', os.path.sep)
   if sys.platform == 'win32':
     # Make sure the drive letter is upper case for consistency.
     path = path[0].upper() + path[1:]
   # This test assumes the variable is in the native path case on disk, this
   # should be the case. Verify this assumption:
   self.assertEqual(path, trace_inputs.get_native_path_case(path))
   self.assertEqual(
       trace_inputs.get_native_path_case(path.lower()),
       trace_inputs.get_native_path_case(path.upper()))
        def test_native_case_symlink_wrong_case(self):
            base_dir = trace_inputs.get_native_path_case(BASE_DIR)
            trace_inputs_dir = os.path.join(base_dir, 'trace_inputs')
            actual = trace_inputs.get_native_path_case(trace_inputs_dir)
            self.assertEqual(trace_inputs_dir, actual)

            # Make sure the symlink is not resolved.
            data = os.path.join(trace_inputs_dir, 'Files2')
            actual = trace_inputs.get_native_path_case(data)
            self.assertEqual(os.path.join(trace_inputs_dir, 'files2'), actual)

            data = os.path.join(trace_inputs_dir, 'Files2', '')
            actual = trace_inputs.get_native_path_case(data)
            self.assertEqual(os.path.join(trace_inputs_dir, 'files2', ''),
                             actual)

            data = os.path.join(trace_inputs_dir, 'Files2', 'Child1.py')
            actual = trace_inputs.get_native_path_case(data)
            # TODO(maruel): Should be child1.py.
            self.assertEqual(
                os.path.join(trace_inputs_dir, 'files2', 'Child1.py'), actual)
Example #17
0
  def setUp(self):
    self.tempdir = None
    self.trace_inputs_path = os.path.join(ROOT_DIR, 'trace_inputs.py')

    # Wraps up all the differences between OSes here.
    # - Windows doesn't track initial_cwd.
    # - OSX replaces /usr/bin/python with /usr/bin/python2.7.
    self.cwd = os.path.join(ROOT_DIR, u'tests')
    self.initial_cwd = unicode(self.cwd)
    self.expected_cwd = unicode(ROOT_DIR)
    if sys.platform == 'win32':
      # Not supported on Windows.
      self.initial_cwd = None
      self.expected_cwd = None

    # There's 3 kinds of references to python, self.executable,
    # self.real_executable and self.naked_executable. It depends how python was
    # started.
    self.executable = sys.executable
    if sys.platform == 'darwin':
      # /usr/bin/python is a thunk executable that decides which version of
      # python gets executed.
      suffix = '.'.join(map(str, sys.version_info[0:2]))
      if os.access(self.executable + suffix, os.X_OK):
        # So it'll look like /usr/bin/python2.7
        self.executable += suffix

    import trace_inputs
    self.real_executable = trace_inputs.get_native_path_case(
        unicode(self.executable))
    self.tempdir = trace_inputs.get_native_path_case(
        unicode(tempfile.mkdtemp(prefix='trace_smoke_test')))
    self.log = os.path.join(self.tempdir, 'log')
    trace_inputs = None

    # self.naked_executable will only be naked on Windows.
    self.naked_executable = unicode(sys.executable)
    if sys.platform == 'win32':
      self.naked_executable = os.path.basename(sys.executable)
Example #18
0
  def setUp(self):
    self.tempdir = None
    self.trace_inputs_path = os.path.join(ROOT_DIR, 'trace_inputs.py')

    # Wraps up all the differences between OSes here.
    # - Windows doesn't track initial_cwd.
    # - OSX replaces /usr/bin/python with /usr/bin/python2.7.
    self.cwd = os.path.join(ROOT_DIR, u'tests')
    self.initial_cwd = unicode(self.cwd)
    self.expected_cwd = unicode(ROOT_DIR)
    if sys.platform == 'win32':
      # Not supported on Windows.
      self.initial_cwd = None
      self.expected_cwd = None

    # There's 3 kinds of references to python, self.executable,
    # self.real_executable and self.naked_executable. It depends how python was
    # started.
    self.executable = sys.executable
    if sys.platform == 'darwin':
      # /usr/bin/python is a thunk executable that decides which version of
      # python gets executed.
      suffix = '.'.join(map(str, sys.version_info[0:2]))
      if os.access(self.executable + suffix, os.X_OK):
        # So it'll look like /usr/bin/python2.7
        self.executable += suffix

    import trace_inputs
    self.real_executable = trace_inputs.get_native_path_case(
        unicode(self.executable))
    self.tempdir = trace_inputs.get_native_path_case(
        unicode(tempfile.mkdtemp(prefix='trace_smoke_test')))
    self.log = os.path.join(self.tempdir, 'log')
    trace_inputs = None

    # self.naked_executable will only be naked on Windows.
    self.naked_executable = unicode(sys.executable)
    if sys.platform == 'win32':
      self.naked_executable = os.path.basename(sys.executable)
Example #19
0
    def test_native_case_symlink_wrong_case(self):
      base_dir = trace_inputs.get_native_path_case(BASE_DIR)
      trace_inputs_dir = os.path.join(base_dir, 'trace_inputs')
      actual = trace_inputs.get_native_path_case(trace_inputs_dir)
      self.assertEqual(trace_inputs_dir, actual)

      # Make sure the symlink is not resolved.
      data = os.path.join(trace_inputs_dir, 'Files2')
      actual = trace_inputs.get_native_path_case(data)
      self.assertEqual(
          os.path.join(trace_inputs_dir, 'files2'), actual)

      data = os.path.join(trace_inputs_dir, 'Files2', '')
      actual = trace_inputs.get_native_path_case(data)
      self.assertEqual(
          os.path.join(trace_inputs_dir, 'files2', ''), actual)

      data = os.path.join(trace_inputs_dir, 'Files2', 'Child1.py')
      actual = trace_inputs.get_native_path_case(data)
      # TODO(maruel): Should be child1.py.
      self.assertEqual(
          os.path.join(trace_inputs_dir, 'files2', 'Child1.py'), actual)
Example #20
0
    def test_native_case_alternate_datastream(self):
      # Create the file manually, since tempfile doesn't support ADS.
      tempdir = unicode(tempfile.mkdtemp(prefix='trace_inputs'))
      try:
        tempdir = trace_inputs.get_native_path_case(tempdir)
        basename = 'foo.txt'
        filename = basename + ':Zone.Identifier'
        filepath = os.path.join(tempdir, filename)
        open(filepath, 'w').close()
        self.assertEqual(filepath, trace_inputs.get_native_path_case(filepath))
        data_suffix = ':$DATA'
        self.assertEqual(
            filepath + data_suffix,
            trace_inputs.get_native_path_case(filepath + data_suffix))

        open(filepath + '$DATA', 'w').close()
        self.assertEqual(
            filepath + data_suffix,
            trace_inputs.get_native_path_case(filepath + data_suffix))
        # Ensure the ADS weren't created as separate file. You love NTFS, don't
        # you?
        self.assertEqual([basename], os.listdir(tempdir))
      finally:
        shutil.rmtree(tempdir)
Example #21
0
 def test_trace(self):
   expected = self._gen_dict_full_gyp()
   results = self._execute_trace(self.get_child_command(True))
   actual = results.flatten()
   self.assertTrue(actual['root'].pop('pid'))
   self.assertTrue(actual['root']['children'][0].pop('pid'))
   self.assertEqual(expected, actual)
   files = [
     u'tests/trace_inputs/child1.py'.replace('/', os.path.sep),
     u'tests/trace_inputs/child2.py'.replace('/', os.path.sep),
     u'tests/trace_inputs/files1/'.replace('/', os.path.sep),
     u'tests/trace_inputs/test_file.txt'.replace('/', os.path.sep),
     u'tests/trace_inputs_smoke_test.py'.replace('/', os.path.sep),
     u'trace_inputs.py',
   ]
   def blacklist(f):
     return f.endswith(('.pyc', 'do_not_care.txt', '.git', '.svn'))
   simplified = trace_inputs.extract_directories(
       trace_inputs.get_native_path_case(unicode(ROOT_DIR)),
       results.files,
       blacklist)
   self.assertEqual(files, [f.path for f in simplified])
  def setUp(self):
    self.temp_file = None

    self.initial_cwd = ROOT_DIR
    if sys.platform == 'win32':
      # Windows has no kernel mode concept of current working directory.
      self.initial_cwd = None

    # There's 2 kinds of references to python, self.executable,
    # self.real_executable. It depends how python was started and on which OS.
    self.executable = unicode(sys.executable)
    if sys.platform == 'darwin':
      # /usr/bin/python is a thunk executable that decides which version of
      # python gets executed.
      suffix = '.'.join(map(str, sys.version_info[0:2]))
      if os.access(self.executable + suffix, os.X_OK):
        # So it'll look like /usr/bin/python2.7
        self.executable += suffix

    self.real_executable = trace_inputs.get_native_path_case(self.executable)
    # Make sure there's no environment variable that could do side effects.
    os.environ.pop('GTEST_SHARD_INDEX', '')
    os.environ.pop('GTEST_TOTAL_SHARDS', '')
    def test_trace(self):
        expected = self._gen_dict_full_gyp()
        results = self._execute_trace(self.get_child_command(True))
        actual = results.flatten()
        self.assertTrue(actual['root'].pop('pid'))
        self.assertTrue(actual['root']['children'][0].pop('pid'))
        self.assertEqual(expected, actual)
        files = [
            u'tests/trace_inputs/child1.py'.replace('/', os.path.sep),
            u'tests/trace_inputs/child2.py'.replace('/', os.path.sep),
            u'tests/trace_inputs/files1/'.replace('/', os.path.sep),
            u'tests/trace_inputs/test_file.txt'.replace('/', os.path.sep),
            u'tests/trace_inputs_smoke_test.py'.replace('/', os.path.sep),
            u'trace_inputs.py',
        ]

        def blacklist(f):
            return f.endswith(('.pyc', 'do_not_care.txt', '.git', '.svn'))

        simplified = trace_inputs.extract_directories(
            trace_inputs.get_native_path_case(unicode(ROOT_DIR)),
            results.files, blacklist)
        self.assertEqual(files, [f.path for f in simplified])
    def setUp(self):
        self.temp_file = None

        self.initial_cwd = ROOT_DIR
        if sys.platform == 'win32':
            # Windows has no kernel mode concept of current working directory.
            self.initial_cwd = None

        # There's 2 kinds of references to python, self.executable,
        # self.real_executable. It depends how python was started and on which OS.
        self.executable = unicode(sys.executable)
        if sys.platform == 'darwin':
            # /usr/bin/python is a thunk executable that decides which version of
            # python gets executed.
            suffix = '.'.join(map(str, sys.version_info[0:2]))
            if os.access(self.executable + suffix, os.X_OK):
                # So it'll look like /usr/bin/python2.7
                self.executable += suffix

        self.real_executable = trace_inputs.get_native_path_case(
            self.executable)
        # Make sure there's no environment variable that could do side effects.
        os.environ.pop('GTEST_SHARD_INDEX', '')
        os.environ.pop('GTEST_TOTAL_SHARDS', '')
Example #25
0
  def test_simple(self):
    file_handle, self.temp_file = tempfile.mkstemp(
        prefix='trace_test_cases_test')
    os.close(file_handle)

    cmd = [
        sys.executable,
        os.path.join(ROOT_DIR, 'trace_test_cases.py'),
        # Forces 4 parallel jobs.
        '--jobs', '4',
        '--out', self.temp_file,
    ]
    if VERBOSE:
      cmd.extend(['-v'] * 3)
    cmd.append(TARGET_PATH)
    logging.debug(' '.join(cmd))
    proc = subprocess.Popen(
        cmd,
        stdout=subprocess.PIPE, stderr=subprocess.PIPE,
        universal_newlines=True,
        cwd=ROOT_DIR)
    out, err = proc.communicate() or ('', '')  # pylint is confused.
    self.assertEqual(0, proc.returncode, (out, err))
    lines = out.splitlines()
    expected_out_re = [
      r'Tracing\.\.\.',
      r'\[1/4\] +\d+\.\d\ds .+',
      r'\[2/4\] +\d+\.\d\ds .+',
      r'\[3/4\] +\d+\.\d\ds .+',
      r'\[4/4\] +\d+\.\d\ds .+',
      r'Reading trace logs\.\.\.',
    ]
    self.assertEqual(len(expected_out_re), len(lines), lines)
    for index in range(len(expected_out_re)):
      self.assertTrue(
          re.match('^%s$' % expected_out_re[index], lines[index]),
          '%d: %s\n%r\n%s' % (
            index, expected_out_re[index], lines[index], out))
    # Junk is printed on win32.
    if sys.platform != 'win32' and not VERBOSE:
      self.assertEqual('', err)

    with open(self.temp_file, 'r') as f:
      content = f.read()
      try:
        result = json.loads(content)
      except:
        print repr(content)
        raise

    test_cases = {
      'Baz.Fail': 1,
      'Foo.Bar1': 0,
      'Foo.Bar2': 0,
      'Foo.Bar3': 0,
    }
    self.assertEqual(dict, result.__class__)
    self.assertEqual(sorted(test_cases), sorted(result))
    for index, test_case in enumerate(sorted(result)):
      actual = result[test_case]
      self.assertEqual(
          [u'duration', u'output', u'returncode', u'trace'], sorted(actual))
      self.assertGreater(actual['duration'], 0.0000001)
      self.assertEqual(test_cases[test_case], actual['returncode'])
      expected_output = (
          'Note: Google Test filter = %s\n' % test_case +
          '\n' +
          gtest_fake_base.get_test_output(test_case) +
          '\n' +
          gtest_fake_base.get_footer(1, 1) +
          '\n')
      # On Windows, actual['output'] is unprocessed so it will contain CRLF.
      output = actual['output']
      if sys.platform == 'win32':
        output = output.replace('\r\n', '\n')
      self.assertEqual(expected_output, output, repr(output))

      expected_trace = {
        u'root': {
          u'children': [],
          u'command': [
            self.executable, TARGET_PATH, '--gtest_filter=' + test_case,
          ],
          u'executable': trace_inputs.get_native_path_case(
            unicode(self.executable)),
          u'initial_cwd': ROOT_DIR,
        },
      }
      if sys.platform == 'win32':
        expected_trace['root']['initial_cwd'] = None
      self.assertGreater(actual['trace']['root'].pop('pid'), 1)
      self.assertGreater(len(actual['trace']['root'].pop('files')), 10)
      self.assertEqual(expected_trace, actual['trace'])
Example #26
0
 def test_native_case_end_with_dot_os_path_sep(self):
   path = trace_inputs.get_native_path_case(ROOT_DIR + os.path.sep)
   self.assertEqual(
       trace_inputs.get_native_path_case(path + '.' + os.path.sep),
       path)
Example #27
0
 def test_native_case_end_with_os_path_sep(self):
   # Make sure the trailing os.path.sep is kept.
   path = trace_inputs.get_native_path_case(ROOT_DIR) + os.path.sep
   self.assertEqual(trace_inputs.get_native_path_case(path), path)
Example #28
0
 def load(cls, data):
   out = super(SavedState, cls).load(data)
   if out.isolate_file:
     out.isolate_file = trace_inputs.get_native_path_case(out.isolate_file)
   return out
    def test_simple(self):
        file_handle, self.temp_file = tempfile.mkstemp(
            prefix='trace_test_cases_test')
        os.close(file_handle)

        cmd = [
            sys.executable,
            os.path.join(ROOT_DIR, 'trace_test_cases.py'),
            # Forces 4 parallel jobs.
            '--jobs',
            '4',
            '--out',
            self.temp_file,
        ]
        if VERBOSE:
            cmd.extend(['-v'] * 3)
        cmd.append(TARGET_PATH)
        logging.debug(' '.join(cmd))
        proc = subprocess.Popen(cmd,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE,
                                universal_newlines=True,
                                cwd=ROOT_DIR)
        out, err = proc.communicate() or ('', '')  # pylint is confused.
        self.assertEqual(0, proc.returncode, (out, err))
        lines = out.splitlines()
        expected_out_re = [
            r'Tracing\.\.\.',
            r'\[1/4\] +\d+\.\d\ds .+',
            r'\[2/4\] +\d+\.\d\ds .+',
            r'\[3/4\] +\d+\.\d\ds .+',
            r'\[4/4\] +\d+\.\d\ds .+',
            r'Reading trace logs\.\.\.',
        ]
        self.assertEqual(len(expected_out_re), len(lines), lines)
        for index in range(len(expected_out_re)):
            self.assertTrue(
                re.match('^%s$' % expected_out_re[index],
                         lines[index]), '%d: %s\n%r\n%s' %
                (index, expected_out_re[index], lines[index], out))
        # Junk is printed on win32.
        if sys.platform != 'win32' and not VERBOSE:
            self.assertEqual('', err)

        with open(self.temp_file, 'r') as f:
            content = f.read()
            try:
                result = json.loads(content)
            except:
                print repr(content)
                raise

        test_cases = {
            'Baz.Fail': 1,
            'Foo.Bar1': 0,
            'Foo.Bar2': 0,
            'Foo.Bar3': 0,
        }
        self.assertEqual(dict, result.__class__)
        self.assertEqual(sorted(test_cases), sorted(result))
        for index, test_case in enumerate(sorted(result)):
            actual = result[test_case]
            self.assertEqual([u'duration', u'output', u'returncode', u'trace'],
                             sorted(actual))
            self.assertGreater(actual['duration'], 0.0000001)
            self.assertEqual(test_cases[test_case], actual['returncode'])
            expected_output = ('Note: Google Test filter = %s\n' % test_case +
                               '\n' + gtest_fake_base.get_test_output(
                                   test_case, 'Fail' in test_case) + '\n' +
                               gtest_fake_base.get_footer(1, 1) + '\n')
            # On Windows, actual['output'] is unprocessed so it will contain CRLF.
            output = actual['output']
            if sys.platform == 'win32':
                output = output.replace('\r\n', '\n')
            self.assertEqual(expected_output, output, repr(output))

            expected_trace = {
                u'root': {
                    u'children': [],
                    u'command': [
                        self.executable,
                        TARGET_PATH,
                        '--gtest_filter=' + test_case,
                    ],
                    u'executable':
                    trace_inputs.get_native_path_case(unicode(
                        self.executable)),
                    u'initial_cwd':
                    ROOT_DIR,
                },
            }
            if sys.platform == 'win32':
                expected_trace['root']['initial_cwd'] = None
            self.assertGreater(actual['trace']['root'].pop('pid'), 1)
            self.assertGreater(len(actual['trace']['root'].pop('files')), 10)
            self.assertEqual(expected_trace, actual['trace'])