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