Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / tools / swarming_client / tests / isolate_smoke_test.py
index e9ffbb0..2602707 100755 (executable)
@@ -20,11 +20,8 @@ ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 sys.path.insert(0, ROOT_DIR)
 
 import isolate
-import isolateserver
+import isolated_format
 from utils import file_path
-import trace_test_util
-# Create shortcuts.
-from isolate_format import KEY_TOUCHED, KEY_TRACKED, KEY_UNTRACKED
 
 
 VERBOSE = False
@@ -178,14 +175,10 @@ class Isolate(unittest.TestCase):
     EXPECTED_MODES = (
         'archive',
         'check',
-        'hashtable',
         'help',
-        'merge',
-        'read',
         'remap',
         'rewrite',
         'run',
-        'trace',
     )
     # If a new command is added it should at least has a bare test.
     self.assertEqual(sorted(EXPECTED_MODES), sorted(modes))
@@ -205,7 +198,7 @@ class IsolateTempdir(unittest.TestCase):
       super(IsolateTempdir, self).tearDown()
 
   def _gen_files(self, read_only, empty_file, with_time):
-    """Returns a dict of files like calling isolate.process_input() on each
+    """Returns a dict of files like calling isolate.files_to_metadata() on each
     file.
 
     Arguments:
@@ -237,7 +230,7 @@ class IsolateTempdir(unittest.TestCase):
         # Upgrade the value to unicode so diffing the structure in case of
         # test failure is easier, since the basestring type must match,
         # str!=unicode.
-        v[u'h'] = unicode(isolateserver.hash_file(filepath, ALGO))
+        v[u'h'] = unicode(isolated_format.hash_file(filepath, ALGO))
 
     if empty_file:
       item = files[empty_file]
@@ -256,7 +249,7 @@ class IsolateTempdir(unittest.TestCase):
       u'algo': u'sha-1',
       u'files': self._gen_files(read_only, empty_file, False),
       u'relative_cwd': unicode(RELATIVE_CWD[self.case()]),
-      u'version': unicode(isolate.isolateserver.ISOLATED_FILE_VERSION),
+      u'version': unicode(isolated_format.ISOLATED_FILE_VERSION),
     }
     if read_only is not None:
       expected[u'read_only'] = read_only
@@ -299,7 +292,7 @@ class IsolateTempdir(unittest.TestCase):
         args, read_only, empty_file, extra_vars, root_dir)
     # Also verifies run_isolated.py will be able to read it.
     with open(self.isolated, 'rb') as f:
-      isolate.isolateserver.load_isolated(f.read(), ALGO)
+      isolated_format.load_isolated(f.read(), ALGO)
 
   def _expect_no_result(self):
     self.assertFalse(os.path.exists(self.isolated))
@@ -490,154 +483,6 @@ class Isolate_check(IsolateTempdir):
       self._expect_results(['symlink_outside_build_root.py'], None, None, None)
 
 
-class Isolate_hashtable(IsolateOutdir):
-  def _gen_expected_tree(self, empty_file):
-    expected = [
-      unicode(v['h'])
-      for v in self._gen_files(False, empty_file, False).itervalues()
-    ]
-    expected.append(
-        unicode(isolateserver.hash_file(self.isolated, ALGO)))
-    return expected
-
-  def _expected_hash_tree(self, empty_file):
-    """Verifies the files written in the temporary directory."""
-    self.assertEqual(
-        sorted(self._gen_expected_tree(empty_file)),
-        map(unicode, self._result_tree()))
-
-  def test_fail(self):
-    self._execute('hashtable', 'fail.isolate', [], False)
-    self._expected_hash_tree(None)
-    self._expect_results(['fail.py'], None, None, None)
-
-  def test_missing_trailing_slash(self):
-    self._test_missing_trailing_slash('hashtable')
-
-  def test_non_existent(self):
-    self._test_non_existent('hashtable')
-
-  def test_all_items_invalid(self):
-    out = self._test_all_items_invalid('hashtable')
-    expected = (
-        '%s  isolate_smoke_test.isolated\n' %
-        isolateserver.hash_file(self.isolated, ALGO))
-    self.assertEqual(expected, out)
-    self._expected_hash_tree(None)
-
-  def test_no_run(self):
-    self._execute('hashtable', 'no_run.isolate', [], False)
-    self._expected_hash_tree(None)
-    self._expect_results([], None, None, None)
-
-  def test_split(self):
-    self._execute(
-        'hashtable',
-        'split.isolate',
-        [
-          '--path-variable', 'DEPTH', '.',
-          '--path-variable', 'PRODUCT_DIR', 'files1',
-        ],
-        False,
-        cwd=os.path.join(ROOT_DIR, 'tests', 'isolate'))
-    # Reimplement _expected_hash_tree():
-    tree = self._gen_expected_tree(None)
-    isolated_base = self.isolated[:-len('.isolated')]
-    isolated_hashes = [
-      unicode(isolateserver.hash_file(isolated_base + '.0.isolated', ALGO)),
-      unicode(isolateserver.hash_file(isolated_base + '.1.isolated', ALGO)),
-    ]
-    tree.extend(isolated_hashes)
-    self.assertEqual(sorted(tree), map(unicode, self._result_tree()))
-
-    # Reimplement _expected_isolated():
-    files = self._gen_files(None, None, False)
-    expected = {
-      u'algo': u'sha-1',
-      u'command': [u'python', u'split.py'],
-      u'files': {u'split.py': files['split.py']},
-      u'includes': isolated_hashes,
-      u'relative_cwd': unicode(RELATIVE_CWD[self.case()]),
-      u'version': unicode(isolate.isolateserver.ISOLATED_FILE_VERSION),
-    }
-    self.assertEqual(expected, json.load(open(self.isolated, 'r')))
-
-    key = os.path.join(u'test', 'data', 'foo.txt')
-    expected = {
-      u'algo': u'sha-1',
-      u'files': {key: files[key]},
-      u'version': unicode(isolate.isolateserver.ISOLATED_FILE_VERSION),
-    }
-    self.assertEqual(
-        expected, json.load(open(isolated_base + '.0.isolated', 'r')))
-
-    key = os.path.join(u'files1', 'subdir', '42.txt')
-    expected = {
-      u'algo': u'sha-1',
-      u'files': {key: files[key]},
-      u'version': unicode(isolate.isolateserver.ISOLATED_FILE_VERSION),
-    }
-    self.assertEqual(
-        expected, json.load(open(isolated_base + '.1.isolated', 'r')))
-
-  # TODO(csharp): Disabled until crbug.com/150823 is fixed.
-  def do_not_test_touch_only(self):
-    self._execute(
-        'hashtable', 'touch_only.isolate', ['--extra-variable', 'FLAG', 'gyp'],
-        False)
-    empty = os.path.join('files1', 'test_file1.txt')
-    self._expected_hash_tree(empty)
-    self._expected_isolated(['touch_only.py', 'gyp'], None, empty)
-
-  def test_touch_root(self):
-    self._execute('hashtable', 'touch_root.isolate', [], False)
-    self._expected_hash_tree(None)
-    self._expect_results(['touch_root.py'], None, None, None, ROOT_DIR)
-
-  def test_with_flag(self):
-    self._execute(
-        'hashtable', 'with_flag.isolate', ['--extra-variable', 'FLAG', 'gyp'],
-        False)
-    self._expected_hash_tree(None)
-    self._expect_results(
-        ['with_flag.py', 'gyp'], None, {u'FLAG': u'gyp'}, None)
-
-  if sys.platform != 'win32':
-    def test_symlink_full(self):
-      self._execute('hashtable', 'symlink_full.isolate', [], False)
-      # Construct our own tree.
-      expected = [
-        str(v['h'])
-        for v in self._gen_files(False, None, False).itervalues() if 'h' in v
-      ]
-      expected.append(isolateserver.hash_file(self.isolated, ALGO))
-      self.assertEqual(sorted(expected), self._result_tree())
-      self._expect_results(['symlink_full.py'], None, None, None)
-
-    def test_symlink_partial(self):
-      self._execute('hashtable', 'symlink_partial.isolate', [], False)
-      # Construct our own tree.
-      expected = [
-        str(v['h'])
-        for v in self._gen_files(False, None, False).itervalues() if 'h' in v
-      ]
-      expected.append(isolateserver.hash_file(self.isolated, ALGO))
-      self.assertEqual(sorted(expected), self._result_tree())
-      self._expect_results(['symlink_partial.py'], None, None, None)
-
-    def test_symlink_outside_build_root(self):
-      self._execute(
-          'hashtable', 'symlink_outside_build_root.isolate', [], False)
-      # Construct our own tree.
-      expected = [
-        str(v['h'])
-        for v in self._gen_files(False, None, False).itervalues() if 'h' in v
-      ]
-      expected.append(isolateserver.hash_file(self.isolated, ALGO))
-      self.assertEqual(sorted(expected), self._result_tree())
-      self._expect_results(['symlink_outside_build_root.py'], None, None, None)
-
-
 class Isolate_remap(IsolateOutdir):
   def test_fail(self):
     self._execute('remap', 'fail.isolate', [], False)
@@ -761,160 +606,6 @@ class Isolate_run(IsolateTempdir):
       self._expect_results(['symlink_outside_build_root.py'], None, None, None)
 
 
-class Isolate_trace_read_merge(IsolateTempdir):
-  # Tests both trace, read and merge.
-  # Warning: merge updates .isolate files. But they are currently in their
-  # canonical format so they shouldn't be changed.
-  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' % file_path.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)
-
-  @trace_test_util.check_can_trace
-  def test_fail(self):
-    # Even if the process returns non-zero, the trace will still be good.
-    try:
-      self._execute('trace', 'fail.isolate', ['-v'], True)
-      self.fail()
-    except subprocess.CalledProcessError, e:
-      self.assertEqual('', e.output)
-    self._expect_results(['fail.py'], None, None, None)
-    expected = _wrap_in_condition(
-        {
-          KEY_TRACKED: ['fail.py'],
-        })
-    out = self._execute('read', 'fail.isolate', [], True) or ''
-    self.assertEqual(expected.splitlines(), out.splitlines())
-    self._check_merge('fail.isolate')
-
-  def test_missing_trailing_slash(self):
-    self._test_missing_trailing_slash('trace')
-
-  def test_non_existent(self):
-    self._test_non_existent('trace')
-
-  @trace_test_util.check_can_trace
-  def test_all_items_invalid(self):
-    out = self._test_all_items_invalid('trace')
-    self.assertEqual('', out)
-
-  def test_no_run(self):
-    try:
-      self._execute('trace', 'no_run.isolate', [], True)
-      self.fail()
-    except subprocess.CalledProcessError, e:
-      out = e.output
-      err = e.stderr
-    self._expect_no_result()
-    expected = 'No command to run.'
-    self.assertEqual('', out)
-    self.assertIn(expected, err)
-
-  # TODO(csharp): Disabled until crbug.com/150823 is fixed.
-  def do_not_test_touch_only(self):
-    out = self._execute(
-        'trace', 'touch_only.isolate', ['--extra-variable', 'FLAG', 'trace'],
-        True)
-    self.assertEqual('', out)
-    empty = os.path.join('files1', 'test_file1.txt')
-    self._expect_results(
-        ['touch_only.py', 'trace'], None, {u'FLAG': u'trace'}, empty)
-    expected = {
-      KEY_TRACKED: ['touch_only.py'],
-      # Note that .isolate format mandates / and not os.path.sep.
-      KEY_TOUCHED: ['files1/test_file1.txt'],
-    }
-    if sys.platform != 'linux2':
-      # TODO(maruel): Implement touch-only tracing on non-linux.
-      del expected[KEY_TOUCHED]
-
-    out = self._execute('read', 'touch_only.isolate', [], True)
-    self.assertEqual(_wrap_in_condition(expected), out)
-    self._check_merge('touch_only.isolate')
-
-  @trace_test_util.check_can_trace
-  def test_touch_root(self):
-    out = self._execute('trace', 'touch_root.isolate', [], True)
-    self.assertEqual('', out)
-    self._expect_results(['touch_root.py'], None, None, None, ROOT_DIR)
-    expected = _wrap_in_condition(
-        {
-          KEY_TRACKED: [
-            '../../isolate.py',
-            'touch_root.py',
-          ],
-        })
-    out = self._execute('read', 'touch_root.isolate', [], True)
-    self.assertEqual(expected, out)
-    self._check_merge('touch_root.isolate')
-
-  @trace_test_util.check_can_trace
-  def test_with_flag(self):
-    out = self._execute(
-        'trace', 'with_flag.isolate', ['--extra-variable', 'FLAG', 'trace'],
-        True)
-    self.assertEqual('', out)
-    self._expect_results(
-        ['with_flag.py', 'trace'], None, {u'FLAG': u'trace'}, None)
-    expected = {
-      KEY_TRACKED: ['with_flag.py'],
-      # Note that .isolate format mandates / and not os.path.sep.
-      KEY_UNTRACKED: ['files1/'],
-    }
-    out = self._execute('read', 'with_flag.isolate', [], True)
-    self.assertEqual(_wrap_in_condition(expected), out)
-    self._check_merge('with_flag.isolate')
-
-  if sys.platform != 'win32':
-    def test_symlink_full(self):
-      out = self._execute(
-          'trace', 'symlink_full.isolate', [], True)
-      self.assertEqual('', out)
-      self._expect_results(['symlink_full.py'], None, None, None)
-      expected = {
-        KEY_TRACKED: ['symlink_full.py'],
-        # Note that .isolate format mandates / and not os.path.sep.
-        KEY_UNTRACKED: ['files2/'],
-      }
-      out = self._execute('read', 'symlink_full.isolate', [], True)
-      self.assertEqual(_wrap_in_condition(expected), out)
-      self._check_merge('symlink_full.isolate')
-
-    def test_symlink_partial(self):
-      out = self._execute(
-          'trace', 'symlink_partial.isolate', [], True)
-      self.assertEqual('', out)
-      self._expect_results(['symlink_partial.py'], None, None, None)
-      expected = {
-        KEY_TRACKED: ['symlink_partial.py'],
-        KEY_UNTRACKED: ['files2/test_file2.txt'],
-      }
-      out = self._execute('read', 'symlink_partial.isolate', [], True)
-      self.assertEqual(_wrap_in_condition(expected), out)
-      self._check_merge('symlink_partial.isolate')
-
-    def test_symlink_outside_build_root(self):
-      out = self._execute(
-          'trace', 'symlink_outside_build_root.isolate', [], True)
-      self.assertEqual('', out)
-      self._expect_results(['symlink_outside_build_root.py'], None, None, None)
-      expected = {
-        KEY_TRACKED: ['symlink_outside_build_root.py'],
-        KEY_UNTRACKED: ['link_outside_build_root/'],
-      }
-      out = self._execute(
-          'read', 'symlink_outside_build_root.isolate', [], True)
-      self.assertEqual(_wrap_in_condition(expected), out)
-      self._check_merge('symlink_outside_build_root.isolate')
-
-
 class IsolateNoOutdir(IsolateTempdir):
   # Test without the --outdir flag.
   # So all the files are first copied in the tempdir and the test is run from
@@ -992,10 +683,6 @@ class IsolateNoOutdir(IsolateTempdir):
     ])
     self.assertEqual(files, list_files_tree(self.tempdir))
 
-  def test_hashtable(self):
-    with self.assertRaises(CalledProcessError):
-      self._execute('hashtable', ['--isolate', self.filename()], False)
-
   def test_remap(self):
     with self.assertRaises(CalledProcessError):
       self._execute('remap', ['--isolate', self.filename()], False)
@@ -1011,39 +698,6 @@ class IsolateNoOutdir(IsolateTempdir):
     ])
     self.assertEqual(files, list_files_tree(self.tempdir))
 
-  @trace_test_util.check_can_trace
-  def test_trace_read_merge(self):
-    self._execute('trace', ['--isolate', self.filename()], False)
-    # Read the trace before cleaning up. No need to specify self.filename()
-    # because add the needed information is in the .state file.
-    output = self._execute('read', [], True)
-    expected = {
-      KEY_TRACKED: [
-        '../../isolate.py',
-        'touch_root.py',
-      ],
-    }
-    self.assertEqual(_wrap_in_condition(expected), output)
-
-    output = self._execute('merge', [], True)
-    expected = 'Updating %s\n' % os.path.join(
-        'root', 'tests', 'isolate', 'touch_root.isolate')
-    self.assertEqual(expected, output)
-    # In theory the file is going to be updated but in practice its content
-    # won't change.
-
-    # Clean the directory from the logs, which are OS-specific.
-    isolate.trace_inputs.get_api().clean_trace(
-        os.path.join(self.tempdir, 'isolate_smoke_test.isolated.log'))
-    files = sorted([
-      'isolate_smoke_test.isolated',
-      'isolate_smoke_test.isolated.state',
-      os.path.join('root', 'tests', 'isolate', 'touch_root.isolate'),
-      os.path.join('root', 'tests', 'isolate', 'touch_root.py'),
-      os.path.join('root', 'isolate.py'),
-    ])
-    self.assertEqual(files, list_files_tree(self.tempdir))
-
 
 class IsolateOther(IsolateTempdir):
   def test_run_mixed(self):