Add a way to pass additional machine information in lnt importreport (#172)
diff --git a/lnt/lnttool/import_report.py b/lnt/lnttool/import_report.py index 46f51fc..05ba45c 100644 --- a/lnt/lnttool/import_report.py +++ b/lnt/lnttool/import_report.py
@@ -12,12 +12,17 @@ "Ex: a svn revision, or timestamp.") @click.option("--machine", required=True, help="the name of the machine to submit under") -@click.option("--run-info", multiple=True, type=str, +@click.option("--run-info", "run_info", multiple=True, type=str, help="Optional additional run information to include in the submission. " "If provided, this must be a key-value pair separated by '='. This " "argument may be repeated multiple times to provide multiple keys " "and values in the run information.") -def action_importreport(input, output, suite, order, machine, run_info): +@click.option("--machine-info", "machine_info", multiple=True, type=str, + help="Optional additional machine information to include in the submission. " + "If provided, this must be a key-value pair separated by '='. This " + "argument may be repeated multiple times to provide multiple keys " + "and values in the machine information.") +def action_importreport(input, output, suite, order, machine, run_info, machine_info): """Import simple data into LNT. This takes a space separated key value file and creates an LNT report file, which can be submitted to an LNT server. Example input file: @@ -33,22 +38,26 @@ import lnt.testing import os - machine = lnt.testing.Machine(machine, report_version=2) - - parsed_info = {} + # Build the run with any additional info + run_info_dict = {} for s in run_info: if '=' not in s: raise click.BadParameter(f"--run-info must be in 'key=value' format, got: {s}") k, v = s.split('=', 1) # Split only on the first '=' in case there are several in the string - parsed_info[k] = v - run_info = parsed_info - run_info.update({'llvm_project_revision': order}) - + run_info_dict[k] = v + run_info_dict.update({'llvm_project_revision': order}) ctime = os.path.getctime(input.name) mtime = os.path.getmtime(input.name) - run = lnt.testing.Run(start_time=ctime, end_time=mtime, - info=run_info, - report_version=2) + run = lnt.testing.Run(start_time=ctime, end_time=mtime, info=run_info_dict, report_version=2) + + # Build the machine with any additional info + machine_info_dict = {} + for s in machine_info: + if '=' not in s: + raise click.BadParameter(f"--machine-info must be in 'key=value' format, got: {s}") + k, v = s.split('=', 1) # Split only on the first '=' in case there are several in the string + machine_info_dict[k] = v + machine = lnt.testing.Machine(machine, info=machine_info_dict, report_version=2) tests = {} # name => lnt.testing.Test for line in input.readlines():
diff --git a/tests/lnttool/importreport.machine-info.shtest b/tests/lnttool/importreport.machine-info.shtest new file mode 100644 index 0000000..1efa887 --- /dev/null +++ b/tests/lnttool/importreport.machine-info.shtest
@@ -0,0 +1,70 @@ +# +# Ensure that we can pass additional machine information with `lnt importreport`. +# + +# Pass one machine information. +# +# RUN: lnt importreport --testsuite nts --order 123 --machine foo --machine-info os=macos %S/Inputs/example_metrics.lnt %t.1.json +# RUN: filecheck --check-prefix=CHECK-1 --input-file %t.1.json %s +# CHECK-1: { +# CHECK-1-NEXT: "format_version": "2", +# CHECK-1-NEXT: "machine": { +# CHECK-1-NEXT: "name": "foo", +# CHECK-1-NEXT: "os": "macos" +# CHECK-1-NEXT: }, +# CHECK-1-NEXT: "run": { +# CHECK-1-NEXT: "end_time": "{{.+}}", +# CHECK-1-NEXT: "llvm_project_revision": "123", +# CHECK-1-NEXT: "start_time": "{{.+}}" +# CHECK-1-NEXT: }, +# CHECK-1-NEXT: "tests": [ +# CHECK-1-NEXT: { +# CHECK-1-NEXT: "execution_time": [ +# CHECK-1-NEXT: 10.0, +# CHECK-1-NEXT: 11.0 +# CHECK-1-NEXT: ], +# CHECK-1-NEXT: "hash": "d7", +# CHECK-1-NEXT: "name": "foo" +# CHECK-1-NEXT: }, +# CHECK-1-NEXT: { +# CHECK-1-NEXT: "execution_time": 20.0, +# CHECK-1-NEXT: "name": "bar", +# CHECK-1-NEXT: "profile": "Xz6/" +# CHECK-1-NEXT: } +# CHECK-1-NEXT: ] +# CHECK-1-NEXT: } + +# Pass multiple machine informations. +# +# RUN: lnt importreport --testsuite nts --order 123 --machine foo \ +# RUN: --machine-info cpu=8 --machine-info os=macos \ +# RUN: %S/Inputs/example_metrics.lnt %t.2.json +# RUN: filecheck --check-prefix=CHECK-2 --input-file %t.2.json %s +# CHECK-2: { +# CHECK-2-NEXT: "format_version": "2", +# CHECK-2-NEXT: "machine": { +# CHECK-2-NEXT: "cpu": "8", +# CHECK-2-NEXT: "name": "foo", +# CHECK-2-NEXT: "os": "macos" +# CHECK-2-NEXT: }, +# CHECK-2-NEXT: "run": { +# CHECK-2-NEXT: "end_time": "{{.+}}", +# CHECK-2-NEXT: "llvm_project_revision": "123", +# CHECK-2-NEXT: "start_time": "{{.+}}" +# CHECK-2-NEXT: }, +# CHECK-2-NEXT: "tests": [ +# CHECK-2-NEXT: { +# CHECK-2-NEXT: "execution_time": [ +# CHECK-2-NEXT: 10.0, +# CHECK-2-NEXT: 11.0 +# CHECK-2-NEXT: ], +# CHECK-2-NEXT: "hash": "d7", +# CHECK-2-NEXT: "name": "foo" +# CHECK-2-NEXT: }, +# CHECK-2-NEXT: { +# CHECK-2-NEXT: "execution_time": 20.0, +# CHECK-2-NEXT: "name": "bar", +# CHECK-2-NEXT: "profile": "Xz6/" +# CHECK-2-NEXT: } +# CHECK-2-NEXT: ] +# CHECK-2-NEXT: }