diff --git a/tensorflow/lite/testing/generate_examples_lib.py b/tensorflow/lite/testing/generate_examples_lib.py index db324229541..8fe32c28846 100644 --- a/tensorflow/lite/testing/generate_examples_lib.py +++ b/tensorflow/lite/testing/generate_examples_lib.py @@ -333,5 +333,6 @@ def generate_multi_set_examples(options, test_sets): generate_examples(new_options) - archive.writestr("manifest.txt", "".join(multi_gen_state.zip_manifest), + zipinfo = zipfile.ZipInfo("manifest.txt") + archive.writestr(zipinfo, "".join(multi_gen_state.zip_manifest), zipfile.ZIP_DEFLATED) diff --git a/tensorflow/lite/testing/generate_examples_report.py b/tensorflow/lite/testing/generate_examples_report.py index 19d3382d435..64598e5f898 100644 --- a/tensorflow/lite/testing/generate_examples_report.py +++ b/tensorflow/lite/testing/generate_examples_report.py @@ -23,6 +23,7 @@ from __future__ import print_function import html import json +import re FAILED = "FAILED" SUCCESS = "SUCCESS" @@ -76,8 +77,8 @@ log.innerHTML = "
" + data[row][col]  + "
"; } """) fp.write("var data = \n") - logs = json.dumps([[html.escape(x[1]["tf_log"], quote=True), - html.escape(x[1]["converter_log"], quote=True) + logs = json.dumps([[escape_and_normalize(x[1]["tf_log"]), + escape_and_normalize(x[1]["converter_log"]) ] for x in reports]) fp.write(logs) fp.write(";\n") @@ -124,3 +125,12 @@ log.innerHTML = "
" + data[row][col]  + "
"; """) + + +def escape_and_normalize(log): + # These logs contain paths like /tmp/tmpgmypg3xa that are inconsistent between + # builds. This replaces these inconsistent paths with a consistent placeholder + # so the output is deterministic. + log = re.sub(r"/tmp/[^ ]+ ", "/NORMALIZED_TMP_FILE_PATH ", log) + log = re.sub(r"/build/work/[^/]+", "/NORMALIZED_BUILD_PATH", log) + return html.escape(log, quote=True) diff --git a/tensorflow/lite/testing/zip_test_utils.py b/tensorflow/lite/testing/zip_test_utils.py index 4639ce0a515..86b662042b9 100644 --- a/tensorflow/lite/testing/zip_test_utils.py +++ b/tensorflow/lite/testing/zip_test_utils.py @@ -478,8 +478,8 @@ def make_zip_of_tests(options, report["converter_log"] = toco_log if options.save_graphdefs: - archive.writestr(zip_path_label + ".pbtxt", - text_format.MessageToString(graph_def), + zipinfo = zipfile.ZipInfo(zip_path_label + ".pbtxt") + archive.writestr(zipinfo, text_format.MessageToString(graph_def), zipfile.ZIP_DEFLATED) if tflite_model_binary: @@ -487,19 +487,20 @@ def make_zip_of_tests(options, # Set proper min max values according to input dtype. baseline_inputs, baseline_outputs = generate_inputs_outputs( tflite_model_binary, min_value=0, max_value=255) - archive.writestr(zip_path_label + ".bin", tflite_model_binary, - zipfile.ZIP_DEFLATED) + zipinfo = zipfile.ZipInfo(zip_path_label + ".bin") + archive.writestr(zipinfo, tflite_model_binary, zipfile.ZIP_DEFLATED) example = {"inputs": baseline_inputs, "outputs": baseline_outputs} example_fp = StringIO() write_examples(example_fp, [example]) - archive.writestr(zip_path_label + ".inputs", example_fp.getvalue(), - zipfile.ZIP_DEFLATED) + zipinfo = zipfile.ZipInfo(zip_path_label + ".inputs") + archive.writestr(zipinfo, example_fp.getvalue(), zipfile.ZIP_DEFLATED) example_fp2 = StringIO() write_test_cases(example_fp2, zip_path_label + ".bin", [example]) - archive.writestr(zip_path_label + "_tests.txt", - example_fp2.getvalue(), zipfile.ZIP_DEFLATED) + zipinfo = zipfile.ZipInfo(zip_path_label + "_tests.txt") + archive.writestr(zipinfo, example_fp2.getvalue(), + zipfile.ZIP_DEFLATED) zip_manifest_label = zip_path_label + " " + label if zip_path_label == label: @@ -529,16 +530,18 @@ def make_zip_of_tests(options, report_io = StringIO() report_lib.make_report_table(report_io, zip_path, convert_report) if options.multi_gen_state: - archive.writestr("report_" + options.multi_gen_state.test_name + ".html", - report_io.getvalue()) + zipinfo = zipfile.ZipInfo("report_" + options.multi_gen_state.test_name + + ".html") + archive.writestr(zipinfo, report_io.getvalue()) else: - archive.writestr("report.html", report_io.getvalue()) + zipinfo = zipfile.ZipInfo("report.html") + archive.writestr(zipinfo, report_io.getvalue()) if options.multi_gen_state: options.multi_gen_state.zip_manifest.extend(zip_manifest) else: - archive.writestr("manifest.txt", "".join(zip_manifest), - zipfile.ZIP_DEFLATED) + zipinfo = zipfile.ZipInfo("manifest.txt") + archive.writestr(zipinfo, "".join(zip_manifest), zipfile.ZIP_DEFLATED) # Log statistics of what succeeded total_conversions = len(convert_report)