diff options
author | Manoj Gupta <manojgupta@google.com> | 2020-04-02 09:46:22 -0700 |
---|---|---|
committer | Manoj Gupta <manojgupta@chromium.org> | 2020-04-02 19:16:40 +0000 |
commit | 8fb2d3d1f70653d340826d561b933c1c4253ff7a (patch) | |
tree | 40fddff9851bd062d99f35d2fd6af5ff6262e7c9 /llvm_tools | |
parent | 58582262e483c0909f98f429225cb2498d086143 (diff) | |
download | toolchain-utils-8fb2d3d1f70653d340826d561b933c1c4253ff7a.tar.gz |
llvm_tools: test_cq: Add more features
Add more features:
1. Choose between llvn and llvm-next
2. Specify list of reviewers for the update CL.
BUG=chromium:1067029
TEST=unit tests
Change-Id: I512c5b5fe944dc49954f9ab82faaf86c8eab983f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2134284
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'llvm_tools')
-rwxr-xr-x | llvm_tools/update_packages_and_test_cq.py | 37 | ||||
-rwxr-xr-x | llvm_tools/update_packages_and_test_cq_unittest.py | 56 |
2 files changed, 83 insertions, 10 deletions
diff --git a/llvm_tools/update_packages_and_test_cq.py b/llvm_tools/update_packages_and_test_cq.py index 0e5e409b..bc8a99e4 100755 --- a/llvm_tools/update_packages_and_test_cq.py +++ b/llvm_tools/update_packages_and_test_cq.py @@ -63,6 +63,20 @@ def GetCommandLineArgs(): default=cros_root, help='the path to the chroot (default: %(default)s)') + # Add argument to choose between llvm and llvm-next. + parser.add_argument( + '--is_llvm_next', + action='store_true', + help= + 'which llvm hash to update. Update LLVM_NEXT_HASH if specified. ' + 'Otherwise, update LLVM_HASH' ) + + # Add argument to add reviewers for the created CL. + parser.add_argument( + '--reviewers', + nargs='+', + help='The reviewers for the package update changelist') + # Add argument for whether to display command contents to `stdout`. parser.add_argument( '--verbose', @@ -125,7 +139,17 @@ def GetCQDependString(dependent_cls): return '\nCq-Depend: ' + ', '.join(('chromium:%s' % i) for i in dependent_cls) -def startCQDryRun(cl, dependent_cls, chroot_path): +def AddReviewers(cl, reviewers, chroot_path): + """Add reviewers for the created CL.""" + + gerrit_abs_path = os.path.join(chroot_path, 'chromite/bin/gerrit') + for reviewer in reviewers: + cmd = [gerrit_abs_path, 'reviewers', str(cl), reviewer] + + ExecCommandAndCaptureOutput(cmd) + + +def StartCQDryRun(cl, dependent_cls, chroot_path): """Start CQ dry run for the changelist and dependencies.""" gerrit_abs_path = os.path.join(chroot_path, 'chromite/bin/gerrit') @@ -170,19 +194,24 @@ def main(): (svn_version, last_svn_version, args_output.last_tested)) return + llvm_variant = update_chromeos_llvm_hash.LLVMVariant.current + if args_output.is_llvm_next: + llvm_variant = update_chromeos_llvm_hash.LLVMVariant.next update_chromeos_llvm_hash.verbose = args_output.verbose extra_commit_msg = GetCQDependString(args_output.extra_change_lists) change_list = update_chromeos_llvm_hash.UpdatePackages( - update_packages, update_chromeos_llvm_hash.LLVMVariant.next, git_hash, - svn_version, args_output.chroot_path, patch_metadata_file, + update_packages, llvm_variant, git_hash, svn_version, + args_output.chroot_path, patch_metadata_file, FailureModes.DISABLE_PATCHES, svn_option, extra_commit_msg) print('Successfully updated packages to %d' % svn_version) print('Gerrit URL: %s' % change_list.url) print('Change list number: %d' % change_list.cl_number) - startCQDryRun(change_list.cl_number, args_output.extra_change_lists, + AddReviewers(change_list.cl_number, args_output.reviewers, + args_output.chroot_path) + StartCQDryRun(change_list.cl_number, args_output.extra_change_lists, args_output.chroot_path) # Updated the packages and submitted tryjobs successfully, so the file will diff --git a/llvm_tools/update_packages_and_test_cq_unittest.py b/llvm_tools/update_packages_and_test_cq_unittest.py index 58f99e83..78f5f136 100755 --- a/llvm_tools/update_packages_and_test_cq_unittest.py +++ b/llvm_tools/update_packages_and_test_cq_unittest.py @@ -45,13 +45,13 @@ class UpdatePackagesAndRunTestCQTest(unittest.TestCase): update_packages_and_test_cq, 'ExecCommandAndCaptureOutput', return_value=None) - def teststartCQDryRunNoDeps(self, mock_exec_cmd): + def testStartCQDryRunNoDeps(self, mock_exec_cmd): chroot_path = '/abs/path/to/chroot' test_cl_number = 1000 # test with no deps cls. extra_cls = [] - update_packages_and_test_cq.startCQDryRun(test_cl_number, extra_cls, + update_packages_and_test_cq.StartCQDryRun(test_cl_number, extra_cls, chroot_path) expected_gerrit_message = [ @@ -67,12 +67,12 @@ class UpdatePackagesAndRunTestCQTest(unittest.TestCase): 'ExecCommandAndCaptureOutput', return_value=None) # test with a single deps cl. - def teststartCQDryRunSingleDep(self, mock_exec_cmd): + def testStartCQDryRunSingleDep(self, mock_exec_cmd): chroot_path = '/abs/path/to/chroot' test_cl_number = 1000 extra_cls = [2000] - update_packages_and_test_cq.startCQDryRun(test_cl_number, extra_cls, + update_packages_and_test_cq.StartCQDryRun(test_cl_number, extra_cls, chroot_path) expected_gerrit_cmd_1 = [ @@ -95,13 +95,13 @@ class UpdatePackagesAndRunTestCQTest(unittest.TestCase): update_packages_and_test_cq, 'ExecCommandAndCaptureOutput', return_value=None) - def teststartCQDryRunMultipleDep(self, mock_exec_cmd): + def testStartCQDryRunMultipleDep(self, mock_exec_cmd): chroot_path = '/abs/path/to/chroot' test_cl_number = 1000 # test with multiple deps cls. extra_cls = [3000, 4000] - update_packages_and_test_cq.startCQDryRun(test_cl_number, extra_cls, + update_packages_and_test_cq.StartCQDryRun(test_cl_number, extra_cls, chroot_path) expected_gerrit_cmd_1 = [ @@ -125,6 +125,50 @@ class UpdatePackagesAndRunTestCQTest(unittest.TestCase): self.assertEqual(mock_exec_cmd.call_args_list[2][0][0], expected_gerrit_cmd_3) + # Mock ExecCommandAndCaptureOutput for the gerrit command execution. + @mock.patch.object( + update_packages_and_test_cq, + 'ExecCommandAndCaptureOutput', + return_value=None) + # test with no reviewers. + def testAddReviewersNone(self, mock_exec_cmd): + chroot_path = '/abs/path/to/chroot' + reviewers = [] + test_cl_number = 1000 + + update_packages_and_test_cq.AddReviewers(test_cl_number, reviewers, + chroot_path) + self.assertTrue(mock_exec_cmd.not_called) + + # Mock ExecCommandAndCaptureOutput for the gerrit command execution. + @mock.patch.object( + update_packages_and_test_cq, + 'ExecCommandAndCaptureOutput', + return_value=None) + # test with multiple reviewers. + def testAddReviewersMultiple(self, mock_exec_cmd): + chroot_path = '/abs/path/to/chroot' + reviewers = ['none1@chromium.org', 'none2@chromium.org'] + test_cl_number = 1000 + + update_packages_and_test_cq.AddReviewers(test_cl_number, reviewers, + chroot_path) + + expected_gerrit_cmd_1 = [ + '%s/chromite/bin/gerrit' % chroot_path, 'reviewers', + str(test_cl_number), 'none1@chromium.org' + ] + expected_gerrit_cmd_2 = [ + '%s/chromite/bin/gerrit' % chroot_path, 'reviewers', + str(test_cl_number), 'none2@chromium.org' + ] + + self.assertEqual(mock_exec_cmd.call_count, 2) + self.assertEqual(mock_exec_cmd.call_args_list[0][0][0], + expected_gerrit_cmd_1) + self.assertEqual(mock_exec_cmd.call_args_list[1][0][0], + expected_gerrit_cmd_2) + if __name__ == '__main__': unittest.main() |