@@ -22,6 +22,7 @@ XFAIL = 2
22
22
23
23
###
24
24
25
+
25
26
def capture_with_result (args , include_stderr = False ):
26
27
"""capture_with_result(command) -> (output, exit code)
27
28
@@ -40,16 +41,19 @@ def capture_with_result(args, include_stderr=False):
40
41
out , _ = p .communicate ()
41
42
return out , p .wait ()
42
43
44
+
43
45
def capture (args , include_stderr = False ):
44
46
"""capture(command) - Run the given command (or argv list) in a shell and
45
47
return the standard output."""
46
48
return capture_with_result (args , include_stderr )[0 ]
47
49
50
+
48
51
def timestamp ():
49
52
return datetime .datetime .utcnow ().strftime ('%Y-%m-%d %H:%M:%S' )
50
53
51
54
###
52
55
56
+
53
57
def submit_results_to_server (results_data , submit_url ):
54
58
# Submit the URL encoded data.
55
59
data = urllib .urlencode ({'input_data' : results_data ,
@@ -73,121 +77,122 @@ def submit_results_to_server(results_data, submit_url):
73
77
74
78
###
75
79
80
+
76
81
def main ():
77
- parser = optparse .OptionParser ("""%prog [options] <results>""" )
78
- parser .add_option ("" , "--submit" , dest = "submit_url" , metavar = "URL" ,
79
- help = "Submit results to the given URL" ,
80
- action = "store" , type = str , default = None )
81
- parser .add_option ("" , "--output" , dest = "output" , metavar = "PATH" ,
82
- help = "Write raw report data to PATH" ,
83
- action = "store" , type = str , default = None )
84
- parser .add_option ("" , "--machine-name" , dest = "machine_name" , metavar = "NAME" ,
85
- help = "Set the machine name to embed in the report" ,
86
- action = "store" , type = str , default = None )
87
- parser .add_option ("" , "--run-order" , dest = "run_order" , metavar = "REVISION" ,
88
- help = "Set the run order to embed in the report" ,
89
- action = "store" , type = int , default = None )
90
- opts , args = parser .parse_args ()
91
-
92
- # At least one of --submit or --output is required.
93
- if len (args ) != 1 :
94
- parser .error ("incorrect number of arguments" )
95
- if opts .submit_url is None and opts .output is None :
96
- parser .error ("no action given (provide --submit or --output)" )
97
- if opts .machine_name is None :
98
- parser .error ("--machine-name is required" )
99
- if opts .run_order is None :
100
- parser .error ("--run-order is required" )
101
-
102
- # Load the results data.
103
- results_path , = args
104
- with open (results_path ) as f :
105
- data = json .load (f )
106
-
107
- # Compute some data not present in the 'lit' report.
108
- machine_name = opts .machine_name
109
- run_order = str (opts .run_order )
110
-
111
- # Estimate the end time as being now, and the start time as being that minus
112
- # the elapsed testing time.
113
- utcnow = datetime .datetime .utcnow ()
114
- start_time = utcnow - datetime .timedelta (seconds = data ['elapsed' ])
115
- end_time = utcnow
116
-
117
- # Create the LNT report format.
118
- lnt_results = {}
119
- lnt_results ['Machine' ] = {
120
- 'Name' : machine_name ,
121
- 'Info' : {
122
- 'hardware' : capture (["uname" , "-m" ], include_stderr = True ).strip (),
123
- 'name' : capture (["uname" , "-n" ], include_stderr = True ).strip (),
124
- 'os' : capture (["uname" , "-sr" ], include_stderr = True ).strip (),
125
- 'uname' : capture (["uname" , "-a" ], include_stderr = True ).strip (),
126
- }
127
- }
128
-
129
- # FIXME: Record source versions for LLVM, Swift, etc.?
130
- lnt_results ['Run' ] = {
131
- 'Start Time' : start_time .strftime ('%Y-%m-%d %H:%M:%S' ),
132
- 'End Time' : end_time .strftime ('%Y-%m-%d %H:%M:%S' ),
133
- 'Info' : {
134
- '__report_version__' : '1' ,
135
- 'tag' : 'nts' ,
136
- 'inferred_run_order' : run_order ,
137
- 'run_order' : run_order ,
138
- 'sw_vers' : capture (['sw_vers' ], include_stderr = True ).strip (),
139
- }
140
- }
141
-
142
- lnt_results ['Tests' ] = lnt_tests = []
143
- for test in data ['tests' ]:
144
- # Ignore tests which have unexpected status.
145
- code = test ['code' ]
146
- if code not in ('PASS' , 'XPASS' , 'FAIL' , 'XFAIL' ):
147
- sys .stderr .write ("ignoring test %r with result code %r" % (
148
- test ['name' ], code ))
149
- continue
150
-
151
- # Extract the test name, which is encoded as 'suite :: name'.
152
- test_name = 'nts.%s' % (test ['name' ].split ('::' , 1 )[1 ][1 :],)
153
-
154
- # Convert this test to the 'nts' schema.
155
- compile_success = test ['metrics' ].get ('compile_success' , 1 )
156
- compile_time = test ['metrics' ]['compile_time' ]
157
- exec_success = test ['metrics' ].get ('exec_success' , 1 )
158
- exec_time = test ['metrics' ]['exec_time' ]
159
-
160
- # FIXME: Ensure the test success flags matches the result code.
161
- # FIXME: The XFAIL handling here isn't going to be right.
162
-
163
- if not compile_success :
164
- lnt_tests .append ({'Name' : '%s.compile.status' % (test_name ,),
165
- 'Info' : {},
166
- 'Data' : [FAIL ]})
167
- if not exec_success :
168
- lnt_tests .append ({'Name' : '%s.exec.status' % (test_name ,),
169
- 'Info' : {},
170
- 'Data' : [FAIL ]})
171
- lnt_tests .append ({'Name' : '%s.compile' % (test_name ,),
172
- 'Info' : {},
173
- 'Data' : [compile_time ]})
174
- lnt_tests .append ({'Name' : '%s.exec' % (test_name ,),
175
- 'Info' : {},
176
- 'Data' : [exec_time ]})
177
-
178
- # Create the report data.
179
- lnt_result_data = json .dumps (lnt_results , indent = 2 ) + '\n '
180
-
181
- # Write the results, if requested.
182
- if opts .output :
183
- sys .stderr .write ('%s: generating report: %r\n ' % (
184
- timestamp (), opts .output ))
185
- with open (opts .output , 'w' ) as f :
186
- f .write (lnt_result_data )
187
-
188
- # Submit the results to an LNT server, if requested.
189
- if opts .submit_url :
190
- submit_results_to_server (lnt_result_data , opts .submit_url )
82
+ parser = optparse .OptionParser ("""%prog [options] <results>""" )
83
+ parser .add_option ("" , "--submit" , dest = "submit_url" , metavar = "URL" ,
84
+ help = "Submit results to the given URL" ,
85
+ action = "store" , type = str , default = None )
86
+ parser .add_option ("" , "--output" , dest = "output" , metavar = "PATH" ,
87
+ help = "Write raw report data to PATH" ,
88
+ action = "store" , type = str , default = None )
89
+ parser .add_option ("" , "--machine-name" , dest = "machine_name" , metavar = "NAME" ,
90
+ help = "Set the machine name to embed in the report" ,
91
+ action = "store" , type = str , default = None )
92
+ parser .add_option ("" , "--run-order" , dest = "run_order" , metavar = "REVISION" ,
93
+ help = "Set the run order to embed in the report" ,
94
+ action = "store" , type = int , default = None )
95
+ opts , args = parser .parse_args ()
96
+
97
+ # At least one of --submit or --output is required.
98
+ if len (args ) != 1 :
99
+ parser .error ("incorrect number of arguments" )
100
+ if opts .submit_url is None and opts .output is None :
101
+ parser .error ("no action given (provide --submit or --output)" )
102
+ if opts .machine_name is None :
103
+ parser .error ("--machine-name is required" )
104
+ if opts .run_order is None :
105
+ parser .error ("--run-order is required" )
106
+
107
+ # Load the results data.
108
+ results_path , = args
109
+ with open (results_path ) as f :
110
+ data = json .load (f )
111
+
112
+ # Compute some data not present in the 'lit' report.
113
+ machine_name = opts .machine_name
114
+ run_order = str (opts .run_order )
115
+
116
+ # Estimate the end time as being now, and the start time as being that minus
117
+ # the elapsed testing time.
118
+ utcnow = datetime .datetime .utcnow ()
119
+ start_time = utcnow - datetime .timedelta (seconds = data ['elapsed' ])
120
+ end_time = utcnow
121
+
122
+ # Create the LNT report format.
123
+ lnt_results = {}
124
+ lnt_results ['Machine' ] = {
125
+ 'Name' : machine_name ,
126
+ 'Info' : {
127
+ 'hardware' : capture (["uname" , "-m" ], include_stderr = True ).strip (),
128
+ 'name' : capture (["uname" , "-n" ], include_stderr = True ).strip (),
129
+ 'os' : capture (["uname" , "-sr" ], include_stderr = True ).strip (),
130
+ 'uname' : capture (["uname" , "-a" ], include_stderr = True ).strip (),
131
+ }
132
+ }
133
+
134
+ # FIXME: Record source versions for LLVM, Swift, etc.?
135
+ lnt_results ['Run' ] = {
136
+ 'Start Time' : start_time .strftime ('%Y-%m-%d %H:%M:%S' ),
137
+ 'End Time' : end_time .strftime ('%Y-%m-%d %H:%M:%S' ),
138
+ 'Info' : {
139
+ '__report_version__' : '1' ,
140
+ 'tag' : 'nts' ,
141
+ 'inferred_run_order' : run_order ,
142
+ 'run_order' : run_order ,
143
+ 'sw_vers' : capture (['sw_vers' ], include_stderr = True ).strip (),
144
+ }
145
+ }
146
+
147
+ lnt_results ['Tests' ] = lnt_tests = []
148
+ for test in data ['tests' ]:
149
+ # Ignore tests which have unexpected status.
150
+ code = test ['code' ]
151
+ if code not in ('PASS' , 'XPASS' , 'FAIL' , 'XFAIL' ):
152
+ sys .stderr .write ("ignoring test %r with result code %r" % (
153
+ test ['name' ], code ))
154
+ continue
155
+
156
+ # Extract the test name, which is encoded as 'suite :: name'.
157
+ test_name = 'nts.%s' % (test ['name' ].split ('::' , 1 )[1 ][1 :],)
158
+
159
+ # Convert this test to the 'nts' schema.
160
+ compile_success = test ['metrics' ].get ('compile_success' , 1 )
161
+ compile_time = test ['metrics' ]['compile_time' ]
162
+ exec_success = test ['metrics' ].get ('exec_success' , 1 )
163
+ exec_time = test ['metrics' ]['exec_time' ]
164
+
165
+ # FIXME: Ensure the test success flags matches the result code.
166
+ # FIXME: The XFAIL handling here isn't going to be right.
167
+
168
+ if not compile_success :
169
+ lnt_tests .append ({'Name' : '%s.compile.status' % (test_name ,),
170
+ 'Info' : {},
171
+ 'Data' : [FAIL ]})
172
+ if not exec_success :
173
+ lnt_tests .append ({'Name' : '%s.exec.status' % (test_name ,),
174
+ 'Info' : {},
175
+ 'Data' : [FAIL ]})
176
+ lnt_tests .append ({'Name' : '%s.compile' % (test_name ,),
177
+ 'Info' : {},
178
+ 'Data' : [compile_time ]})
179
+ lnt_tests .append ({'Name' : '%s.exec' % (test_name ,),
180
+ 'Info' : {},
181
+ 'Data' : [exec_time ]})
182
+
183
+ # Create the report data.
184
+ lnt_result_data = json .dumps (lnt_results , indent = 2 ) + '\n '
185
+
186
+ # Write the results, if requested.
187
+ if opts .output :
188
+ sys .stderr .write ('%s: generating report: %r\n ' % (
189
+ timestamp (), opts .output ))
190
+ with open (opts .output , 'w' ) as f :
191
+ f .write (lnt_result_data )
192
+
193
+ # Submit the results to an LNT server, if requested.
194
+ if opts .submit_url :
195
+ submit_results_to_server (lnt_result_data , opts .submit_url )
191
196
192
197
if __name__ == '__main__' :
193
- main ()
198
+ main ()
0 commit comments