1*1fa4b3daSHector Dearman#!/usr/bin/env python2.7 2*1fa4b3daSHector Dearman 3*1fa4b3daSHector Dearman# Copyright 2015 The Chromium Authors. All rights reserved. 4*1fa4b3daSHector Dearman# Use of this source code is governed by a BSD-style license that can be 5*1fa4b3daSHector Dearman# found in the LICENSE file. 6*1fa4b3daSHector Dearman 7*1fa4b3daSHector Dearman"""Runs the unit test suite for systrace.""" 8*1fa4b3daSHector Dearman 9*1fa4b3daSHector Dearmanimport optparse 10*1fa4b3daSHector Dearmanimport os 11*1fa4b3daSHector Dearmanimport sys 12*1fa4b3daSHector Dearmanimport unittest 13*1fa4b3daSHector Dearman 14*1fa4b3daSHector Dearman_SYSTRACE_DIR = os.path.abspath( 15*1fa4b3daSHector Dearman os.path.join(os.path.dirname(__file__), os.path.pardir)) 16*1fa4b3daSHector Dearmansys.path.insert(0, _SYSTRACE_DIR) 17*1fa4b3daSHector Dearmanfrom systrace import decorators 18*1fa4b3daSHector Dearman 19*1fa4b3daSHector Dearman 20*1fa4b3daSHector Dearmandef main(): 21*1fa4b3daSHector Dearman parser = optparse.OptionParser() 22*1fa4b3daSHector Dearman parser.add_option("-d", "--device", dest="device", 23*1fa4b3daSHector Dearman help="device the test runs on", metavar="DEVICE") 24*1fa4b3daSHector Dearman options, _args = parser.parse_args() # pylint: disable=unused-variable 25*1fa4b3daSHector Dearman unfiltered_suite = unittest.TestLoader().discover( 26*1fa4b3daSHector Dearman _SYSTRACE_DIR, 27*1fa4b3daSHector Dearman pattern = '*_unittest.py', 28*1fa4b3daSHector Dearman top_level_dir=_SYSTRACE_DIR) 29*1fa4b3daSHector Dearman suite = unittest.TestSuite() 30*1fa4b3daSHector Dearman 31*1fa4b3daSHector Dearman for test_group in unfiltered_suite._tests: 32*1fa4b3daSHector Dearman for inner_group in test_group: 33*1fa4b3daSHector Dearman for test in inner_group: 34*1fa4b3daSHector Dearman method = getattr( 35*1fa4b3daSHector Dearman test, test._testMethodName) # pylint: disable=protected-access 36*1fa4b3daSHector Dearman if not decorators.ShouldSkip(method, options.device): 37*1fa4b3daSHector Dearman suite.addTest(test) 38*1fa4b3daSHector Dearman 39*1fa4b3daSHector Dearman result = unittest.TextTestRunner(verbosity=2).run(suite) 40*1fa4b3daSHector Dearman if result.wasSuccessful(): 41*1fa4b3daSHector Dearman sys.exit(0) 42*1fa4b3daSHector Dearman else: 43*1fa4b3daSHector Dearman sys.exit(1) 44*1fa4b3daSHector Dearman 45*1fa4b3daSHector Dearmanif __name__ == '__main__': 46*1fa4b3daSHector Dearman main() 47