Add new test reporting option.

The new test reporting supports writing the test log with an accessible
index during test execution. Follow-up work will allow resuming from the
previous state of a test report.

Bug: 186607794
Change-Id: I22a11d9e86eb1bdcaf8189a2fa2ebcc251f711f9
diff --git a/tools/test.py b/tools/test.py
index 6f3fe83..685cbf2 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -170,6 +170,14 @@
   result.add_option('--print-times', '--print_times',
       help='Print the execution time of the slowest tests..',
       default=False, action='store_true')
+  result.add_option(
+      '--testing-report',
+      help='Use the custom testing report output format',
+      default=False, action='store_true')
+  result.add_option(
+      '--stacktrace',
+      help='Pass --stacktrace to the gradle run',
+      default=False, action='store_true')
   return result.parse_args()
 
 def archive_failures():
@@ -214,7 +222,11 @@
       shutil.copyfile(library_jar, desugar_jdk_libs)
       print('Desugared library for test in ' + desugar_jdk_libs)
 
-  gradle_args = ['--stacktrace']
+  gradle_args = []
+
+  if options.stacktrace or utils.is_bot():
+    gradle_args.append('--stacktrace')
+
   if utils.is_bot():
     # Bots don't like dangling processes.
     gradle_args.append('--no-daemon')
@@ -301,7 +313,8 @@
     gradle_args.append('-Pdesugar_jdk_json_dir=' + desugar_jdk_json_dir)
   if desugar_jdk_libs:
     gradle_args.append('-Pdesugar_jdk_libs=' + desugar_jdk_libs)
-
+  if options.testing_report:
+    gradle_args.append('-Ptesting-report')
 
   # Build an R8 with dependencies for bootstrapping tests before adding test sources.
   gradle_args.append('r8WithDeps')