Skip to content

Commit dc8b2d3

Browse files
committedOct 26, 2015
Port the python api decorator to use test categories
Summary: Per discussions on the mailing list, I have implemented a decorator which annotates individual test methods with categories. I have used this framework to replace the '-a' and '+a' command-line switches (now '-G pyapi' and '--skip-category pyapi') and the @python_api_test decorator (now @add_test_categories('pyapi')). The test suite now gives an error message suggesting the new options if the user specifies the deprecated +/-a switches. If the general direction is good, I will follow this up with other switches. Reviewers: tberghammer, tfiala, granata.enrico, zturner Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D14020 llvm-svn: 251277
1 parent 4cfc919 commit dc8b2d3

File tree

96 files changed

+235
-262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+235
-262
lines changed
 

‎lldb/test/dotest.py

Lines changed: 7 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import inspect
4242
import unittest2
4343
import lldbtest_config
44+
import test_categories
4445

4546
import six
4647

@@ -80,33 +81,9 @@ def writeln(self, arg=None):
8081
# Global variables:
8182
#
8283

83-
# Dictionary of categories
84-
# When you define a new category for your testcases, be sure to add it here, or the test suite
85-
# will gladly complain as soon as you try to use it. This allows us to centralize which categories
86-
# exist, and to provide a description for each one
87-
validCategories = {
88-
'dataformatters':'Tests related to the type command and the data formatters subsystem',
89-
'expression':'Tests related to the expression parser',
90-
'objc':'Tests related to the Objective-C programming language support',
91-
'pyapi':'Tests related to the Python API',
92-
'basic_process': 'Basic process execution sniff tests.',
93-
'cmdline' : 'Tests related to the LLDB command-line interface',
94-
'dyntype' : 'Tests related to dynamic type support',
95-
'stresstest' : 'Tests related to stressing lldb limits',
96-
'flakey' : 'Flakey test cases, i.e. tests that do not reliably pass at each execution'
97-
}
98-
9984
# The test suite.
10085
suite = unittest2.TestSuite()
10186

102-
# By default, both command line and Python API tests are performed.
103-
# Use @python_api_test decorator, defined in lldbtest.py, to mark a test as
104-
# a Python API test.
105-
dont_do_python_api_test = False
106-
107-
# By default, both command line and Python API tests are performed.
108-
just_do_python_api_test = False
109-
11087
# By default, lldb-mi tests are performed if lldb-mi can be found.
11188
# Use @lldbmi_test decorator, defined in lldbtest.py, to mark a test as
11289
# a lldb-mi test.
@@ -389,35 +366,6 @@ def usage(parser):
389366
sys.exit(0)
390367

391368

392-
def unique_string_match(yourentry,list):
393-
candidate = None
394-
for item in list:
395-
if item.startswith(yourentry):
396-
if candidate:
397-
return None
398-
candidate = item
399-
return candidate
400-
401-
def validate_categories(categories):
402-
"""For each category in categories, ensure that it's a valid category (or a prefix thereof).
403-
If a category is invalid, print a message and quit.
404-
If all categories are valid, return the list of categories. Prefixes are expanded in the
405-
returned list.
406-
"""
407-
global validCategories
408-
result = []
409-
for category in categories:
410-
origCategory = category
411-
if category not in validCategories:
412-
category = unique_string_match(category, validCategories)
413-
if (category not in validCategories) or category == None:
414-
print("fatal error: category '" + origCategory + "' is not a valid category")
415-
print("if you have added a new category, please edit dotest.py, adding your new category to validCategories")
416-
print("else, please specify one or more of the following: " + str(list(validCategories.keys())))
417-
sys.exit(1)
418-
result.append(category)
419-
return result
420-
421369
def setCrashInfoHook_Mac(text):
422370
import crashinfo
423371
crashinfo.setCrashReporterDescription(text)
@@ -472,8 +420,6 @@ def parseOptionsAndInitTestdirs():
472420
'-h/--help as the first option prints out usage info and exit the program.
473421
"""
474422

475-
global dont_do_python_api_test
476-
global just_do_python_api_test
477423
global dont_do_lldbmi_test
478424
global just_do_lldbmi_test
479425
global just_do_benchmarks_test
@@ -592,13 +538,13 @@ def parseOptionsAndInitTestdirs():
592538
archs = [platform_machine]
593539

594540
if args.categoriesList:
595-
categoriesList = set(validate_categories(args.categoriesList))
541+
categoriesList = set(test_categories.validate(args.categoriesList, False))
596542
useCategories = True
597543
else:
598544
categoriesList = []
599545

600546
if args.skipCategories:
601-
skipCategories = validate_categories(args.skipCategories)
547+
skipCategories = test_categories.validate(args.skipCategories, False)
602548

603549
if args.D:
604550
dumpSysPath = True
@@ -615,14 +561,10 @@ def parseOptionsAndInitTestdirs():
615561
elif args.N == 'dsym':
616562
dont_do_dsym_test = True
617563

618-
if args.a:
619-
dont_do_python_api_test = True
620-
621-
if args.plus_a:
622-
if dont_do_python_api_test:
623-
print("Warning: -a and +a can't both be specified! Using only -a")
624-
else:
625-
just_do_python_api_test = True
564+
if args.a or args.plus_a:
565+
print("Options '-a' and '+a' have been deprecated. Please use the test category\n"
566+
"functionality (-G pyapi, --skip-category pyapi) instead.")
567+
sys.exit(1)
626568

627569
if args.plus_b:
628570
just_do_benchmarks_test = True
@@ -785,10 +727,6 @@ def parseOptionsAndInitTestdirs():
785727
if do_help == True:
786728
usage(parser)
787729

788-
# Do not specify both '-a' and '+a' at the same time.
789-
if dont_do_python_api_test and just_do_python_api_test:
790-
usage(parser)
791-
792730
# Do not specify both '-m' and '+m' at the same time.
793731
if dont_do_lldbmi_test and just_do_lldbmi_test:
794732
usage(parser)
@@ -1579,8 +1517,6 @@ def getsource_if_available(obj):
15791517
lldb.lldbtest_remote_shell_template = lldbtest_remote_shell_template
15801518

15811519
# Put all these test decorators in the lldb namespace.
1582-
lldb.dont_do_python_api_test = dont_do_python_api_test
1583-
lldb.just_do_python_api_test = just_do_python_api_test
15841520
lldb.dont_do_lldbmi_test = dont_do_lldbmi_test
15851521
lldb.just_do_lldbmi_test = just_do_lldbmi_test
15861522
lldb.just_do_benchmarks_test = just_do_benchmarks_test

‎lldb/test/dotest_args.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ def create_parser():
5555
# Test filtering options
5656
group = parser.add_argument_group('Test filtering options')
5757
group.add_argument('-N', choices=['dwarf', 'dwo', 'dsym'], help="Don't do test cases marked with the @dsym_test/@dwarf_test/@dwo_test decorator by passing dsym/dwarf/dwo as the option arg")
58-
X('-a', "Don't do lldb Python API tests")
59-
X('+a', "Just do lldb Python API tests. Do not specify along with '-a'", dest='plus_a')
6058
X('+b', 'Just do benchmark tests', dest='plus_b')
6159
group.add_argument('-b', metavar='blacklist', help='Read a blacklist file specified after this option')
6260
group.add_argument('-f', metavar='filterspec', action='append', help='Specify a filter, which consists of the test class name, a dot, followed by the test method, to only admit such test into the test suite') # FIXME: Example?
@@ -183,6 +181,13 @@ def create_parser():
183181
# Remove the reference to our helper function
184182
del X
185183

184+
D = lambda optstr, **kwargs: group.add_argument(optstr, action='store_true', **kwargs)
185+
group = parser.add_argument_group('Deprecated options (do not use)')
186+
# Deprecated on 23.10.2015. Remove completely after a grace period.
187+
D('-a')
188+
D('+a', dest='plus_a')
189+
del D
190+
186191
group = parser.add_argument_group('Test directories')
187192
group.add_argument('args', metavar='test-dir', nargs='*', help='Specify a list of directory names to search for test modules named after Test*.py (test discovery). If empty, search from the current working directory instead.')
188193

0 commit comments

Comments
 (0)