Add --land option to test.py

Change-Id: Ib5f2cc88bd2ec747314462706bb2d7b488d91a8f
diff --git a/tools/test.py b/tools/test.py
index 16bb545..c071e71 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -264,6 +264,14 @@
                         help='Pass --no-daemon to the gradle run',
                         default=False,
                         action='store_true')
+    result.add_argument('--land',
+                        help='Land current CL if tests pass',
+                        default=False,
+                        action='store_true')
+    result.add_argument('--land-bypass-hooks',
+                        help='Pass --bypass-hooks to `git cl land`',
+                        default=False,
+                        action='store_true')
     result.add_argument('--low-priority',
                         help='Run gradle with priority=low (higher niceness)',
                         default=False,
@@ -278,7 +286,10 @@
                         help='Specify to run tests on older kotlin compilers',
                         default=False,
                         action='store_true')
-    return result.parse_known_args()
+    options, args = result.parse_known_args()
+    if options.land_bypass_hooks:
+        options.land = True
+    return options, args
 
 
 def has_failures(classes_file):
@@ -337,8 +348,16 @@
         os.symlink("/usr/lib/x86_64-linux-gnu/libncurses.so.6",
                    art7 + "/lib64/libtinfo.so.5")
 
+
 def Main():
     (options, args) = ParseOptions()
+    return_code = test(options, args)
+    if return_code == 0 and options.land:
+        land(options)
+    return return_code
+
+
+def test(options, args):
     if utils.is_bot():
         gradle.RunGradle(['--no-daemon', 'clean'])
         print('Running with python ' + str(sys.version_info))
@@ -630,6 +649,13 @@
     return return_code
 
 
+def land(options):
+    cmd = ['git', 'cl', 'land']
+    if options.land_bypass_hooks:
+        cmd.append('--bypass-hooks')
+    subprocess.check_call(cmd)
+
+
 def print_jstacks():
     processes = subprocess.check_output(['ps', 'aux']).decode('utf-8')
     for l in processes.splitlines():