Skip to content

Commit d2339d3

Browse files
authored
Generate JSON reports in format V2 when using lnt importreport (llvm#72)
It seems that a transition towards a new input format had been started a long time ago, however several parts of the codebase don't seem to be producing the latest format yet. This moves `lnt importreport` to the latest format. As part of the patch, fix capitalization of `Name` for the `Machine` and the `Test` classes, which didn't match the capitalization documented and expected by the rest of the code.
1 parent 7cd5f1e commit d2339d3

File tree

6 files changed

+65
-32
lines changed

6 files changed

+65
-32
lines changed

lnt/lnttool/import_report.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,30 @@ def action_importreport(input, output, suite, order, machine):
2828
import lnt.testing
2929
import os
3030

31-
machine_info = {}
32-
run_info = {'tag': suite}
33-
run_info['run_order'] = order
34-
machine = lnt.testing.Machine(machine,
35-
machine_info)
31+
machine = lnt.testing.Machine(machine, report_version=2)
32+
3633
ctime = os.path.getctime(input.name)
3734
mtime = os.path.getmtime(input.name)
35+
run = lnt.testing.Run(start_time=ctime, end_time=mtime,
36+
info={'llvm_project_revision': order},
37+
report_version=2)
3838

39-
run = lnt.testing.Run(ctime, mtime, run_info)
40-
report = lnt.testing.Report(machine=machine, run=run, tests=[])
41-
39+
tests = {} # name => lnt.testing.Test
4240
for line in input.readlines():
4341
key, val = line.split()
44-
metric = key.split(".")[1]
42+
(testname, metric) = key.split(".")
4543
metric_type = float if metric not in ("hash", "profile") else str
46-
test = lnt.testing.TestSamples(suite + "." + key, [val],
47-
conv_f=metric_type)
4844

49-
report.tests.extend([test])
45+
if testname not in tests:
46+
tests[testname] = lnt.testing.Test(testname, [], info={}, report_version=2)
47+
test = tests[testname]
48+
49+
samples = next((s for s in test.samples if s.metric == metric), None)
50+
if samples is None:
51+
test.samples.append(lnt.testing.MetricSamples(metric, [], report_version=2))
52+
samples = test.samples[-1]
53+
54+
samples.add_samples([val], conv_f=metric_type)
5055

56+
report = lnt.testing.Report(machine=machine, run=run, tests=list(tests.values()), report_version=2)
5157
output.write(report.render())

lnt/testing/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def render(self):
128128
"""
129129
if self.report_version == 2:
130130
d = dict(self.info)
131-
d['Name'] = self.name
131+
d['name'] = self.name
132132
return d
133133
else:
134134
return {'Name': self.name,
@@ -280,7 +280,7 @@ def render(self):
280280
"""
281281
d = dict(self.info)
282282
d.update([s.render().popitem() for s in self.samples])
283-
d['Name'] = self.name
283+
d['name'] = self.name
284284
return d
285285

286286

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
foo.execution_time 10
2+
foo.execution_time 11
3+
bar.execution_time 20
4+
foo.hash d7
5+
bar.profile Xz6/

tests/lnttool/importreport.shtest

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Testing text importing.
2+
#
3+
# RUN: lnt importreport --testsuite nts --order 123 --machine foo %S/Inputs/example_metrics.lnt %t.json
4+
# RUN: filecheck --input-file %t.json %s
5+
# CHECK: {
6+
# CHECK-NEXT: "format_version": "2",
7+
# CHECK-NEXT: "machine": {
8+
# CHECK-NEXT: "name": "foo"
9+
# CHECK-NEXT: },
10+
# CHECK-NEXT: "run": {
11+
# CHECK-NEXT: "end_time": "{{.+}}",
12+
# CHECK-NEXT: "llvm_project_revision": "123",
13+
# CHECK-NEXT: "start_time": "{{.+}}"
14+
# CHECK-NEXT: },
15+
# CHECK-NEXT: "tests": [
16+
# CHECK-NEXT: {
17+
# CHECK-NEXT: "execution_time": [
18+
# CHECK-NEXT: 10.0,
19+
# CHECK-NEXT: 11.0
20+
# CHECK-NEXT: ],
21+
# CHECK-NEXT: "hash": "d7",
22+
# CHECK-NEXT: "name": "foo"
23+
# CHECK-NEXT: },
24+
# CHECK-NEXT: {
25+
# CHECK-NEXT: "execution_time": 20.0,
26+
# CHECK-NEXT: "name": "bar",
27+
# CHECK-NEXT: "profile": "Xz6/"
28+
# CHECK-NEXT: }
29+
# CHECK-NEXT: ]
30+
# CHECK-NEXT: }

tests/lnttool/test_importreport.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/testing/TestingTest.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ def test_check(self):
165165

166166
def test_render(self):
167167
# Check rendering with no info.
168-
d1 = {'Name': 'Test1',
168+
d1 = {'name': 'Test1',
169169
'execution_time': [21.4, 3.2]}
170170
self.assertDictEqual(self.test_noinfo.render(), d1)
171171

172172
# Check rendering with info.
173-
d2 = {'Name': 'Test2',
173+
d2 = {'name': 'Test2',
174174
'execution_time': [21.4, 3.2],
175175
'nb_files': '2'}
176176
self.assertDictEqual(self.test_info.render(), d2)
@@ -479,13 +479,13 @@ def test_render(self):
479479
self.assertDictEqual(self.machine_v1.render(), d2)
480480

481481
# Check v2 rendering with no info.
482-
d3 = {'Name': 'Machine3',
482+
d3 = {'name': 'Machine3',
483483
'CPUs': '2'}
484484
self.assertDictEqual(self.machine_v2.render(), d3)
485485

486486
# Check v2 rendering with info.
487487
self.machine_v2.info = {}
488-
d4 = {'Name': 'Machine3'}
488+
d4 = {'name': 'Machine3'}
489489
self.assertDictEqual(self.machine_v2.render(), d4)
490490

491491

@@ -662,7 +662,7 @@ def test_render(self):
662662
{
663663
"format_version": "2",
664664
"machine": {
665-
"Name": "Machine",
665+
"name": "Machine",
666666
"nb_cpus": "2"
667667
},
668668
"run": {
@@ -671,11 +671,11 @@ def test_render(self):
671671
},
672672
"tests": [
673673
{
674-
"Name": "Test",
675674
"execution_time": [
676675
21.4,
677676
3.2
678677
],
678+
"name": "Test",
679679
"nb_files": "2"
680680
}
681681
]
@@ -687,7 +687,7 @@ def test_render(self):
687687
{
688688
"format_version": "2",
689689
"machine": {
690-
"Name": "Machine",
690+
"name": "Machine",
691691
"nb_cpus": "2"
692692
},
693693
"run": {
@@ -696,11 +696,11 @@ def test_render(self):
696696
},
697697
"tests": [
698698
{
699-
"Name": "Test",
700699
"execution_time": [
701700
21.4,
702701
3.2
703702
],
703+
"name": "Test",
704704
"nb_files": "2"
705705
}
706706
]
@@ -714,7 +714,7 @@ def test_render(self):
714714
{
715715
"format_version": "2",
716716
"machine": {
717-
"Name": "Machine",
717+
"name": "Machine",
718718
"nb_cpus": "2"
719719
},
720720
"run": {
@@ -723,8 +723,8 @@ def test_render(self):
723723
},
724724
"tests": [
725725
{
726-
"Name": "Test",
727726
"execution_time": 21.4,
727+
"name": "Test",
728728
"nb_files": "2"
729729
}
730730
]

0 commit comments

Comments
 (0)