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

Side by Side Diff: scripts/slave/recipe_modules/chromium_android/api.py

Issue 1465343002: [Android] Add context manager to record logcat during step(s). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 5 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 | Annotate | Revision Log
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import contextlib 5 import contextlib
6 import datetime 6 import datetime
7 import json 7 import json
8 import os 8 import os
9 import re 9 import re
10 import urllib 10 import urllib
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 # (or at least make the difference clear). 242 # (or at least make the difference clear).
243 self.m.archive.zip_and_upload_build( 243 self.m.archive.zip_and_upload_build(
244 'zip_build', 244 'zip_build',
245 target=self.m.chromium.c.BUILD_CONFIG, 245 target=self.m.chromium.c.BUILD_CONFIG,
246 # We send None as the path so that zip_build.py gets it from factory 246 # We send None as the path so that zip_build.py gets it from factory
247 # properties. 247 # properties.
248 build_url=None, 248 build_url=None,
249 src_dir=self.m.path['slave_build'].join('src'), 249 src_dir=self.m.path['slave_build'].join('src'),
250 exclude_files='lib.target,gen,android_webview,jingle_unittests') 250 exclude_files='lib.target,gen,android_webview,jingle_unittests')
251 251
252 def spawn_logcat_monitor(self):
253 self.m.step(
254 'spawn_logcat_monitor',
255 [self.m.path['build'].join('scripts', 'slave', 'daemonizer.py'),
256 '--', self.c.cr_build_android.join('adb_logcat_monitor.py'),
257 self.m.chromium.c.build_dir.join('logcat')],
258 env=self.m.chromium.get_env(),
259 infra_step=True)
260
261 def spawn_device_monitor(self): 252 def spawn_device_monitor(self):
262 script = self.m.path['build'].join('scripts', 'slave', 'daemonizer.py') 253 script = self.m.path['build'].join('scripts', 'slave', 'daemonizer.py')
263 args = [ 254 args = [
264 '--action', 'restart', 255 '--action', 'restart',
265 '--pid-file-path', '/tmp/device_monitor.pid', 256 '--pid-file-path', '/tmp/device_monitor.pid',
266 '--', self.resource('spawn_device_monitor.py'), 257 '--', self.resource('spawn_device_monitor.py'),
267 self.m.adb.adb_path(), 258 self.m.adb.adb_path(),
268 json.dumps(self._devices), 259 json.dumps(self._devices),
269 self.m.properties['mastername'], 260 self.m.properties['mastername'],
270 self.m.properties['buildername'], 261 self.m.properties['buildername'],
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 args.extend(['--official-build']) 659 args.extend(['--official-build'])
669 if json_results_file: 660 if json_results_file:
670 args.extend(['--json-results-file', json_results_file]) 661 args.extend(['--json-results-file', json_results_file])
671 662
672 return self.test_runner( 663 return self.test_runner(
673 'Instrumentation test %s%s' % (annotation or name, 664 'Instrumentation test %s%s' % (annotation or name,
674 ' (%s)' % suffix if suffix else ''), 665 ' (%s)' % suffix if suffix else ''),
675 args=['instrumentation'] + args, 666 args=['instrumentation'] + args,
676 **kwargs) 667 **kwargs)
677 668
678 def logcat_dump(self, gs_bucket=None): 669 def spawn_logcat_monitor(self, logcat_dir=None):
670 if not logcat_dir:
671 logcat_dir = self.m.chromium.c.build_dir.join('logcat')
luqui 2015/11/23 22:59:40 Sure you don't want this to be a config item?
mikecase (-- gone --) 2015/11/24 20:50:59 Added default_logcat_dir to config.
672
673 self.m.step(
674 'spawn_logcat_monitor',
675 [self.m.path['build'].join('scripts', 'slave', 'daemonizer.py'),
676 '--', self.c.cr_build_android.join('adb_logcat_monitor.py'),
677 logcat_dir],
678 env=self.m.chromium.get_env(),
679 infra_step=True)
680
681 def logcat_dump(self, output_logcat_file, logcat_dir=None, gs_bucket=None):
682 if not logcat_dir:
683 logcat_dir = self.m.chromium.c.build_dir.join('logcat')
684
679 if gs_bucket: 685 if gs_bucket:
680 log_path = self.m.chromium.output_dir.join('full_log')
681 self.m.python( 686 self.m.python(
682 'logcat_dump', 687 'logcat_dump',
683 self.m.path['checkout'].join('build', 'android', 688 self.m.path['checkout'].join('build', 'android',
684 'adb_logcat_printer.py'), 689 'adb_logcat_printer.py'),
685 [ '--output-path', log_path, 690 ['--output-path', output_logcat_file, logcat_dir],
686 self.m.path['checkout'].join('out', 'logcat') ],
687 infra_step=True) 691 infra_step=True)
688 self.m.gsutil.upload( 692 self.m.gsutil.upload(
689 log_path, 693 output_logcat_file,
690 gs_bucket, 694 gs_bucket,
691 'logcat_dumps/%s/%s' % (self.m.properties['buildername'], 695 'logcat_dumps/%s/%s' % (self.m.properties['buildername'],
692 self.m.properties['buildnumber']), 696 self.m.properties['buildnumber']),
693 link_name='logcat dump', 697 link_name='logcat dump',
694 version='4.7') 698 version='4.7')
695 else: 699 else:
696 self.m.python( 700 self.m.python(
697 'logcat_dump', 701 'logcat_dump',
698 self.m.path['build'].join('scripts', 'slave', 'tee.py'), 702 self.m.path['build'].join('scripts', 'slave', 'tee.py'),
699 [self.m.chromium.output_dir.join('full_log'), 703 [output_logcat_file,
700 '--', 704 '--',
701 self.m.path['checkout'].join('build', 'android', 705 self.m.path['checkout'].join('build', 'android',
702 'adb_logcat_printer.py'), 706 'adb_logcat_printer.py'),
703 self.m.path['checkout'].join('out', 'logcat')], 707 logcat_dir],
704 infra_step=True, 708 infra_step=True)
705 )
706 709
707 def stack_tool_steps(self): 710 @contextlib.contextmanager
708 log_file = self.m.path['checkout'].join('out', 711 def logcat(self, step_name):
709 self.m.chromium.c.BUILD_CONFIG, 712 """Context manager for recording logcat.
710 'full_log') 713
714 Args:
715 step_name: Name of the outer step. Any steps ran inside this context
716 manager will be nested inside.
717 """
718 with self.m.step.nest(step_name):
719 logcat_dir = self.m.path.mkdtemp('test_logcat')
720 self.spawn_logcat_monitor(logcat_dir)
721 yield
722 self.logcat_dump(logcat_dir=logcat_dir,
luqui 2015/11/23 22:59:40 Will this kill the logcat monitor.. or will the n
mikecase (-- gone --) 2015/11/24 20:50:59 So, I looked through the scripts, spawn_logcat_mon
723 output_logcat_file=self.m.raw_io.output('logcat'),
724 gs_bucket=None)
725
726 def stack_tool_steps(self, logcat_file):
711 target_arch = self.m.chromium.c.gyp_env.GYP_DEFINES['target_arch'] 727 target_arch = self.m.chromium.c.gyp_env.GYP_DEFINES['target_arch']
712 # gyp converts ia32 to x86, bot needs to do the same 728 # gyp converts ia32 to x86, bot needs to do the same
713 target_arch = {'ia32': 'x86'}.get(target_arch) or target_arch 729 target_arch = {'ia32': 'x86'}.get(target_arch) or target_arch
714 self.m.step( 730 self.m.step(
715 'stack_tool_with_logcat_dump', 731 'stack_tool_with_logcat_dump',
716 [self.m.path['checkout'].join('third_party', 'android_platform', 732 [self.m.path['checkout'].join('third_party', 'android_platform',
717 'development', 'scripts', 'stack'), 733 'development', 'scripts', 'stack'),
718 '--arch', target_arch, '--more-info', log_file], 734 '--arch', target_arch, '--more-info', logcat_file],
719 env=self.m.chromium.get_env(), 735 env=self.m.chromium.get_env(),
720 infra_step=True) 736 infra_step=True)
721 self.m.step( 737 self.m.step(
722 'stack_tool_for_tombstones', 738 'stack_tool_for_tombstones',
723 [self.m.path['checkout'].join('build', 'android', 'tombstones.py'), 739 [self.m.path['checkout'].join('build', 'android', 'tombstones.py'),
724 '-a', '-s', '-w'], env=self.get_env(), 740 '-a', '-s', '-w'], env=self.get_env(),
725 infra_step=True) 741 infra_step=True)
726 if self.c.asan_symbolize: 742 if self.c.asan_symbolize:
727 self.m.step( 743 self.m.step(
728 'stack_tool_for_asan', 744 'stack_tool_for_asan',
729 [self.m.path['checkout'].join('build', 745 [self.m.path['checkout'].join('build',
730 'android', 746 'android',
731 'asan_symbolize.py'), 747 'asan_symbolize.py'),
732 '-l', log_file], env=self.m.chromium.get_env(), 748 '-l', logcat_file], env=self.m.chromium.get_env(),
733 infra_step=True) 749 infra_step=True)
734 750
735 def test_report(self): 751 def test_report(self):
736 self.m.python.inline( 752 self.m.python.inline(
737 'test_report', 753 'test_report',
738 """ 754 """
739 import glob, os, sys 755 import glob, os, sys
740 for report in glob.glob(sys.argv[1]): 756 for report in glob.glob(sys.argv[1]):
741 with open(report, 'r') as f: 757 with open(report, 'r') as f:
742 for l in f.readlines(): 758 for l in f.readlines():
(...skipping 19 matching lines...) Expand all
762 else: 778 else:
763 kwargs = {} 779 kwargs = {}
764 self.provision_devices(**kwargs) 780 self.provision_devices(**kwargs)
765 if self.m.chromium.c.gyp_env.GYP_DEFINES.get('asan', 0) == 1: 781 if self.m.chromium.c.gyp_env.GYP_DEFINES.get('asan', 0) == 1:
766 self.asan_device_setup() 782 self.asan_device_setup()
767 783
768 self.spawn_device_monitor() 784 self.spawn_device_monitor()
769 785
770 def common_tests_final_steps(self, logcat_gs_bucket=None): 786 def common_tests_final_steps(self, logcat_gs_bucket=None):
771 self.shutdown_device_monitor() 787 self.shutdown_device_monitor()
772 self.logcat_dump(gs_bucket=logcat_gs_bucket) 788 logcat_file = self.m.chromium.output_dir.join('full_log')
773 self.stack_tool_steps() 789 self.logcat_dump(output_logcat_file=logcat_file,
790 gs_bucket=logcat_gs_bucket)
791 self.stack_tool_steps(logcat_file=logcat_file)
774 self.test_report() 792 self.test_report()
775 793
776 def run_bisect_script(self, extra_src='', path_to_config='', **kwargs): 794 def run_bisect_script(self, extra_src='', path_to_config='', **kwargs):
777 self.m.step('prepare bisect perf regression', 795 self.m.step('prepare bisect perf regression',
778 [self.m.path['checkout'].join('tools', 796 [self.m.path['checkout'].join('tools',
779 'prepare-bisect-perf-regression.py'), 797 'prepare-bisect-perf-regression.py'),
780 '-w', self.m.path['slave_build']]) 798 '-w', self.m.path['slave_build']])
781 799
782 args = [] 800 args = []
783 if extra_src: 801 if extra_src:
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 def test_runner(self, step_name, args=None, **kwargs): 1058 def test_runner(self, step_name, args=None, **kwargs):
1041 """Wrapper for the python testrunner script. 1059 """Wrapper for the python testrunner script.
1042 1060
1043 Args: 1061 Args:
1044 step_name: Name of the step. 1062 step_name: Name of the step.
1045 args: Testrunner arguments. 1063 args: Testrunner arguments.
1046 """ 1064 """
1047 with self.handle_exit_codes(): 1065 with self.handle_exit_codes():
1048 return self.m.python( 1066 return self.m.python(
1049 step_name, self.c.test_runner, args, **kwargs) 1067 step_name, self.c.test_runner, args, **kwargs)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698