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

Side by Side Diff: systrace/systrace/output_generator_unittest.py

Issue 2712163002: [Systrace] Fix systrace clock syncing issue with BattOr. (Closed)
Patch Set: no more telemetry references Created 3 years, 9 months 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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright 2016 The Chromium Authors. All rights reserved. 3 # Copyright 2016 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 import hashlib
7 import json 8 import json
8 import os 9 import os
9 import unittest 10 import unittest
10 11
11 from systrace import decorators 12 from systrace import decorators
12 from systrace import output_generator 13 from systrace import output_generator
13 from systrace import trace_result 14 from systrace import trace_result
14 from systrace import update_systrace_trace_viewer 15 from systrace import update_systrace_trace_viewer
15 from systrace import util 16 from systrace import util
17 from tracing.trace_data import trace_data as trace_data_module
16 18
17 19
18 TEST_DIR = os.path.join(os.path.dirname(__file__), 'test_data') 20 TEST_DIR = os.path.join(os.path.dirname(__file__), 'test_data')
19 ATRACE_DATA = os.path.join(TEST_DIR, 'atrace_data') 21 ATRACE_DATA = os.path.join(TEST_DIR, 'atrace_data')
22 BATTOR_DATA = os.path.join(TEST_DIR, 'battor_test_data.txt')
20 COMBINED_PROFILE_CHROME_DATA = os.path.join( 23 COMBINED_PROFILE_CHROME_DATA = os.path.join(
21 TEST_DIR, 'profile-chrome_systrace_perf_chrome_data') 24 TEST_DIR, 'profile-chrome_systrace_perf_chrome_data')
22 25
23 26
24 class OutputGeneratorTest(unittest.TestCase): 27 class OutputGeneratorTest(unittest.TestCase):
25 28
26 @decorators.HostOnlyTest 29 @decorators.HostOnlyTest
27 def testJsonTraceMerging(self): 30 def testJsonTraceMerging(self):
28 update_systrace_trace_viewer.update(force_update=True) 31 update_systrace_trace_viewer.update(force_update=True)
29 self.assertTrue(os.path.exists( 32 self.assertTrue(os.path.exists(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 os.remove(final_path) 66 os.remove(final_path)
64 67
65 # Ensure the trace data written in HTML is located within the 68 # Ensure the trace data written in HTML is located within the
66 # correct place in the HTML document and that the data is not 69 # correct place in the HTML document and that the data is not
67 # malformed. 70 # malformed.
68 self.assertEquals(trace_data, atrace_data) 71 self.assertEquals(trace_data, atrace_data)
69 os.remove(update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE) 72 os.remove(update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE)
70 73
71 @decorators.HostOnlyTest 74 @decorators.HostOnlyTest
72 def testHtmlOutputGenerationFormatsMultipleTraces(self): 75 def testHtmlOutputGenerationFormatsMultipleTraces(self):
73 update_systrace_trace_viewer.update(force_update=True)
74 self.assertTrue(os.path.exists(
75 update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE))
76 json_data = open(COMBINED_PROFILE_CHROME_DATA).read()
Chris Craik 2017/03/21 19:52:23 can we delete the file COMBINED_PROFILE_CHROME_DAT
rnephew (Reviews Here) 2017/03/23 15:14:15 The new unittest still uses it.
77 combined_data = json.loads(json_data)
78 trace_results = [] 76 trace_results = []
79 trace_results_expected = [] 77 trace_data_builder = trace_data_module.TraceDataBuilder()
80 for (trace_name, data) in combined_data.iteritems():
81 trace_results.append(trace_result.TraceResult(str(trace_name),
82 str(data)))
83 trace_results_expected.append(str(data).replace(" ", "").strip())
84 output_file_name = util.generate_random_filename_for_test()
85 final_path = output_generator.GenerateHTMLOutput(trace_results,
86 output_file_name)
87 with open(output_file_name, 'r') as f:
88 html_output = f.read()
89 for i in range(1, len(trace_results)):
90 trace_data = (html_output.split(
91 '<script class="trace-data" type="application/text">')[i].split(
92 '</script>'))[0].replace(" ", "").strip()
93 78
94 # Ensure the trace data written in HTML is located within the 79 with open(BATTOR_DATA) as fp:
95 # correct place in the HTML document and that the data is not 80 battor_data = fp.read()
96 # malformed. 81 trace_results.append(
97 self.assertTrue(trace_data in trace_results_expected) 82 trace_result.TraceResult('powerTraceAsString', battor_data))
98 os.remove(final_path) 83 trace_data_builder.AddTraceFor(
99 os.remove(update_systrace_trace_viewer.SYSTRACE_TRACE_VIEWER_HTML_FILE) 84 trace_data_module.BATTOR_TRACE_PART, battor_data)
85
86 with open(ATRACE_DATA) as fp:
87 atrace_data = fp.read()
88 trace_results.append(
89 trace_result.TraceResult('systemTraceEvents', atrace_data))
90 trace_data_builder.AddTraceFor(trace_data_module.ATRACE_PART, atrace_data)
91
92
93 with open(COMBINED_PROFILE_CHROME_DATA) as fp:
94 chrome_data = fp.read()
95 trace_results.append(
96 trace_result.TraceResult('traceEvents', json.loads(chrome_data)))
97 trace_data_builder.AddTraceFor(
98 trace_data_module.CHROME_TRACE_PART, json.loads(chrome_data))
99
100 # Generate controller trace.
charliea (OOO until 10-5) 2017/03/21 19:47:23 nit: I think "Generate controller trace" is implie
rnephew (Reviews Here) 2017/03/23 15:14:15 Done.
101 trace_results.append(
102 trace_result.TraceResult('systraceController', str({})))
103 trace_data_builder.AddTraceFor(trace_data_module.TELEMETRY_PART, {})
104
105 try:
106 data_builder_out = util.generate_random_filename_for_test()
107 output_generator_out = util.generate_random_filename_for_test()
108 output_generator.GenerateHTMLOutput(trace_results, output_generator_out)
109 trace_data_builder.AsData().Serialize(data_builder_out, 'Systrace')
110
111 output_generator_md5sum = hashlib.md5(
112 open(output_generator_out, 'rb').read()).hexdigest()
113 data_builder_md5sum = hashlib.md5(
114 open(data_builder_out, 'rb').read()).hexdigest()
115
116 self.assertEqual(output_generator_md5sum, data_builder_md5sum)
117 finally:
118 def del_if_exist(path):
119 try:
120 os.remove(path)
121 except IOError:
122 pass
123 del_if_exist(output_generator_out)
124 del_if_exist(data_builder_out)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698