Save target lists to json files

Introduce a new command line argument `--target-list-dir` to
run_all_fuzzers.py. When this arg presents, the script will save
the lists of successful targets and all targets to the designated
directory. `fuzz.py` will later upload those files to gcs.

Chromium code coverage dashboard UI will fetch the list and use that
to populate test types dropdown.

Bug: 416037384
Change-Id: Id13f21f30ed21ff26cc3352c740867221ac1e9d2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6526087
Reviewed-by: Prakhar Asthana <[email protected]>
Commit-Queue: Weizhong Xia <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1467105}
NOKEYCHECK=True
GitOrigin-RevId: a102375ce96ae9f008cdd9f3d141b299fd0d1da8
diff --git a/run_all_fuzzers.py b/run_all_fuzzers.py
index b6ea4c6..4eaa9ab 100644
--- a/run_all_fuzzers.py
+++ b/run_all_fuzzers.py
@@ -613,6 +613,11 @@
                           default=LIBFUZZER,
                           help='The type of fuzzer tests to run.')
 
+  arg_parser.add_argument(
+      '--target-list-dir',
+      type=str,
+      help='Directory where the json files for target list will be stored.')
+
   arg_parser.add_argument
   args = arg_parser.parse_args()
   return args
@@ -787,6 +792,14 @@
   logging.info('Successful targets: %s', verified_fuzzer_targets)
   logging.info('Failed targets: %s', failed_targets)
 
+  if args.target_list_dir:
+    json_path = os.path.join(args.target_list_dir, args.fuzzer + '.json')
+    with open(json_path, "w") as fp:
+      json.dump(list(verified_fuzzer_targets), fp)
+    json_path = os.path.join(args.target_list_dir, args.fuzzer + '_all.json')
+    with open(json_path, "w") as fp:
+      json.dump(list(verified_fuzzer_targets) + list(failed_targets), fp)
+
   logging.info('Finished getting coverage information. Copying to %s',
                args.profdata_outdir)
   for fuzzer in verified_fuzzer_targets: