Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: build/android/pylib/results/json_results.py

Issue 757683002: [Android] Implement generic JSON results that match base/test/launcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit issue Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import json
6 import logging
7
8 from pylib.base import base_test_result
9
10
11 def GenerateResultsDict(test_run_result):
12 """Create a results dict from |test_run_result| suitable for writing to JSON.
13 Args:
14 test_run_result: a base_test_result.TestRunResults object.
15 Returns:
16 A results dict that mirrors the one generated by
17 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON.
18 """
19 assert isinstance(test_run_result, base_test_result.TestRunResults)
20
21 def status_as_string(s):
22 if s == base_test_result.ResultType.PASS:
23 return 'SUCCESS'
24 elif s == base_test_result.ResultType.SKIP:
25 return 'SKIPPED'
26 elif s == base_test_result.ResultType.FAIL:
27 return 'FAILURE'
28 elif s == base_test_result.ResultType.CRASH:
29 return 'CRASH'
30 elif s == base_test_result.ResultType.TIMEOUT:
31 return 'TIMEOUT'
32 elif s == base_test_result.ResultType.UNKNOWN:
33 return 'UNKNOWN'
34
35 def generate_iteration_data(t):
36 return {
37 t.GetName(): [
38 {
39 'status': status_as_string(t.GetType()),
40 'elapsed_time_ms': t.GetDuration(),
41 'output_snippet': '',
42 'losless_snippet': '',
43 'output_snippet_base64:': '',
44 }
45 ]
46 }
47
48 all_tests_tuple, per_iteration_data_tuple = zip(
49 *[(t.GetName(), generate_iteration_data(t))
50 for t in test_run_result.GetAll()])
51
52 return {
53 'global_tags': [],
54 'all_tests': list(all_tests_tuple),
55 # TODO(jbudorick): Add support for disabled tests within base_test_result.
56 'disabled_tests': [],
57 'per_iteration_data': list(per_iteration_data_tuple),
58 }
59
60
61 def GenerateJsonResultsFile(test_run_result, file_path):
62 """Write |test_run_result| to JSON.
63
64 This emulates the format of the JSON emitted by
65 base/test/launcher/test_results_tracker.cc:SaveSummaryAsJSON.
66
67 Args:
68 test_run_result: a base_test_result.TestRunResults object.
69 file_path: The path to the JSON file to write.
70 """
71 with open(file_path, 'w') as json_result_file:
72 json_result_file.write(json.dumps(GenerateResultsDict(test_run_result)))
73
OLDNEW
« no previous file with comments | « build/android/pylib/results/flakiness_dashboard/results_uploader.py ('k') | build/android/pylib/results/json_results_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698