summaryrefslogtreecommitdiffstats
path: root/media/libyuv/libyuv/tools_libyuv/autoroller/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'media/libyuv/libyuv/tools_libyuv/autoroller/unittests')
-rwxr-xr-xmedia/libyuv/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py148
-rw-r--r--media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS21
-rw-r--r--media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new13
-rw-r--r--media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old13
4 files changed, 195 insertions, 0 deletions
diff --git a/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py b/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py
new file mode 100755
index 0000000000..af86bdd586
--- /dev/null
+++ b/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py
@@ -0,0 +1,148 @@
+#!/usr/bin/env vpython3
+
+# Copyright 2017 The LibYuv Project Authors. All rights reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS. All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+import glob
+import os
+import shutil
+import sys
+import tempfile
+import unittest
+
+import roll_deps
+from roll_deps import CalculateChangedDeps, GetMatchingDepsEntries, \
+ ParseDepsDict, ParseLocalDepsFile, UpdateDepsFile
+
+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
+PARENT_DIR = os.path.join(SCRIPT_DIR, os.pardir)
+sys.path.append(PARENT_DIR)
+
+TEST_DATA_VARS = {
+ 'chromium_git': 'https://chromium.googlesource.com',
+ 'chromium_revision': '1b9c098a08e40114e44b6c1ec33ddf95c40b901d',
+}
+
+DEPS_ENTRIES = {
+ 'src/build': 'https://build.com',
+ 'src/buildtools': 'https://buildtools.com',
+ 'src/testing/gtest': 'https://gtest.com',
+ 'src/testing/gmock': 'https://gmock.com',
+}
+
+BUILD_OLD_REV = '52f7afeca991d96d68cf0507e20dbdd5b845691f'
+BUILD_NEW_REV = 'HEAD'
+BUILDTOOLS_OLD_REV = '64e38f0cebdde27aa0cfb405f330063582f9ac76'
+BUILDTOOLS_NEW_REV = '55ad626b08ef971fd82a62b7abb325359542952b'
+
+
+class TestError(Exception):
+ pass
+
+
+class FakeCmd():
+ def __init__(self):
+ self.expectations = []
+
+ def add_expectation(self, *args, **kwargs):
+ returns = kwargs.pop('_returns', None)
+ self.expectations.append((args, kwargs, returns))
+
+ def __call__(self, *args, **kwargs):
+ if not self.expectations:
+ raise TestError('Got unexpected\n%s\n%s' % (args, kwargs))
+ exp_args, exp_kwargs, exp_returns = self.expectations.pop(0)
+ if args != exp_args or kwargs != exp_kwargs:
+ message = 'Expected:\n args: %s\n kwargs: %s\n' % (exp_args, exp_kwargs)
+ message += 'Got:\n args: %s\n kwargs: %s\n' % (args, kwargs)
+ raise TestError(message)
+ return exp_returns
+
+
+class TestRollChromiumRevision(unittest.TestCase):
+ def setUp(self):
+ self._output_dir = tempfile.mkdtemp()
+ for test_file in glob.glob(os.path.join(SCRIPT_DIR, 'testdata', '*')):
+ shutil.copy(test_file, self._output_dir)
+ self._libyuv_depsfile = os.path.join(self._output_dir, 'DEPS')
+ self._old_cr_depsfile = os.path.join(self._output_dir, 'DEPS.chromium.old')
+ self._new_cr_depsfile = os.path.join(self._output_dir, 'DEPS.chromium.new')
+
+ self.fake = FakeCmd()
+ self.old_RunCommand = getattr(roll_deps, '_RunCommand')
+ setattr(roll_deps, '_RunCommand', self.fake)
+
+ def tearDown(self):
+ shutil.rmtree(self._output_dir, ignore_errors=True)
+ self.assertEqual(self.fake.expectations, [])
+ setattr(roll_deps, '_RunCommand', self.old_RunCommand)
+
+ def testVarLookup(self):
+ local_scope = {'foo': 'wrong', 'vars': {'foo': 'bar'}}
+ lookup = roll_deps.VarLookup(local_scope)
+ self.assertEqual(lookup('foo'), 'bar')
+
+ def testUpdateDepsFile(self):
+ new_rev = 'aaaaabbbbbcccccdddddeeeeefffff0000011111'
+
+ current_rev = TEST_DATA_VARS['chromium_revision']
+ UpdateDepsFile(self._libyuv_depsfile, current_rev, new_rev, [])
+ with open(self._libyuv_depsfile, 'r') as deps_file:
+ deps_contents = deps_file.read()
+ self.assertTrue(new_rev in deps_contents,
+ 'Failed to find %s in\n%s' % (new_rev, deps_contents))
+
+ def testParseDepsDict(self):
+ with open(self._libyuv_depsfile, 'r') as deps_file:
+ deps_contents = deps_file.read()
+ local_scope = ParseDepsDict(deps_contents)
+ vars_dict = local_scope['vars']
+
+ def assertVar(variable_name):
+ self.assertEqual(vars_dict[variable_name], TEST_DATA_VARS[variable_name])
+ assertVar('chromium_git')
+ assertVar('chromium_revision')
+ self.assertEqual(len(local_scope['deps']), 3)
+
+ def testGetMatchingDepsEntriesReturnsPathInSimpleCase(self):
+ entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing/gtest')
+ self.assertEqual(len(entries), 1)
+ self.assertEqual(entries[0], DEPS_ENTRIES['src/testing/gtest'])
+
+ def testGetMatchingDepsEntriesHandlesSimilarStartingPaths(self):
+ entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/testing')
+ self.assertEqual(len(entries), 2)
+
+ def testGetMatchingDepsEntriesHandlesTwoPathsWithIdenticalFirstParts(self):
+ entries = GetMatchingDepsEntries(DEPS_ENTRIES, 'src/build')
+ self.assertEqual(len(entries), 1)
+ self.assertEqual(entries[0], DEPS_ENTRIES['src/build'])
+
+ def testCalculateChangedDeps(self):
+ _SetupGitLsRemoteCall(self.fake,
+ 'https://chromium.googlesource.com/chromium/src/build', BUILD_NEW_REV)
+ libyuv_deps = ParseLocalDepsFile(self._libyuv_depsfile)
+ new_cr_deps = ParseLocalDepsFile(self._new_cr_depsfile)
+ changed_deps = CalculateChangedDeps(libyuv_deps, new_cr_deps)
+ self.assertEqual(len(changed_deps), 2)
+ self.assertEqual(changed_deps[0].path, 'src/build')
+ self.assertEqual(changed_deps[0].current_rev, BUILD_OLD_REV)
+ self.assertEqual(changed_deps[0].new_rev, BUILD_NEW_REV)
+
+ self.assertEqual(changed_deps[1].path, 'src/buildtools')
+ self.assertEqual(changed_deps[1].current_rev, BUILDTOOLS_OLD_REV)
+ self.assertEqual(changed_deps[1].new_rev, BUILDTOOLS_NEW_REV)
+
+
+def _SetupGitLsRemoteCall(cmd_fake, url, revision):
+ cmd = ['git', 'ls-remote', url, revision]
+ cmd_fake.add_expectation(cmd, _returns=(revision, None))
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS b/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS
new file mode 100644
index 0000000000..4f45860cda
--- /dev/null
+++ b/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS
@@ -0,0 +1,21 @@
+# DEPS file for unit tests.
+
+vars = {
+ 'chromium_git': 'https://chromium.googlesource.com',
+ 'chromium_revision': '1b9c098a08e40114e44b6c1ec33ddf95c40b901d',
+ 'ignored_str': Str(''),
+}
+
+deps = {
+ # Entry that is a directory in Chromium, so we're using a Git subtree mirror for it.
+ 'src/build':
+ Var('chromium_git') + '/chromium/src/build' + '@' + '52f7afeca991d96d68cf0507e20dbdd5b845691f',
+
+ # Entry that's also a DEPS entry in the Chromium DEPS file.
+ 'src/buildtools':
+ Var('chromium_git') + '/chromium/buildtools.git' + '@' + '64e38f0cebdde27aa0cfb405f330063582f9ac76',
+
+ # Entry only present in libyuv, not Chromium.
+ 'src/third_party/gflags/src':
+ Var('chromium_git') + '/external/github.com/gflags/gflags@03bebcb065c83beff83d50ae025a55a4bf94dfca',
+}
diff --git a/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new b/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new
new file mode 100644
index 0000000000..d53083ceec
--- /dev/null
+++ b/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new
@@ -0,0 +1,13 @@
+# DEPS file for unit tests.
+
+vars = {
+ 'chromium_git': 'https://chromium.googlesource.com',
+
+ # This is updated compared to the DEPS.chromium.old file.
+ 'buildtools_revision': '55ad626b08ef971fd82a62b7abb325359542952b',
+}
+
+deps = {
+ 'src/buildtools':
+ Var('chromium_git') + '/chromium/buildtools.git' + '@' + Var('buildtools_revision'),
+}
diff --git a/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old b/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old
new file mode 100644
index 0000000000..dd6ddaec81
--- /dev/null
+++ b/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old
@@ -0,0 +1,13 @@
+# DEPS file for unit tests.
+
+vars = {
+ 'chromium_git': 'https://chromium.googlesource.com',
+
+ # This is and older revision than DEPS.chromium.new file.
+ 'buildtools_revision': '64e38f0cebdde27aa0cfb405f330063582f9ac76',
+}
+
+deps = {
+ 'src/buildtools':
+ Var('chromium_git') + '/chromium/buildtools.git' + '@' + Var('buildtools_revision'),
+}