예제 #1
0
 def _check_merge(self, filename):
   filepath = file_path.get_native_path_case(
           os.path.join(unicode(ROOT_DIR), 'tests', 'isolate', filename))
   expected = 'Updating %s\n' % isolate.safe_relpath(filepath, self.tempdir)
   with open(filepath, 'rb') as f:
     old_content = f.read()
   out = self._execute('merge', filename, [], True) or ''
   self.assertEqual(expected, out)
   with open(filepath, 'rb') as f:
     new_content = f.read()
   self.assertEqual(old_content, new_content)
예제 #2
0
  def test_subdir_variable(self):
    # The resulting .isolated file will be missing ../../isolate.py. It is
    # because this file is outside the --subdir parameter.
    isolate_file = os.path.join(
        ROOT_DIR, 'tests', 'isolate', 'touch_root.isolate')
    options = self._get_option(isolate_file)
    chromeos_value = int(isolate.get_flavor() == 'linux')
    options.variables['chromeos'] = chromeos_value
    options.variables['BAZ'] = os.path.join('tests', 'isolate')
    complete_state = isolate.load_complete_state(
        options, self.cwd, '<(BAZ)', False)
    actual_isolated = complete_state.saved_state.to_isolated()
    actual_saved_state = complete_state.saved_state.flatten()

    expected_isolated =  {
      'command': ['python', 'touch_root.py'],
      'files': {
        os.path.join('tests', 'isolate', 'touch_root.py'): {
          'm': 488,
          'h': _sha1('tests', 'isolate', 'touch_root.py'),
          's': _size('tests', 'isolate', 'touch_root.py'),
        },
      },
      'os': isolate.get_flavor(),
      'relative_cwd': os.path.join('tests', 'isolate'),
    }
    self._cleanup_isolated(expected_isolated)
    self.assertEqual(expected_isolated, actual_isolated)

    expected_saved_state = {
      'child_isolated_files': [],
      'command': ['python', 'touch_root.py'],
      'files': {
        os.path.join(u'tests', 'isolate', 'touch_root.py'): {
          'm': 488,
          'h': _sha1('tests', 'isolate', 'touch_root.py'),
          's': _size('tests', 'isolate', 'touch_root.py'),
        },
      },
      'isolate_file': isolate.safe_relpath(
          isolate.trace_inputs.get_native_path_case(isolate_file),
          os.path.dirname(options.isolated)),
      'relative_cwd': os.path.join(u'tests', 'isolate'),
      'variables': {
        'foo': 'bar',
        'BAZ': os.path.join('tests', 'isolate'),
        'OS': isolate.get_flavor(),
        'chromeos': chromeos_value,
      },
    }
    self._cleanup_isolated(expected_saved_state)
    self._cleanup_saved_state(actual_saved_state)
    self.assertEqual(expected_saved_state, actual_saved_state)
예제 #3
0
 def _check_merge(self, filename):
     filepath = file_path.get_native_path_case(
         os.path.join(unicode(ROOT_DIR), 'tests', 'isolate', filename))
     expected = 'Updating %s\n' % isolate.safe_relpath(
         filepath, self.tempdir)
     with open(filepath, 'rb') as f:
         old_content = f.read()
     out = self._execute('merge', filename, [], True) or ''
     self.assertEqual(expected, out)
     with open(filepath, 'rb') as f:
         new_content = f.read()
     self.assertEqual(old_content, new_content)
 def _expected_saved_state(self, args, read_only, empty_file, extra_vars):
   flavor = isolate.get_flavor()
   chromeos_value = int(flavor == 'linux')
   expected = {
     u'child_isolated_files': [],
     u'command': [],
     u'files': self._gen_files(read_only, empty_file, True),
     u'isolate_file': isolate.safe_relpath(
         isolate.trace_inputs.get_native_path_case(unicode(self.filename())),
         unicode(os.path.dirname(self.isolated))),
     u'relative_cwd': unicode(RELATIVE_CWD[self.case()]),
     u'variables': {
       u'EXECUTABLE_SUFFIX': u'.exe' if flavor == 'win' else u'',
       u'OS': unicode(flavor),
       u'chromeos': chromeos_value,
     },
   }
   if args:
     expected[u'command'] = [u'python'] + [unicode(x) for x in args]
   expected['variables'].update(extra_vars or {})
   self.assertEqual(expected, json.load(open(self.saved_state(), 'r')))
예제 #5
0
 def _expected_saved_state(self, args, read_only, empty_file, extra_vars):
     flavor = isolate.get_flavor()
     chromeos_value = int(flavor == 'linux')
     expected = {
         u'child_isolated_files': [],
         u'command': [],
         u'files':
         self._gen_files(read_only, empty_file, True),
         u'isolate_file':
         isolate.safe_relpath(
             isolate.trace_inputs.get_native_path_case(
                 unicode(self.filename())),
             unicode(os.path.dirname(self.isolated))),
         u'relative_cwd':
         unicode(RELATIVE_CWD[self.case()]),
         u'variables': {
             u'EXECUTABLE_SUFFIX': u'.exe' if flavor == 'win' else u'',
             u'OS': unicode(flavor),
             u'chromeos': chromeos_value,
         },
     }
예제 #6
0
  def test_chromium_split(self):
    # Create an .isolate file and a tree of random stuff.
    isolate_file = os.path.join(
        ROOT_DIR, 'tests', 'isolate', 'split.isolate')
    options = self._get_option(isolate_file)
    options.variables = {
      'OS': isolate.get_flavor(),
      'DEPTH': '.',
      'PRODUCT_DIR': os.path.join('files1'),
    }
    complete_state = isolate.load_complete_state(
        options, os.path.join(ROOT_DIR, 'tests', 'isolate'), None, False)
    # By saving the files, it forces splitting the data up.
    complete_state.save_files()

    actual_isolated_master = isolate.trace_inputs.read_json(
        os.path.join(self.directory, 'foo.isolated'))
    expected_isolated_master = {
      u'command': [u'python', u'split.py'],
      u'files': {
        u'split.py': {
          u'm': 488,
          u'h': unicode(_sha1('tests', 'isolate', 'split.py')),
          u's': _size('tests', 'isolate', 'split.py'),
        },
      },
      u'includes': [
        unicode(_sha1(os.path.join(self.directory, 'foo.0.isolated'))),
        unicode(_sha1(os.path.join(self.directory, 'foo.1.isolated'))),
      ],
      u'os': unicode(isolate.get_flavor()),
      u'relative_cwd': u'.',
    }
    self._cleanup_isolated(expected_isolated_master)
    self.assertEqual(expected_isolated_master, actual_isolated_master)

    actual_isolated_0 = isolate.trace_inputs.read_json(
        os.path.join(self.directory, 'foo.0.isolated'))
    expected_isolated_0 = {
      u'files': {
        os.path.join(u'test', 'data', 'foo.txt'): {
          u'm': 416,
          u'h': unicode(_sha1('tests', 'isolate', 'test', 'data', 'foo.txt')),
          u's': _size('tests', 'isolate', 'test', 'data', 'foo.txt'),
        },
      },
      u'os': unicode(isolate.get_flavor()),
    }
    self._cleanup_isolated(expected_isolated_0)
    self.assertEqual(expected_isolated_0, actual_isolated_0)

    actual_isolated_1 = isolate.trace_inputs.read_json(
        os.path.join(self.directory, 'foo.1.isolated'))
    expected_isolated_1 = {
      u'files': {
        os.path.join(u'files1', 'subdir', '42.txt'): {
          u'm': 416,
          u'h': unicode(
              _sha1('tests', 'isolate', 'files1', 'subdir', '42.txt')),
          u's': _size('tests', 'isolate', 'files1', 'subdir', '42.txt'),
        },
      },
      u'os': unicode(isolate.get_flavor()),
    }
    self._cleanup_isolated(expected_isolated_1)
    self.assertEqual(expected_isolated_1, actual_isolated_1)

    actual_saved_state = isolate.trace_inputs.read_json(
        isolate.isolatedfile_to_state(options.isolated))
    isolated_base = unicode(os.path.basename(options.isolated))
    expected_saved_state = {
      u'child_isolated_files': [
        isolated_base[:-len('.isolated')] + '.0.isolated',
        isolated_base[:-len('.isolated')] + '.1.isolated',
      ],
      u'command': [u'python', u'split.py'],
      u'files': {
        os.path.join(u'files1', 'subdir', '42.txt'): {
          u'm': 416,
          u'h': unicode(
            _sha1('tests', 'isolate', 'files1', 'subdir', '42.txt')),
          u's': _size('tests', 'isolate', 'files1', 'subdir', '42.txt'),
        },
        u'split.py': {
          u'm': 488,
          u'h': unicode(_sha1('tests', 'isolate', 'split.py')),
          u's': _size('tests', 'isolate', 'split.py'),
        },
        os.path.join(u'test', 'data', 'foo.txt'): {
          u'm': 416,
          u'h': unicode(_sha1('tests', 'isolate', 'test', 'data', 'foo.txt')),
          u's': _size('tests', 'isolate', 'test', 'data', 'foo.txt'),
        },
      },
      u'isolate_file': isolate.safe_relpath(
          isolate.trace_inputs.get_native_path_case(isolate_file),
          unicode(os.path.dirname(options.isolated))),
      u'relative_cwd': u'.',
      u'variables': {
        u'OS': unicode(isolate.get_flavor()),
        u'DEPTH': u'.',
        u'PRODUCT_DIR': u'files1',
      },
    }
    self._cleanup_isolated(expected_saved_state)
    self._cleanup_saved_state(actual_saved_state)
    self.assertEqual(expected_saved_state, actual_saved_state)
    self.assertEqual(
        [
          'foo.0.isolated', 'foo.1.isolated',
          'foo.isolated', 'foo.isolated.state',
        ],
        sorted(os.listdir(self.directory)))
예제 #7
0
  def test_variable(self):
    isolate_file = os.path.join(
        ROOT_DIR, 'tests', 'isolate', 'touch_root.isolate')
    options = self._get_option(isolate_file)
    chromeos_value = int(isolate.get_flavor() == 'linux')
    options.variables['chromeos'] = chromeos_value
    options.variables['PRODUCT_DIR'] = os.path.join('tests', 'isolate')
    complete_state = isolate.load_complete_state(options, ROOT_DIR, None, False)
    actual_isolated = complete_state.saved_state.to_isolated()
    actual_saved_state = complete_state.saved_state.flatten()

    expected_isolated =  {
      'command': ['python', 'touch_root.py'],
      'files': {
        'isolate.py': {
          'm': 488,
          'h': _sha1('isolate.py'),
          's': _size('isolate.py'),
        },
        os.path.join('tests', 'isolate', 'touch_root.py'): {
          'm': 488,
          'h': _sha1('tests', 'isolate', 'touch_root.py'),
          's': _size('tests', 'isolate', 'touch_root.py'),
        },
      },
      'os': isolate.get_flavor(),
      'relative_cwd': os.path.join('tests', 'isolate'),
    }
    self._cleanup_isolated(expected_isolated)
    self.assertEqual(expected_isolated, actual_isolated)

    expected_saved_state = {
      'child_isolated_files': [],
      'command': ['python', 'touch_root.py'],
      'files': {
        u'isolate.py': {
          'm': 488,
          'h': _sha1('isolate.py'),
          's': _size('isolate.py'),
        },
        os.path.join(u'tests', 'isolate', 'touch_root.py'): {
          'm': 488,
          'h': _sha1('tests', 'isolate', 'touch_root.py'),
          's': _size('tests', 'isolate', 'touch_root.py'),
        },
      },
      'isolate_file': isolate.safe_relpath(
          isolate.trace_inputs.get_native_path_case(isolate_file),
          os.path.dirname(options.isolated)),
      'relative_cwd': os.path.join(u'tests', 'isolate'),
      'variables': {
        'foo': 'bar',
        'PRODUCT_DIR': '.',
        'OS': isolate.get_flavor(),
        'chromeos': chromeos_value,
      },
    }
    self._cleanup_isolated(expected_saved_state)
    self._cleanup_saved_state(actual_saved_state)
    self.assertEqual(expected_saved_state, actual_saved_state)
    self.assertEqual([], os.listdir(self.directory))
예제 #8
0
  def test_load_stale_isolated(self):
    isolate_file = os.path.join(
        ROOT_DIR, 'tests', 'isolate', 'touch_root.isolate')

    # Data to be loaded in the .isolated file. Do not create a .state file.
    input_data = {
      'command': ['python'],
      'files': {
        'foo': {
          "m": 416,
          "h": "invalid",
          "s": 538,
          "t": 1335146921,
        },
        os.path.join('tests', 'isolate', 'touch_root.py'): {
          "m": 488,
          "h": "invalid",
          "s": 538,
          "t": 1335146921,
        },
      },
    }
    options = self._get_option(isolate_file)
    isolate.trace_inputs.write_json(options.isolated, input_data, False)

    # A CompleteState object contains two parts:
    # - Result instance stored in complete_state.isolated, corresponding to the
    #   .isolated file, is what is read by run_test_from_archive.py.
    # - SavedState instance stored in compelte_state.saved_state,
    #   corresponding to the .state file, which is simply to aid the developer
    #   when re-running the same command multiple times and contain
    #   discardable information.
    complete_state = isolate.load_complete_state(options, self.cwd, None, False)
    actual_isolated = complete_state.saved_state.to_isolated()
    actual_saved_state = complete_state.saved_state.flatten()

    expected_isolated = {
      'command': ['python', 'touch_root.py'],
      'files': {
        os.path.join(u'tests', 'isolate', 'touch_root.py'): {
          'm': 488,
          'h': _sha1('tests', 'isolate', 'touch_root.py'),
          's': _size('tests', 'isolate', 'touch_root.py'),
        },
        'isolate.py': {
          'm': 488,
          'h': _sha1('isolate.py'),
          's': _size('isolate.py'),
        },
      },
      'os': isolate.get_flavor(),
      'relative_cwd': os.path.join('tests', 'isolate'),
    }
    self._cleanup_isolated(expected_isolated)
    self.assertEqual(expected_isolated, actual_isolated)

    expected_saved_state = {
      'child_isolated_files': [],
      'command': ['python', 'touch_root.py'],
      'files': {
        os.path.join(u'tests', 'isolate', 'touch_root.py'): {
          'm': 488,
          'h': _sha1('tests', 'isolate', 'touch_root.py'),
          's': _size('tests', 'isolate', 'touch_root.py'),
        },
        u'isolate.py': {
          'm': 488,
          'h': _sha1('isolate.py'),
          's': _size('isolate.py'),
        },
      },
      'isolate_file': isolate.safe_relpath(
          isolate.trace_inputs.get_native_path_case(isolate_file),
          os.path.dirname(options.isolated)),
      'relative_cwd': os.path.join(u'tests', 'isolate'),
      'variables': {
        'foo': 'bar',
        'OS': isolate.get_flavor(),
        'chromeos': options.variables['chromeos'],
      }
    }
    self._cleanup_isolated(expected_saved_state)
    self._cleanup_saved_state(actual_saved_state)
    self.assertEqual(expected_saved_state, actual_saved_state)