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

Side by Side Diff: build/android/pylib/instrumentation/instrumentation_test_instance.py

Issue 1315743004: [Android] Add a custom pylintrc for build/android/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix appurify_sanitized import-errors Created 5 years, 3 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 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 logging 5 import logging
6 import os 6 import os
7 import pickle 7 import pickle
8 import re 8 import re
9 import sys 9 import sys
10 10
11 from devil.android import apk_helper 11 from devil.android import apk_helper
12 from devil.android import md5sum 12 from devil.android import md5sum
13 from devil.utils import cmd_helper
14 from pylib import constants 13 from pylib import constants
15 from pylib import flag_changer
16 from pylib.base import base_test_result 14 from pylib.base import base_test_result
17 from pylib.base import test_instance 15 from pylib.base import test_instance
18 from pylib.instrumentation import test_result 16 from pylib.instrumentation import test_result
19 from pylib.instrumentation import instrumentation_parser 17 from pylib.instrumentation import instrumentation_parser
20 from pylib.utils import proguard 18 from pylib.utils import proguard
21 19
22 sys.path.append( 20 sys.path.append(
23 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', 'common')) 21 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib', 'common'))
24 import unittest_util 22 import unittest_util # pylint: disable=import-error
25 23
26 # Ref: http://developer.android.com/reference/android/app/Activity.html 24 # Ref: http://developer.android.com/reference/android/app/Activity.html
27 _ACTIVITY_RESULT_CANCELED = 0 25 _ACTIVITY_RESULT_CANCELED = 0
28 _ACTIVITY_RESULT_OK = -1 26 _ACTIVITY_RESULT_OK = -1
29 27
30 _DEFAULT_ANNOTATIONS = [ 28 _DEFAULT_ANNOTATIONS = [
31 'Smoke', 'SmallTest', 'MediumTest', 'LargeTest', 29 'Smoke', 'SmallTest', 'MediumTest', 'LargeTest',
32 'EnormousTest', 'IntegrationTest'] 30 'EnormousTest', 'IntegrationTest']
33 _EXTRA_ENABLE_HTTP_SERVER = ( 31 _EXTRA_ENABLE_HTTP_SERVER = (
34 'org.chromium.chrome.test.ChromeInstrumentationTestRunner.' 32 'org.chromium.chrome.test.ChromeInstrumentationTestRunner.'
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 [None, 'chrome', 'test', 'data', device_rel_path])]) 350 [None, 'chrome', 'test', 'data', device_rel_path])])
353 351
354 def GetDataDependencies(self): 352 def GetDataDependencies(self):
355 return self._data_deps 353 return self._data_deps
356 354
357 def GetTests(self): 355 def GetTests(self):
358 pickle_path = '%s-proguard.pickle' % self.test_jar 356 pickle_path = '%s-proguard.pickle' % self.test_jar
359 try: 357 try:
360 tests = self._GetTestsFromPickle(pickle_path, self.test_jar) 358 tests = self._GetTestsFromPickle(pickle_path, self.test_jar)
361 except self.ProguardPickleException as e: 359 except self.ProguardPickleException as e:
362 logging.info('Getting tests from JAR via proguard. (%s)' % str(e)) 360 logging.info('Getting tests from JAR via proguard. (%s)', str(e))
363 tests = self._GetTestsFromProguard(self.test_jar) 361 tests = self._GetTestsFromProguard(self.test_jar)
364 self._SaveTestsToPickle(pickle_path, self.test_jar, tests) 362 self._SaveTestsToPickle(pickle_path, self.test_jar, tests)
365 return self._InflateTests(self._FilterTests(tests)) 363 return self._InflateTests(self._FilterTests(tests))
366 364
367 class ProguardPickleException(Exception): 365 class ProguardPickleException(Exception):
368 pass 366 pass
369 367
370 def _GetTestsFromPickle(self, pickle_path, jar_path): 368 def _GetTestsFromPickle(self, pickle_path, jar_path):
371 if not os.path.exists(pickle_path): 369 if not os.path.exists(pickle_path):
372 raise self.ProguardPickleException('%s does not exist.' % pickle_path) 370 raise self.ProguardPickleException('%s does not exist.' % pickle_path)
373 if os.path.getmtime(pickle_path) <= os.path.getmtime(jar_path): 371 if os.path.getmtime(pickle_path) <= os.path.getmtime(jar_path):
374 raise self.ProguardPickleException( 372 raise self.ProguardPickleException(
375 '%s newer than %s.' % (jar_path, pickle_path)) 373 '%s newer than %s.' % (jar_path, pickle_path))
376 374
377 with open(pickle_path, 'r') as pickle_file: 375 with open(pickle_path, 'r') as pickle_file:
378 pickle_data = pickle.loads(pickle_file.read()) 376 pickle_data = pickle.loads(pickle_file.read())
379 jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path] 377 jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path]
380 378
381 try: 379 try:
382 if pickle_data['VERSION'] != _PICKLE_FORMAT_VERSION: 380 if pickle_data['VERSION'] != _PICKLE_FORMAT_VERSION:
383 raise self.ProguardPickleException('PICKLE_FORMAT_VERSION has changed.') 381 raise self.ProguardPickleException('PICKLE_FORMAT_VERSION has changed.')
384 if pickle_data['JAR_MD5SUM'] != jar_md5: 382 if pickle_data['JAR_MD5SUM'] != jar_md5:
385 raise self.ProguardPickleException('JAR file MD5 sum differs.') 383 raise self.ProguardPickleException('JAR file MD5 sum differs.')
386 return pickle_data['TEST_METHODS'] 384 return pickle_data['TEST_METHODS']
387 except TypeError as e: 385 except TypeError as e:
388 logging.error(pickle_data) 386 logging.error(pickle_data)
389 raise self.ProguardPickleException(str(e)) 387 raise self.ProguardPickleException(str(e))
390 388
389 # pylint: disable=no-self-use
391 def _GetTestsFromProguard(self, jar_path): 390 def _GetTestsFromProguard(self, jar_path):
392 p = proguard.Dump(jar_path) 391 p = proguard.Dump(jar_path)
393 392
394 def is_test_class(c): 393 def is_test_class(c):
395 return c['class'].endswith('Test') 394 return c['class'].endswith('Test')
396 395
397 def is_test_method(m): 396 def is_test_method(m):
398 return m['method'].startswith('test') 397 return m['method'].startswith('test')
399 398
400 class_lookup = dict((c['class'], c) for c in p['classes']) 399 class_lookup = dict((c['class'], c) for c in p['classes'])
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 def GenerateTestResults( 515 def GenerateTestResults(
517 result_code, result_bundle, statuses, start_ms, duration_ms): 516 result_code, result_bundle, statuses, start_ms, duration_ms):
518 return GenerateTestResults(result_code, result_bundle, statuses, 517 return GenerateTestResults(result_code, result_bundle, statuses,
519 start_ms, duration_ms) 518 start_ms, duration_ms)
520 519
521 #override 520 #override
522 def TearDown(self): 521 def TearDown(self):
523 if self._isolate_delegate: 522 if self._isolate_delegate:
524 self._isolate_delegate.Clear() 523 self._isolate_delegate.Clear()
525 524
OLDNEW
« no previous file with comments | « build/android/pylib/instrumentation/instrumentation_parser.py ('k') | build/android/pylib/instrumentation/json_perf_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698