19707bb6e50715489119bd756f208d3e9b7072848Johnny Chen#!/usr/bin/env python 29707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 39707bb6e50715489119bd756f208d3e9b7072848Johnny Chen""" 49707bb6e50715489119bd756f208d3e9b7072848Johnny ChenA simple testing framework for lldb using python's unit testing framework. 59707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 69707bb6e50715489119bd756f208d3e9b7072848Johnny ChenTests for lldb are written as python scripts which take advantage of the script 79707bb6e50715489119bd756f208d3e9b7072848Johnny Chenbridging provided by LLDB.framework to interact with lldb core. 89707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 99707bb6e50715489119bd756f208d3e9b7072848Johnny ChenA specific naming pattern is followed by the .py script to be recognized as 109707bb6e50715489119bd756f208d3e9b7072848Johnny Chena module which implements a test scenario, namely, Test*.py. 119707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 129707bb6e50715489119bd756f208d3e9b7072848Johnny ChenTo specify the directories where "Test*.py" python test scripts are located, 139707bb6e50715489119bd756f208d3e9b7072848Johnny Chenyou need to pass in a list of directory names. By default, the current 149707bb6e50715489119bd756f208d3e9b7072848Johnny Chenworking directory is searched if nothing is specified on the command line. 15872aee15367f49a091d2d327f123cfba3eaacc48Johnny Chen 16872aee15367f49a091d2d327f123cfba3eaacc48Johnny ChenType: 17872aee15367f49a091d2d327f123cfba3eaacc48Johnny Chen 18872aee15367f49a091d2d327f123cfba3eaacc48Johnny Chen./dotest.py -h 19872aee15367f49a091d2d327f123cfba3eaacc48Johnny Chen 20872aee15367f49a091d2d327f123cfba3eaacc48Johnny Chenfor available options. 219707bb6e50715489119bd756f208d3e9b7072848Johnny Chen""" 229707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 234793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Claytonimport os 244793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Claytonimport platform 254793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Claytonimport signal 262891bb03e1ceafe4f894d7edb01f15b8ba890d27Johnny Chenimport subprocess 274793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Claytonimport sys 284793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Claytonimport textwrap 294793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Claytonimport time 3075e28f942c1b9f9c6d5a0d5f2efd037cbbc9fc74Johnny Chenimport unittest2 31bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granataimport progress 329707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 33d3eb83791bf5fdfe60925766383950015d095919Filipe Cabecinhasif sys.version_info >= (2, 7): 34d3eb83791bf5fdfe60925766383950015d095919Filipe Cabecinhas argparse = __import__('argparse') 35d3eb83791bf5fdfe60925766383950015d095919Filipe Cabecinhaselse: 36d3eb83791bf5fdfe60925766383950015d095919Filipe Cabecinhas argparse = __import__('argparse_compat') 37d3eb83791bf5fdfe60925766383950015d095919Filipe Cabecinhas 38f3b68becfe3c7310958375874b08d4891a51b410Daniel Maleadef parse_args(parser): 39f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea """ Returns an argument object. LLDB_TEST_ARGUMENTS environment variable can 40f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea be used to pass additional arguments if a compatible (>=2.7) argparse 41f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea library is available. 42f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea """ 43f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea if sys.version_info >= (2, 7): 44f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea args = ArgParseNamespace() 45f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea 46f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea if ('LLDB_TEST_ARGUMENTS' in os.environ): 47f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea print "Arguments passed through environment: '%s'" % os.environ['LLDB_TEST_ARGUMENTS'] 48f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea args = parser.parse_args([sys.argv[0]].__add__(os.environ['LLDB_TEST_ARGUMENTS'].split()),namespace=args) 49f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea 50f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea return parser.parse_args(namespace=args) 51f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea else: 52f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea return parser.parse_args() 53f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea 5426901c8c615beb9f2942bae337d927ff38535687Johnny Chendef is_exe(fpath): 55f2c7b28ace015f755b1585d9e0633be0aa27819cJohnny Chen """Returns true if fpath is an executable.""" 5626901c8c615beb9f2942bae337d927ff38535687Johnny Chen return os.path.isfile(fpath) and os.access(fpath, os.X_OK) 5726901c8c615beb9f2942bae337d927ff38535687Johnny Chen 5826901c8c615beb9f2942bae337d927ff38535687Johnny Chendef which(program): 59f2c7b28ace015f755b1585d9e0633be0aa27819cJohnny Chen """Returns the full path to a program; None otherwise.""" 6026901c8c615beb9f2942bae337d927ff38535687Johnny Chen fpath, fname = os.path.split(program) 6126901c8c615beb9f2942bae337d927ff38535687Johnny Chen if fpath: 6226901c8c615beb9f2942bae337d927ff38535687Johnny Chen if is_exe(program): 6326901c8c615beb9f2942bae337d927ff38535687Johnny Chen return program 6426901c8c615beb9f2942bae337d927ff38535687Johnny Chen else: 6526901c8c615beb9f2942bae337d927ff38535687Johnny Chen for path in os.environ["PATH"].split(os.pathsep): 6626901c8c615beb9f2942bae337d927ff38535687Johnny Chen exe_file = os.path.join(path, program) 6726901c8c615beb9f2942bae337d927ff38535687Johnny Chen if is_exe(exe_file): 6826901c8c615beb9f2942bae337d927ff38535687Johnny Chen return exe_file 6926901c8c615beb9f2942bae337d927ff38535687Johnny Chen return None 7026901c8c615beb9f2942bae337d927ff38535687Johnny Chen 71877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chenclass _WritelnDecorator(object): 72877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen """Used to decorate file-like objects with a handy 'writeln' method""" 73877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen def __init__(self,stream): 74877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen self.stream = stream 75877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen 76877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen def __getattr__(self, attr): 77877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen if attr in ('stream', '__getstate__'): 78877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen raise AttributeError(attr) 79877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen return getattr(self.stream,attr) 80877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen 81877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen def writeln(self, arg=None): 82877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen if arg: 83877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen self.write(arg) 84877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen self.write('\n') # text-mode streams translate to \r\n if needed 85877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen 869707bb6e50715489119bd756f208d3e9b7072848Johnny Chen# 879707bb6e50715489119bd756f208d3e9b7072848Johnny Chen# Global variables: 889707bb6e50715489119bd756f208d3e9b7072848Johnny Chen# 899707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 90ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata# Dictionary of categories 91ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata# When you define a new category for your testcases, be sure to add it here, or the test suite 92ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata# will gladly complain as soon as you try to use it. This allows us to centralize which categories 93ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata# exist, and to provide a description for each one 94ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico GranatavalidCategories = { 95ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata'dataformatters':'Tests related to the type command and the data formatters subsystem', 96ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata'expression':'Tests related to the expression parser', 97ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata'objc':'Tests related to the Objective-C programming language support', 9860139f32db191a977a198ac07ee12e19d6d1071bJim Ingham'pyapi':'Tests related to the Python API', 993cb3fe3da5851d90504b7c36817863a413447181Enrico Granata'basic_process': 'Basic process execution sniff tests.', 1003cb3fe3da5851d90504b7c36817863a413447181Enrico Granata'cmdline' : 'Tests related to the LLDB command-line interface' 101ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata} 102ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata 1039707bb6e50715489119bd756f208d3e9b7072848Johnny Chen# The test suite. 10475e28f942c1b9f9c6d5a0d5f2efd037cbbc9fc74Johnny Chensuite = unittest2.TestSuite() 1059707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 1064f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chen# By default, both command line and Python API tests are performed. 1073ebdaccbbb3567d6de652b91083997fbf10079baJohnny Chen# Use @python_api_test decorator, defined in lldbtest.py, to mark a test as 1083ebdaccbbb3567d6de652b91083997fbf10079baJohnny Chen# a Python API test. 1094f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chendont_do_python_api_test = False 1104f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chen 1114f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chen# By default, both command line and Python API tests are performed. 1124f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chenjust_do_python_api_test = False 1134f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chen 11482ccf4033d09dc7002637ddc70a3ffcc518a58c9Johnny Chen# By default, benchmarks tests are not run. 11582ccf4033d09dc7002637ddc70a3ffcc518a58c9Johnny Chenjust_do_benchmarks_test = False 11682ccf4033d09dc7002637ddc70a3ffcc518a58c9Johnny Chen 117a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chen# By default, both dsym and dwarf tests are performed. 118a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chen# Use @dsym_test or @dwarf_test decorators, defined in lldbtest.py, to mark a test 119a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chen# as a dsym or dwarf test. Use '-N dsym' or '-N dwarf' to exclude dsym or dwarf 120a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chen# tests from running. 121bd5505c04a480992eb2023f8dff08f97a694017bEd Mastedont_do_dsym_test = "linux" in sys.platform or "freebsd" in sys.platform 122a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chendont_do_dwarf_test = False 123a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chen 12482e6b1ef7cdb39c0d0c93142b195969b2dee63f0Johnny Chen# The blacklist is optional (-b blacklistFile) and allows a central place to skip 12582e6b1ef7cdb39c0d0c93142b195969b2dee63f0Johnny Chen# testclass's and/or testclass.testmethod's. 12682e6b1ef7cdb39c0d0c93142b195969b2dee63f0Johnny Chenblacklist = None 12782e6b1ef7cdb39c0d0c93142b195969b2dee63f0Johnny Chen 12882e6b1ef7cdb39c0d0c93142b195969b2dee63f0Johnny Chen# The dictionary as a result of sourcing blacklistFile. 12982e6b1ef7cdb39c0d0c93142b195969b2dee63f0Johnny ChenblacklistConfig = {} 13082e6b1ef7cdb39c0d0c93142b195969b2dee63f0Johnny Chen 131ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata# The list of categories we said we care about 132ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico GranatacategoriesList = None 133ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata# set to true if we are going to use categories for cherry-picking test cases 134ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico GranatauseCategories = False 1352bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit# Categories we want to skip 1362bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du ToitskipCategories = [] 137ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata# use this to track per-category failures 138ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico GranatafailuresPerCategory = {} 139ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata 1400acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan# The path to LLDB.framework is optional. 1410acf4c6de1540f316e0c2b1bae02a943dba655deSean CallananlldbFrameworkPath = None 1420acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan 1430acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan# The path to lldb is optional 1440acf4c6de1540f316e0c2b1bae02a943dba655deSean CallananlldbExecutablePath = None 1450acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan 1469fdb0a9dd07ac6cf826d9f90f5457b571adedff5Johnny Chen# The config file is optional. 1479fdb0a9dd07ac6cf826d9f90f5457b571adedff5Johnny ChenconfigFile = None 1489fdb0a9dd07ac6cf826d9f90f5457b571adedff5Johnny Chen 149d2acdb38ed0f756e8dd846e65fa149bd49a872c3Johnny Chen# Test suite repeat count. Can be overwritten with '-# count'. 150d2acdb38ed0f756e8dd846e65fa149bd49a872c3Johnny Chencount = 1 151d2acdb38ed0f756e8dd846e65fa149bd49a872c3Johnny Chen 152b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen# The dictionary as a result of sourcing configFile. 153b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chenconfig = {} 154ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen# The pre_flight and post_flight functions come from reading a config file. 155ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chenpre_flight = None 156ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chenpost_flight = None 157b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen 1581a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen# The 'archs' and 'compilers' can be specified via either command line or configFile, 1594793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton# with the command line overriding the configFile. The corresponding options can be 160d3eb83791bf5fdfe60925766383950015d095919Filipe Cabecinhas# specified more than once. For example, "-A x86_64 -A i386" => archs=['x86_64', 'i386'] 1614793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton# and "-C gcc -C clang" => compilers=['gcc', 'clang']. 1624793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Claytonarchs = None # Must be initialized after option parsing 1634793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Claytoncompilers = None # Must be initialized after option parsing 1641a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen 1651abe4c00bbce29b53e3bd2a5f35de431cb59081bJohnny Chen# The arch might dictate some specific CFLAGS to be passed to the toolchain to build 1661abe4c00bbce29b53e3bd2a5f35de431cb59081bJohnny Chen# the inferior programs. The global variable cflags_extras provides a hook to do 1671abe4c00bbce29b53e3bd2a5f35de431cb59081bJohnny Chen# just that. 1681abe4c00bbce29b53e3bd2a5f35de431cb59081bJohnny Chencflags_extras = '' 1691abe4c00bbce29b53e3bd2a5f35de431cb59081bJohnny Chen 17091960d3b4f1c8ccbc7b2087bc82fe2cc24b45f5aJohnny Chen# Delay startup in order for the debugger to attach. 17191960d3b4f1c8ccbc7b2087bc82fe2cc24b45f5aJohnny Chendelay = False 17291960d3b4f1c8ccbc7b2087bc82fe2cc24b45f5aJohnny Chen 173d536233de27d7e55d2c61fd55bf5aa624201c8dcJohnny Chen# Dump the Python sys.path variable. Use '-D' to dump sys.path. 17450bc638c63c838adf8f7ddf28430bba5cb136c50Johnny ChendumpSysPath = False 17550bc638c63c838adf8f7ddf28430bba5cb136c50Johnny Chen 176e00c9303c148e3ad4d1e511a27f3104cdd404e07Johnny Chen# Full path of the benchmark executable, as specified by the '-e' option. 177e00c9303c148e3ad4d1e511a27f3104cdd404e07Johnny ChenbmExecutable = None 178e00c9303c148e3ad4d1e511a27f3104cdd404e07Johnny Chen# The breakpoint specification of bmExecutable, as specified by the '-x' option. 179e00c9303c148e3ad4d1e511a27f3104cdd404e07Johnny ChenbmBreakpointSpec = None 1805f2ed17114c1711a23011c160832b318d77db888Johnny Chen# The benchamrk iteration count, as specified by the '-y' option. 1815f2ed17114c1711a23011c160832b318d77db888Johnny ChenbmIterationCount = -1 182e00c9303c148e3ad4d1e511a27f3104cdd404e07Johnny Chen 183e9eae8142a492bb17af559eed5ad1a5e382c3905Johnny Chen# By default, don't exclude any directories. Use '-X' to add one excluded directory. 184e9eae8142a492bb17af559eed5ad1a5e382c3905Johnny Chenexcluded = set(['.svn', '.git']) 185e9eae8142a492bb17af559eed5ad1a5e382c3905Johnny Chen 1867d6d84435a99d8cc59523b0c1985a8eb4f2af5bfJohnny Chen# By default, failfast is False. Use '-F' to overwrite it. 1877d6d84435a99d8cc59523b0c1985a8eb4f2af5bfJohnny Chenfailfast = False 1887d6d84435a99d8cc59523b0c1985a8eb4f2af5bfJohnny Chen 189c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chen# The filters (testclass.testmethod) used to admit tests into our test suite. 190c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chenfilters = [] 191b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen 19238f823c14468f8dec5a0568828ab22989240179dJohnny Chen# The runhooks is a list of lldb commands specifically for the debugger. 19338f823c14468f8dec5a0568828ab22989240179dJohnny Chen# Use '-k' to specify a runhook. 19438f823c14468f8dec5a0568828ab22989240179dJohnny ChenrunHooks = [] 19538f823c14468f8dec5a0568828ab22989240179dJohnny Chen 196a224cd19e4dbefdcb6c3769619133c155c185dd8Johnny Chen# If '-g' is specified, the filterspec is not exclusive. If a test module does 197a224cd19e4dbefdcb6c3769619133c155c185dd8Johnny Chen# not contain testclass.testmethod which matches the filterspec, the whole test 198a224cd19e4dbefdcb6c3769619133c155c185dd8Johnny Chen# module is still admitted into our test suite. fs4all flag defaults to True. 199a224cd19e4dbefdcb6c3769619133c155c185dd8Johnny Chenfs4all = True 200b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen 201af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen# Ignore the build search path relative to this script to locate the lldb.py module. 202af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chenignore = False 203af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen 204028d8ebd7e97d46e3de13fd977f8a17d6bf246f5Johnny Chen# By default, we do not skip build and cleanup. Use '-S' option to override. 205028d8ebd7e97d46e3de13fd977f8a17d6bf246f5Johnny Chenskip_build_and_cleanup = False 206028d8ebd7e97d46e3de13fd977f8a17d6bf246f5Johnny Chen 207548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen# By default, we skip long running test case. Use '-l' option to override. 208028d8ebd7e97d46e3de13fd977f8a17d6bf246f5Johnny Chenskip_long_running_test = True 20941998197e9d81cba31ac4645c1ec5f0ba7ca1668Johnny Chen 210fe5f1ed2d4ca6cc0039c1069980c998330c4027cJohnny Chen# By default, we print the build dir, lldb version, and svn info. Use '-n' option to 211fe5f1ed2d4ca6cc0039c1069980c998330c4027cJohnny Chen# turn it off. 212fe5f1ed2d4ca6cc0039c1069980c998330c4027cJohnny ChennoHeaders = False 213fe5f1ed2d4ca6cc0039c1069980c998330c4027cJohnny Chen 214361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea# Parsable mode silences headers, and any other output this script might generate, and instead 215361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea# prints machine-readable output similar to what clang tests produce. 216361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Maleaparsable = False 217361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea 2187c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen# The regular expression pattern to match against eligible filenames as our test cases. 2197c52ff1d83ec262f35c9a825af107735913e7225Johnny Chenregexp = None 2207c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen 221548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen# By default, tests are executed in place and cleanups are performed afterwards. 222548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen# Use '-r dir' option to relocate the tests and their intermediate files to a 223548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen# different directory and to forgo any cleanups. The directory specified must 224548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen# not exist yet. 225548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chenrdir = None 226548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen 227125fc2b1ea49af439e86bbf8f32fce8bbd5a7cddJohnny Chen# By default, recorded session info for errored/failed test are dumped into its 228125fc2b1ea49af439e86bbf8f32fce8bbd5a7cddJohnny Chen# own file under a session directory named after the timestamp of the test suite 229125fc2b1ea49af439e86bbf8f32fce8bbd5a7cddJohnny Chen# run. Use '-s session-dir-name' to specify a specific dir name. 230125fc2b1ea49af439e86bbf8f32fce8bbd5a7cddJohnny Chensdir_name = None 231125fc2b1ea49af439e86bbf8f32fce8bbd5a7cddJohnny Chen 23263c2cba24d3dd924211a4ea7a9ef3ff64555cfbbJohnny Chen# Set this flag if there is any session info dumped during the test run. 23363c2cba24d3dd924211a4ea7a9ef3ff64555cfbbJohnny Chensdir_has_content = False 23463c2cba24d3dd924211a4ea7a9ef3ff64555cfbbJohnny Chen 235b5fe80c62f0de8b855e0ee4bf25d3325f52e1984Johnny Chen# svn_info stores the output from 'svn info lldb.base.dir'. 236b5fe80c62f0de8b855e0ee4bf25d3325f52e1984Johnny Chensvn_info = '' 237b5fe80c62f0de8b855e0ee4bf25d3325f52e1984Johnny Chen 238814c8135ab879d07ebbe69cc099c7181fe2b107cEnrico Granata# svn_silent means do not try to obtain svn status 239814c8135ab879d07ebbe69cc099c7181fe2b107cEnrico Granatasvn_silent = True 240814c8135ab879d07ebbe69cc099c7181fe2b107cEnrico Granata 2419707bb6e50715489119bd756f208d3e9b7072848Johnny Chen# Default verbosity is 0. 24275f260ab03aa7277b100e1bff477b13c6abacbb7Jim Inghamverbose = 1 2439707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 24408967199e95ad3ad0d5a65fd6877d85386e533f7Johnny Chen# Set to True only if verbose is 0 and LLDB trace mode is off. 24508967199e95ad3ad0d5a65fd6877d85386e533f7Johnny Chenprogress_bar = False 24608967199e95ad3ad0d5a65fd6877d85386e533f7Johnny Chen 24761aca48855d023d7dbb1b4743704907b77f6acbaPeter Collingbourne# By default, search from the script directory. 24861aca48855d023d7dbb1b4743704907b77f6acbaPeter Collingbournetestdirs = [ sys.path[0] ] 2499707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 250877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen# Separator string. 251877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chenseparator = '-' * 70 252877c7e4a4af2dd95b3999c1d7381b661787155cbJohnny Chen 25324765573e1f52b45f789e5358fd56aab577e429bDaniel Maleafailed = False 2549707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 2554793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Claytondef usage(parser): 2564793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton parser.print_help() 2574f347cbb039d9b5ef5f5772dcb672b5557feeb7eJim Ingham if verbose > 0: 2584f347cbb039d9b5ef5f5772dcb672b5557feeb7eJim Ingham print """ 2599656ab2a9777e78799ed5df55fcd17eace5f597eJohnny ChenExamples: 2609656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chen 261a224cd19e4dbefdcb6c3769619133c155c185dd8Johnny ChenThis is an example of using the -f option to pinpoint to a specfic test class 262a224cd19e4dbefdcb6c3769619133c155c185dd8Johnny Chenand test method to be run: 2636ad7e5e815daf24afc345eed219226d52d0e1dcdJohnny Chen 264a224cd19e4dbefdcb6c3769619133c155c185dd8Johnny Chen$ ./dotest.py -f ClassTypesTestCase.test_with_dsym_and_run_command 2656ad7e5e815daf24afc345eed219226d52d0e1dcdJohnny Chen---------------------------------------------------------------------- 2666ad7e5e815daf24afc345eed219226d52d0e1dcdJohnny ChenCollected 1 test 2676ad7e5e815daf24afc345eed219226d52d0e1dcdJohnny Chen 2686ad7e5e815daf24afc345eed219226d52d0e1dcdJohnny Chentest_with_dsym_and_run_command (TestClassTypes.ClassTypesTestCase) 2696ad7e5e815daf24afc345eed219226d52d0e1dcdJohnny ChenTest 'frame variable this' when stopped on a class constructor. ... ok 2706ad7e5e815daf24afc345eed219226d52d0e1dcdJohnny Chen 2716ad7e5e815daf24afc345eed219226d52d0e1dcdJohnny Chen---------------------------------------------------------------------- 2726ad7e5e815daf24afc345eed219226d52d0e1dcdJohnny ChenRan 1 test in 1.396s 2736ad7e5e815daf24afc345eed219226d52d0e1dcdJohnny Chen 2746ad7e5e815daf24afc345eed219226d52d0e1dcdJohnny ChenOK 2759656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chen 2769656ab2a9777e78799ed5df55fcd17eace5f597eJohnny ChenAnd this is an example of using the -p option to run a single file (the filename 2779656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chenmatches the pattern 'ObjC' and it happens to be 'TestObjCMethods.py'): 2789656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chen 2799656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chen$ ./dotest.py -v -p ObjC 2809656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chen---------------------------------------------------------------------- 2819656ab2a9777e78799ed5df55fcd17eace5f597eJohnny ChenCollected 4 tests 2829656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chen 2839656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chentest_break_with_dsym (TestObjCMethods.FoundationTestCase) 284b72d0f098e45936fa72e26b1a026c603e17e2d6cGreg ClaytonTest setting objc breakpoints using '_regexp-break' and 'breakpoint set'. ... ok 2859656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chentest_break_with_dwarf (TestObjCMethods.FoundationTestCase) 286b72d0f098e45936fa72e26b1a026c603e17e2d6cGreg ClaytonTest setting objc breakpoints using '_regexp-break' and 'breakpoint set'. ... ok 2879656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chentest_data_type_and_expr_with_dsym (TestObjCMethods.FoundationTestCase) 2889656ab2a9777e78799ed5df55fcd17eace5f597eJohnny ChenLookup objective-c data types and evaluate expressions. ... ok 2899656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chentest_data_type_and_expr_with_dwarf (TestObjCMethods.FoundationTestCase) 2909656ab2a9777e78799ed5df55fcd17eace5f597eJohnny ChenLookup objective-c data types and evaluate expressions. ... ok 2919656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chen 2929656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chen---------------------------------------------------------------------- 2939656ab2a9777e78799ed5df55fcd17eace5f597eJohnny ChenRan 4 tests in 16.661s 2949656ab2a9777e78799ed5df55fcd17eace5f597eJohnny Chen 2959656ab2a9777e78799ed5df55fcd17eace5f597eJohnny ChenOK 2966ad7e5e815daf24afc345eed219226d52d0e1dcdJohnny Chen 29758f9392cf71468cefaeeda34324cdef38f66f1dcJohnny ChenRunning of this script also sets up the LLDB_TEST environment variable so that 298af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chenindividual test cases can locate their supporting files correctly. The script 299af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chentries to set up Python's search paths for modules by looking at the build tree 300a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chenrelative to this script. See also the '-i' option in the following example. 301a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chen 302a85859f87fe7e6170af5e120b9b049f60410742dJohnny ChenFinally, this is an example of using the lldb.py module distributed/installed by 303a85859f87fe7e6170af5e120b9b049f60410742dJohnny ChenXcode4 to run against the tests under the 'forward' directory, and with the '-w' 304a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chenoption to add some delay between two tests. It uses ARCH=x86_64 to specify that 305a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chenas the architecture and CC=clang to specify the compiler used for the test run: 306a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chen 307a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chen$ PYTHONPATH=/Xcode4/Library/PrivateFrameworks/LLDB.framework/Versions/A/Resources/Python ARCH=x86_64 CC=clang ./dotest.py -v -w -i forward 308a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chen 309a85859f87fe7e6170af5e120b9b049f60410742dJohnny ChenSession logs for test failures/errors will go into directory '2010-11-11-13_56_16' 310a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chen---------------------------------------------------------------------- 311a85859f87fe7e6170af5e120b9b049f60410742dJohnny ChenCollected 2 tests 312a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chen 313a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chentest_with_dsym_and_run_command (TestForwardDeclaration.ForwardDeclarationTestCase) 314a85859f87fe7e6170af5e120b9b049f60410742dJohnny ChenDisplay *bar_ptr when stopped on a function with forward declaration of struct bar. ... ok 315a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chentest_with_dwarf_and_run_command (TestForwardDeclaration.ForwardDeclarationTestCase) 316a85859f87fe7e6170af5e120b9b049f60410742dJohnny ChenDisplay *bar_ptr when stopped on a function with forward declaration of struct bar. ... ok 317a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chen 318a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chen---------------------------------------------------------------------- 319a85859f87fe7e6170af5e120b9b049f60410742dJohnny ChenRan 2 tests in 5.659s 320a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chen 321a85859f87fe7e6170af5e120b9b049f60410742dJohnny ChenOK 322a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chen 323a85859f87fe7e6170af5e120b9b049f60410742dJohnny ChenThe 'Session ...' verbiage is recently introduced (see also the '-s' option) to 324a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chennotify the directory containing the session logs for test failures or errors. 325a85859f87fe7e6170af5e120b9b049f60410742dJohnny ChenIn case there is any test failure/error, a similar message is appended at the 326a85859f87fe7e6170af5e120b9b049f60410742dJohnny Chenend of the stderr output for your convenience. 327fde69bccb31c88b1fbb52c9ceadbd399bff104c7Johnny Chen 328fde69bccb31c88b1fbb52c9ceadbd399bff104c7Johnny ChenEnvironment variables related to loggings: 329fde69bccb31c88b1fbb52c9ceadbd399bff104c7Johnny Chen 330fde69bccb31c88b1fbb52c9ceadbd399bff104c7Johnny Cheno LLDB_LOG: if defined, specifies the log file pathname for the 'lldb' subsystem 331fde69bccb31c88b1fbb52c9ceadbd399bff104c7Johnny Chen with a default option of 'event process' if LLDB_LOG_OPTION is not defined. 332fde69bccb31c88b1fbb52c9ceadbd399bff104c7Johnny Chen 333fde69bccb31c88b1fbb52c9ceadbd399bff104c7Johnny Cheno GDB_REMOTE_LOG: if defined, specifies the log file pathname for the 334fde69bccb31c88b1fbb52c9ceadbd399bff104c7Johnny Chen 'process.gdb-remote' subsystem with a default option of 'packets' if 335fde69bccb31c88b1fbb52c9ceadbd399bff104c7Johnny Chen GDB_REMOTE_LOG_OPTION is not defined. 3369707bb6e50715489119bd756f208d3e9b7072848Johnny Chen""" 3379fdb0a9dd07ac6cf826d9f90f5457b571adedff5Johnny Chen sys.exit(0) 3389707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 3399707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 34069d7c10e876db3b84c9cd914271441a9cf81ff6dEnrico Granatadef unique_string_match(yourentry,list): 34169d7c10e876db3b84c9cd914271441a9cf81ff6dEnrico Granata candidate = None 34269d7c10e876db3b84c9cd914271441a9cf81ff6dEnrico Granata for item in list: 34369d7c10e876db3b84c9cd914271441a9cf81ff6dEnrico Granata if item.startswith(yourentry): 34469d7c10e876db3b84c9cd914271441a9cf81ff6dEnrico Granata if candidate: 34569d7c10e876db3b84c9cd914271441a9cf81ff6dEnrico Granata return None 34669d7c10e876db3b84c9cd914271441a9cf81ff6dEnrico Granata candidate = item 34769d7c10e876db3b84c9cd914271441a9cf81ff6dEnrico Granata return candidate 34869d7c10e876db3b84c9cd914271441a9cf81ff6dEnrico Granata 3496fa3c50f009787e87998e74e90a75d0e11efbda2Enrico Granataclass ArgParseNamespace(object): 3506fa3c50f009787e87998e74e90a75d0e11efbda2Enrico Granata pass 3516fa3c50f009787e87998e74e90a75d0e11efbda2Enrico Granata 3522bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toitdef validate_categories(categories): 3532bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit """For each category in categories, ensure that it's a valid category (or a prefix thereof). 3542bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit If a category is invalid, print a message and quit. 3552bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit If all categories are valid, return the list of categories. Prefixes are expanded in the 3562bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit returned list. 3572bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit """ 3582bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit global validCategories 3592bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit result = [] 3602bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit for category in categories: 3612bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit origCategory = category 3622bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit if category not in validCategories: 3632bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit category = unique_string_match(category, validCategories) 3642bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit if (category not in validCategories) or category == None: 3652bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit print "fatal error: category '" + origCategory + "' is not a valid category" 3662bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit print "if you have added a new category, please edit dotest.py, adding your new category to validCategories" 3672bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit print "else, please specify one or more of the following: " + str(validCategories.keys()) 3682bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit sys.exit(1) 3692bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit result.append(category) 3702bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit return result 3712bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit 372af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chendef parseOptionsAndInitTestdirs(): 373af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen """Initialize the list of directories containing our unittest scripts. 374af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen 375af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen '-h/--help as the first option prints out usage info and exit the program. 376af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen """ 377af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen 3784f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chen global dont_do_python_api_test 3794f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chen global just_do_python_api_test 38082ccf4033d09dc7002637ddc70a3ffcc518a58c9Johnny Chen global just_do_benchmarks_test 381a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chen global dont_do_dsym_test 382a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chen global dont_do_dwarf_test 38382e6b1ef7cdb39c0d0c93142b195969b2dee63f0Johnny Chen global blacklist 38482e6b1ef7cdb39c0d0c93142b195969b2dee63f0Johnny Chen global blacklistConfig 385ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata global categoriesList 386ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata global validCategories 387ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata global useCategories 3882bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit global skipCategories 3890acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan global lldbFrameworkPath 3900acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan global lldbExecutablePath 3919fdb0a9dd07ac6cf826d9f90f5457b571adedff5Johnny Chen global configFile 3921a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen global archs 3931a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen global compilers 394d2acdb38ed0f756e8dd846e65fa149bd49a872c3Johnny Chen global count 395af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen global delay 39650bc638c63c838adf8f7ddf28430bba5cb136c50Johnny Chen global dumpSysPath 397e00c9303c148e3ad4d1e511a27f3104cdd404e07Johnny Chen global bmExecutable 398e00c9303c148e3ad4d1e511a27f3104cdd404e07Johnny Chen global bmBreakpointSpec 3995f2ed17114c1711a23011c160832b318d77db888Johnny Chen global bmIterationCount 4007d6d84435a99d8cc59523b0c1985a8eb4f2af5bfJohnny Chen global failfast 401c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chen global filters 402b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen global fs4all 4037c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen global ignore 40408967199e95ad3ad0d5a65fd6877d85386e533f7Johnny Chen global progress_bar 40538f823c14468f8dec5a0568828ab22989240179dJohnny Chen global runHooks 406028d8ebd7e97d46e3de13fd977f8a17d6bf246f5Johnny Chen global skip_build_and_cleanup 407028d8ebd7e97d46e3de13fd977f8a17d6bf246f5Johnny Chen global skip_long_running_test 408fe5f1ed2d4ca6cc0039c1069980c998330c4027cJohnny Chen global noHeaders 409361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea global parsable 4107c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen global regexp 411548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen global rdir 412125fc2b1ea49af439e86bbf8f32fce8bbd5a7cddJohnny Chen global sdir_name 413814c8135ab879d07ebbe69cc099c7181fe2b107cEnrico Granata global svn_silent 414af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen global verbose 415af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen global testdirs 416af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen 4174f347cbb039d9b5ef5f5772dcb672b5557feeb7eJim Ingham do_help = False 4184f347cbb039d9b5ef5f5772dcb672b5557feeb7eJim Ingham 4194793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton parser = argparse.ArgumentParser(description='description', prefix_chars='+-', add_help=False) 4204793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group = None 4214793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 4224793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton # Helper function for boolean options (group will point to the current group when executing X) 4234793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X = lambda optstr, helpstr, **kwargs: group.add_argument(optstr, help=helpstr, action='store_true', **kwargs) 4244793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 4254793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group = parser.add_argument_group('Help') 4264793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-h', '--help', dest='h', action='store_true', help="Print this help message and exit. Add '-v' for more detailed help.") 4274793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 4284793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton # C and Python toolchain options 4294793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group = parser.add_argument_group('Toolchain options') 4304793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-A', '--arch', metavar='arch', action='append', dest='archs', help=textwrap.dedent('''Specify the architecture(s) to test. This option can be specified more than once''')) 4314793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-C', '--compiler', metavar='compiler', dest='compilers', action='append', help=textwrap.dedent('''Specify the compiler(s) used to build the inferior executables. The compiler path can be an executable basename or a full path to a compiler executable. This option can be specified multiple times.''')) 4324793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton # FIXME? This won't work for different extra flags according to each arch. 4334793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-E', metavar='extra-flags', help=textwrap.dedent('''Specify the extra flags to be passed to the toolchain when building the inferior programs to be debugged 4344793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton suggestions: do not lump the "-A arch1 -A arch2" together such that the -E option applies to only one of the architectures''')) 4354793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('-D', 'Dump the Python sys.path variable') 4364793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 4374793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton # Test filtering options 4384793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group = parser.add_argument_group('Test filtering options') 4394793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-N', choices=['dwarf', 'dsym'], help="Don't do test cases marked with the @dsym decorator by passing 'dsym' as the option arg, or don't do test cases marked with the @dwarf decorator by passing 'dwarf' as the option arg") 4404793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('-a', "Don't do lldb Python API tests") 4414793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('+a', "Just do lldb Python API tests. Do not specify along with '+a'", dest='plus_a') 4424793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('+b', 'Just do benchmark tests', dest='plus_b') 4434793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-b', metavar='blacklist', help='Read a blacklist file specified after this option') 44458b03a4a6c2cc68cf874efa25c76836084d5b080Enrico Granata 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? 4454793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('-g', 'If specified, the filterspec by -f is not exclusive, i.e., if a test module does not match the filterspec (testclass.testmethod), the whole module is still admitted to the test suite') 4464793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('-l', "Don't skip long running tests") 4474793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-p', metavar='pattern', help='Specify a regexp filename pattern for inclusion in the test suite') 4484793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-X', metavar='directory', help="Exclude a directory from consideration for test discovery. -X types => if 'types' appear in the pathname components of a potential testfile, it will be ignored") 449ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata group.add_argument('-G', '--category', metavar='category', action='append', dest='categoriesList', help=textwrap.dedent('''Specify categories of test cases of interest. Can be specified more than once.''')) 4502bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit group.add_argument('--skip-category', metavar='category', action='append', dest='skipCategories', help=textwrap.dedent('''Specify categories of test cases to skip. Takes precedence over -G. Can be specified more than once.''')) 4514793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 4524793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton # Configuration options 4534793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group = parser.add_argument_group('Configuration options') 4544793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-c', metavar='config-file', help='Read a config file specified after this option') # FIXME: additional doc. 4550acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan group.add_argument('--framework', metavar='framework-path', help='The path to LLDB.framework') 4560acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan group.add_argument('--executable', metavar='executable-path', help='The path to the lldb executable') 457042b14cb98cb44779bf2b1c804786130178bba8cDaniel Malea group.add_argument('--libcxx', metavar='directory', help='The path to custom libc++ library') 4584793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-e', metavar='benchmark-exe', help='Specify the full path of an executable used for benchmark purposes (see also: -x)') 4594793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-k', metavar='command', action='append', help="Specify a runhook, which is an lldb command to be executed by the debugger; The option can occur multiple times. The commands are executed one after the other to bring the debugger to a desired state, so that, for example, further benchmarking can be done") 4604793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-R', metavar='dir', help='Specify a directory to relocate the tests and their intermediate files to. BE WARNED THAT the directory, if exists, will be deleted before running this test driver. No cleanup of intermediate test files is performed in this case') 4614793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-r', metavar='dir', help="Similar to '-R', except that the directory must not exist before running this test driver") 4624793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-s', metavar='name', help='Specify the name of the dir created to store the session files of tests with errored or failed status. If not specified, the test driver uses the timestamp as the session dir name') 4634793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-x', metavar='breakpoint-spec', help='Specify the breakpoint specification for the benchmark executable') 4644793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-y', type=int, metavar='count', help="Specify the iteration count used to collect our benchmarks. An example is the number of times to do 'thread step-over' to measure stepping speed.") 4654793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group.add_argument('-#', type=int, metavar='sharp', dest='sharp', help='Repeat the test suite for a specified number of times') 4664793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 4674793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton # Test-suite behaviour 4684793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group = parser.add_argument_group('Runtime behaviour options') 4694793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('-d', 'Delay startup for 10 seconds (in order for the debugger to attach)') 4704793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('-F', 'Fail fast. Stop the test suite on the first error/failure') 4714793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('-i', "Ignore (don't bailout) if 'lldb.py' module cannot be located in the build tree relative to this script; use PYTHONPATH to locate the module") 4724793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('-n', "Don't print the headers like build dir, lldb version, and svn info at all") 47375f260ab03aa7277b100e1bff477b13c6abacbb7Jim Ingham X('-P', "Use the graphic progress bar.") 474361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea X('-q', "Don't print extra output from this script.") 4754793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('-S', "Skip the build and cleanup while running the test. Use this option with care as you would need to build the inferior(s) by hand and build the executable(s) with the correct name(s). This can be used with '-# n' to stress test certain test cases for n number of times") 4764793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('-t', 'Turn on tracing of lldb command and other detailed test executions') 477b85785cc7344a4cd6ec07397a447aa39495b22e8Greg Clayton group.add_argument('-u', dest='unset_env_varnames', metavar='variable', action='append', help='Specify an environment variable to unset before running the test cases. e.g., -u DYLD_INSERT_LIBRARIES -u MallocScribble') 4784793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('-v', 'Do verbose mode of unittest framework (print out each test case invocation)') 4794793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton X('-w', 'Insert some wait time (currently 0.5 sec) between consecutive test cases') 480814c8135ab879d07ebbe69cc099c7181fe2b107cEnrico Granata X('-T', 'Obtain and dump svn information for this checkout of LLDB (off by default)') 4814793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 4824793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton # Remove the reference to our helper function 4834793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton del X 4844793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 4854793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton group = parser.add_argument_group('Test directories') 4864793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 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.') 4876fa3c50f009787e87998e74e90a75d0e11efbda2Enrico Granata 488f3b68becfe3c7310958375874b08d4891a51b410Daniel Malea args = parse_args(parser) 4894793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton platform_system = platform.system() 4904793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton platform_machine = platform.machine() 4912d329243d1a41559699d2d4c1a42fb75b878ceb2Enrico Granata 492b85785cc7344a4cd6ec07397a447aa39495b22e8Greg Clayton if args.unset_env_varnames: 493b85785cc7344a4cd6ec07397a447aa39495b22e8Greg Clayton for env_var in args.unset_env_varnames: 494b85785cc7344a4cd6ec07397a447aa39495b22e8Greg Clayton if env_var in os.environ: 495b85785cc7344a4cd6ec07397a447aa39495b22e8Greg Clayton # From Python Doc: When unsetenv() is supported, deletion of items in os.environ 496b85785cc7344a4cd6ec07397a447aa39495b22e8Greg Clayton # is automatically translated into a corresponding call to unsetenv(). 497b85785cc7344a4cd6ec07397a447aa39495b22e8Greg Clayton del os.environ[env_var] 498b85785cc7344a4cd6ec07397a447aa39495b22e8Greg Clayton #os.unsetenv(env_var) 499b85785cc7344a4cd6ec07397a447aa39495b22e8Greg Clayton 500361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea # only print the args if being verbose (and parsable is off) 501361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea if args.v and not args.q: 502b0cb21eb83c900bf6a8b1d2f3b184e584056bbd6Enrico Granata print sys.argv 5034793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5044793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.h: 5054793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton do_help = True 5064793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5074793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.archs: 5084793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton archs = args.archs 5094793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton else: 5104793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if platform_system == 'Darwin' and platform_machine == 'x86_64': 5114793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton archs = ['x86_64', 'i386'] 5124f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chen else: 5134793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton archs = [platform_machine] 5144793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 515ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata if args.categoriesList: 5162bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit categoriesList = set(validate_categories(args.categoriesList)) 517ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata useCategories = True 518ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata else: 519ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata categoriesList = [] 520ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata 5212bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit if args.skipCategories: 5222bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit skipCategories = validate_categories(args.skipCategories) 5232bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit 5244793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.compilers: 5254793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton compilers = args.compilers 5264793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton else: 5274793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton compilers = ['clang'] 5284793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5294793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.D: 5304793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton dumpSysPath = True 5314793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5324793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.E: 5334793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton cflags_extras = args.E 5344793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton os.environ['CFLAGS_EXTRAS'] = cflags_extras 5354793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5364793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton # argparse makes sure we have correct options 5374793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.N == 'dwarf': 5384793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton dont_do_dwarf_test = True 5394793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton elif args.N == 'dsym': 5404793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton dont_do_dsym_test = True 5414793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5424793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.a: 5434793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton dont_do_python_api_test = True 5444793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5454793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.plus_a: 5464793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if dont_do_python_api_test: 5474793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton print "Warning: -a and +a can't both be specified! Using only -a" 548af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen else: 5494793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton just_do_python_api_test = True 5504793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5514793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.plus_b: 5524793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton just_do_benchmarks_test = True 5534793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5544793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.b: 5554793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.b.startswith('-'): 5564793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 5574793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton blacklistFile = args.b 5584793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if not os.path.isfile(blacklistFile): 5594793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton print 'Blacklist file:', blacklistFile, 'does not exist!' 5604793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 5614793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton # Now read the blacklist contents and assign it to blacklist. 5624793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton execfile(blacklistFile, globals(), blacklistConfig) 5634793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton blacklist = blacklistConfig.get('blacklist') 5644793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5654793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.c: 5664793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.c.startswith('-'): 5674793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 5684793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton configFile = args.c 5694793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if not os.path.isfile(configFile): 5704793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton print 'Config file:', configFile, 'does not exist!' 5714793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 5724793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5734793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.d: 5744793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton delay = True 5754793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5764793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.e: 5774793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.e.startswith('-'): 5784793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 5794793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton bmExecutable = args.e 5804793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if not is_exe(bmExecutable): 5814793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 5824793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5834793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.F: 5844793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton failfast = True 5854793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5864793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.f: 58758b03a4a6c2cc68cf874efa25c76836084d5b080Enrico Granata if any([x.startswith('-') for x in args.f]): 5884793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 58958b03a4a6c2cc68cf874efa25c76836084d5b080Enrico Granata filters.extend(args.f) 5904793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5914793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.g: 5924793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton fs4all = False 5934793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5944793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.i: 5954793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton ignore = True 5964793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 5974793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.k: 5984793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton runHooks.extend(args.k) 5994793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 6004793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.l: 6014793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton skip_long_running_test = False 6024793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 6030acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if args.framework: 6040acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbFrameworkPath = args.framework 6050acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan 6060acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if args.executable: 6070acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbExecutablePath = args.executable 6080acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan 609042b14cb98cb44779bf2b1c804786130178bba8cDaniel Malea if args.libcxx: 610042b14cb98cb44779bf2b1c804786130178bba8cDaniel Malea os.environ["LIBCXX_PATH"] = args.libcxx 611042b14cb98cb44779bf2b1c804786130178bba8cDaniel Malea 6124793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.n: 6134793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton noHeaders = True 6144793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 6154793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.p: 6164793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.p.startswith('-'): 6174793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 6184793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton regexp = args.p 6194793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 620361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea if args.q: 621361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea noHeaders = True 622361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea parsable = True 623361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea 62475f260ab03aa7277b100e1bff477b13c6abacbb7Jim Ingham if args.P: 62575f260ab03aa7277b100e1bff477b13c6abacbb7Jim Ingham progress_bar = True 62675f260ab03aa7277b100e1bff477b13c6abacbb7Jim Ingham verbose = 0 62775f260ab03aa7277b100e1bff477b13c6abacbb7Jim Ingham 6284793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.R: 6294793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.R.startswith('-'): 6304793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 6314793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton rdir = os.path.abspath(args.R) 6324793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if os.path.exists(rdir): 6334793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton import shutil 6344793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton print 'Removing tree:', rdir 6354793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton shutil.rmtree(rdir) 6364793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 6374793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.r: 6384793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.r.startswith('-'): 6394793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 6404793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton rdir = os.path.abspath(args.r) 6414793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if os.path.exists(rdir): 6424793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton print 'Relocated directory:', rdir, 'must not exist!' 6434793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 6444793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 6454793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.S: 6464793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton skip_build_and_cleanup = True 6474793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 6484793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.s: 6494793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.s.startswith('-'): 6504793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 6514793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton sdir_name = args.s 6524793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 6534793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.t: 6544793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton os.environ['LLDB_COMMAND_TRACE'] = 'YES' 6554793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 656814c8135ab879d07ebbe69cc099c7181fe2b107cEnrico Granata if args.T: 657814c8135ab879d07ebbe69cc099c7181fe2b107cEnrico Granata svn_silent = False 658814c8135ab879d07ebbe69cc099c7181fe2b107cEnrico Granata 6594793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.v: 6604793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton verbose = 2 6614793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 6624793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.w: 6634793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton os.environ['LLDB_WAIT_BETWEEN_TEST_CASES'] = 'YES' 6644793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 6654793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.X: 6664793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.X.startswith('-'): 6674793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 6684793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton excluded.add(args.X) 6694793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 6704793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.x: 6714793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.x.startswith('-'): 6724793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 6734793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton bmBreakpointSpec = args.x 6744793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 6754793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton # argparse makes sure we have a number 6764793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.y: 6774793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton bmIterationCount = args.y 6784793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton 6794793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton # argparse makes sure we have a number 6804793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if args.sharp: 6814793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton count = args.sharp 682af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen 6834f347cbb039d9b5ef5f5772dcb672b5557feeb7eJim Ingham if do_help == True: 6844793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 6854f347cbb039d9b5ef5f5772dcb672b5557feeb7eJim Ingham 686cc659ad4d604d198aac952cdea2a95a188184affJohnny Chen # Do not specify both '-a' and '+a' at the same time. 687cc659ad4d604d198aac952cdea2a95a188184affJohnny Chen if dont_do_python_api_test and just_do_python_api_test: 6884793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton usage(parser) 689cc659ad4d604d198aac952cdea2a95a188184affJohnny Chen 690af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen # Gather all the dirs passed on the command line. 6914793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if len(args.args) > 0: 6924793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton testdirs = map(os.path.abspath, args.args) 693af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen 694548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # If '-r dir' is specified, the tests should be run under the relocated 695548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # directory. Let's copy the testdirs over. 696548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen if rdir: 697548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen from shutil import copytree, ignore_patterns 698548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen 699548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen tmpdirs = [] 7003bc7e5e8960a8928b9811a10175627a397aa643dJohnny Chen orig_testdirs = testdirs[:] 701548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen for srcdir in testdirs: 7021abe4c00bbce29b53e3bd2a5f35de431cb59081bJohnny Chen # For example, /Volumes/data/lldb/svn/ToT/test/functionalities/watchpoint/hello_watchpoint 7031abe4c00bbce29b53e3bd2a5f35de431cb59081bJohnny Chen # shall be split into ['/Volumes/data/lldb/svn/ToT/', 'functionalities/watchpoint/hello_watchpoint']. 7041abe4c00bbce29b53e3bd2a5f35de431cb59081bJohnny Chen # Utilize the relative path to the 'test' directory to make our destination dir path. 7054793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton if ("test" + os.sep) in srcdir: 7064793e94ba92a5959e1c6afd987a38c08d3e6b755Greg Clayton to_split_on = "test" + os.sep 7073bc7e5e8960a8928b9811a10175627a397aa643dJohnny Chen else: 7083bc7e5e8960a8928b9811a10175627a397aa643dJohnny Chen to_split_on = "test" 7093bc7e5e8960a8928b9811a10175627a397aa643dJohnny Chen dstdir = os.path.join(rdir, srcdir.split(to_split_on)[1]) 7103bc7e5e8960a8928b9811a10175627a397aa643dJohnny Chen dstdir = dstdir.rstrip(os.sep) 711548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # Don't copy the *.pyc and .svn stuffs. 712548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen copytree(srcdir, dstdir, ignore=ignore_patterns('*.pyc', '.svn')) 713548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen tmpdirs.append(dstdir) 714548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen 715548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # This will be our modified testdirs. 716548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen testdirs = tmpdirs 717548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen 718548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # With '-r dir' specified, there's no cleanup of intermediate test files. 719548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen os.environ["LLDB_DO_CLEANUP"] = 'NO' 720548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen 7213bc7e5e8960a8928b9811a10175627a397aa643dJohnny Chen # If the original testdirs is ['test'], the make directory has already been copied 722548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # recursively and is contained within the rdir/test dir. For anything 723548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # else, we would need to copy over the make directory and its contents, 724548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # so that, os.listdir(rdir) looks like, for example: 725548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # 726548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # array_types conditional_break make 727548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # 728548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # where the make directory contains the Makefile.rules file. 7293bc7e5e8960a8928b9811a10175627a397aa643dJohnny Chen if len(testdirs) != 1 or os.path.basename(orig_testdirs[0]) != 'test': 730c056664431d0126f3fb7a57844eee54455807781Filipe Cabecinhas scriptdir = os.path.dirname(__file__) 731548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # Don't copy the .svn stuffs. 732c056664431d0126f3fb7a57844eee54455807781Filipe Cabecinhas copytree(os.path.join(scriptdir, 'make'), os.path.join(rdir, 'make'), 733548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen ignore=ignore_patterns('.svn')) 734548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen 735548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen #print "testdirs:", testdirs 736548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen 737b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen # Source the configFile if specified. 738b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen # The side effect, if any, will be felt from this point on. An example 739b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen # config file may be these simple two lines: 740b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen # 741b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen # sys.stderr = open("/tmp/lldbtest-stderr", "w") 742b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen # sys.stdout = open("/tmp/lldbtest-stdout", "w") 743b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen # 744b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen # which will reassign the two file objects to sys.stderr and sys.stdout, 745b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen # respectively. 746b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen # 7478c130645ee61963440ce2113233e2b3bd78683e5Johnny Chen # See also lldb-trunk/examples/test/usage-config. 748ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen global config, pre_flight, post_flight 749b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen if configFile: 750b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen # Pass config (a dictionary) as the locals namespace for side-effect. 751b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen execfile(configFile, globals(), config) 752ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen print "config:", config 753ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen if "pre_flight" in config: 754ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen pre_flight = config["pre_flight"] 755ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen if not callable(pre_flight): 756ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen print "fatal error: pre_flight is not callable, exiting." 757ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen sys.exit(1) 758ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen if "post_flight" in config: 759ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen post_flight = config["post_flight"] 760ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen if not callable(post_flight): 761ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen print "fatal error: post_flight is not callable, exiting." 762ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen sys.exit(1) 763b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen #print "sys.stderr:", sys.stderr 764b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen #print "sys.stdout:", sys.stdout 765b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen 766af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen 7679707bb6e50715489119bd756f208d3e9b7072848Johnny Chendef setupSysPath(): 7688a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen """ 7698a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen Add LLDB.framework/Resources/Python to the search paths for modules. 7708a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen As a side effect, we also discover the 'lldb' executable and export it here. 7718a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen """ 7729707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 773548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen global rdir 774548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen global testdirs 77550bc638c63c838adf8f7ddf28430bba5cb136c50Johnny Chen global dumpSysPath 776fe5f1ed2d4ca6cc0039c1069980c998330c4027cJohnny Chen global noHeaders 777b5fe80c62f0de8b855e0ee4bf25d3325f52e1984Johnny Chen global svn_info 778814c8135ab879d07ebbe69cc099c7181fe2b107cEnrico Granata global svn_silent 7790acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan global lldbFrameworkPath 7800acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan global lldbExecutablePath 781548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen 7829707bb6e50715489119bd756f208d3e9b7072848Johnny Chen # Get the directory containing the current script. 7834d162e5e8ac747827bce78a39af863f945611fefJohnny Chen if ("DOTEST_PROFILE" in os.environ or "DOTEST_PDB" in os.environ) and "DOTEST_SCRIPT_DIR" in os.environ: 7840de6ab53db8a87e6010a6cfcc18647b3bad6fbb6Johnny Chen scriptPath = os.environ["DOTEST_SCRIPT_DIR"] 7850de6ab53db8a87e6010a6cfcc18647b3bad6fbb6Johnny Chen else: 7860de6ab53db8a87e6010a6cfcc18647b3bad6fbb6Johnny Chen scriptPath = sys.path[0] 787a1affab962b9f57b64d798ea7fa93dc71d4cc0b1Johnny Chen if not scriptPath.endswith('test'): 7889707bb6e50715489119bd756f208d3e9b7072848Johnny Chen print "This script expects to reside in lldb's test directory." 7899707bb6e50715489119bd756f208d3e9b7072848Johnny Chen sys.exit(-1) 7909707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 791548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen if rdir: 792548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # Set up the LLDB_TEST environment variable appropriately, so that the 793548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # individual tests can be located relatively. 794548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # 795548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen # See also lldbtest.TestBase.setUpClass(cls). 796548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen if len(testdirs) == 1 and os.path.basename(testdirs[0]) == 'test': 797548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen os.environ["LLDB_TEST"] = os.path.join(rdir, 'test') 798548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen else: 799548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen os.environ["LLDB_TEST"] = rdir 800548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen else: 801548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen os.environ["LLDB_TEST"] = scriptPath 802f6c3de8ff0f3ecd3b5739bfa7c732a3b152e48c7Peter Collingbourne 803f6c3de8ff0f3ecd3b5739bfa7c732a3b152e48c7Peter Collingbourne # Set up the LLDB_SRC environment variable, so that the tests can locate 804f6c3de8ff0f3ecd3b5739bfa7c732a3b152e48c7Peter Collingbourne # the LLDB source code. 805f6c3de8ff0f3ecd3b5739bfa7c732a3b152e48c7Peter Collingbourne os.environ["LLDB_SRC"] = os.path.join(sys.path[0], os.pardir) 806f6c3de8ff0f3ecd3b5739bfa7c732a3b152e48c7Peter Collingbourne 8079de4edee4cb4371813d0281f662a7cf1468cee66Johnny Chen pluginPath = os.path.join(scriptPath, 'plugins') 8088a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen pexpectPath = os.path.join(scriptPath, 'pexpect-2.4') 80958f9392cf71468cefaeeda34324cdef38f66f1dcJohnny Chen 8108a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen # Append script dir, plugin dir, and pexpect dir to the sys.path. 811af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen sys.path.append(scriptPath) 812af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen sys.path.append(pluginPath) 8138a3c0430323c28c1fbe8ceecd2cd8e58b64a9295Johnny Chen sys.path.append(pexpectPath) 814c056664431d0126f3fb7a57844eee54455807781Filipe Cabecinhas 81526901c8c615beb9f2942bae337d927ff38535687Johnny Chen # This is our base name component. 816a1affab962b9f57b64d798ea7fa93dc71d4cc0b1Johnny Chen base = os.path.abspath(os.path.join(scriptPath, os.pardir)) 8176a564a4732c69c5402e3d25305cdcad551a1a429Johnny Chen 81826901c8c615beb9f2942bae337d927ff38535687Johnny Chen # These are for xcode build directories. 8196a564a4732c69c5402e3d25305cdcad551a1a429Johnny Chen xcode3_build_dir = ['build'] 8206a564a4732c69c5402e3d25305cdcad551a1a429Johnny Chen xcode4_build_dir = ['build', 'lldb', 'Build', 'Products'] 8216a564a4732c69c5402e3d25305cdcad551a1a429Johnny Chen dbg = ['Debug'] 822d9d9463dc284de6cf848e758f9c2a23f3bc3c910Sean Callanan dbc = ['DebugClang'] 8236a564a4732c69c5402e3d25305cdcad551a1a429Johnny Chen rel = ['Release'] 8246a564a4732c69c5402e3d25305cdcad551a1a429Johnny Chen bai = ['BuildAndIntegration'] 8256a564a4732c69c5402e3d25305cdcad551a1a429Johnny Chen python_resource_dir = ['LLDB.framework', 'Resources', 'Python'] 82626901c8c615beb9f2942bae337d927ff38535687Johnny Chen 82726901c8c615beb9f2942bae337d927ff38535687Johnny Chen # Some of the tests can invoke the 'lldb' command directly. 82826901c8c615beb9f2942bae337d927ff38535687Johnny Chen # We'll try to locate the appropriate executable right here. 82926901c8c615beb9f2942bae337d927ff38535687Johnny Chen 8300acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbExec = None 8310acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if lldbExecutablePath: 8320acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if is_exe(lldbExecutablePath): 8330acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbExec = lldbExecutablePath 834502000d088c505fee743213c7262a9442ae0d705Sean Callanan lldbHere = lldbExec 8350acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan else: 8360acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan print lldbExecutablePath + " is not an executable" 8370acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan sys.exit(-1) 8386033bedc163bc57b5e5c3c1aee8ba81f64b4f11eJohnny Chen else: 8390acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan # First, you can define an environment variable LLDB_EXEC specifying the 8400acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan # full pathname of the lldb executable. 8410acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if "LLDB_EXEC" in os.environ and is_exe(os.environ["LLDB_EXEC"]): 8420acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbExec = os.environ["LLDB_EXEC"] 8430acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan else: 8440acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbExec = None 8450acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan 8460acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan executable = ['lldb'] 8470acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan dbgExec = os.path.join(base, *(xcode3_build_dir + dbg + executable)) 8480acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan dbgExec2 = os.path.join(base, *(xcode4_build_dir + dbg + executable)) 8490acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan dbcExec = os.path.join(base, *(xcode3_build_dir + dbc + executable)) 8500acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan dbcExec2 = os.path.join(base, *(xcode4_build_dir + dbc + executable)) 8510acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan relExec = os.path.join(base, *(xcode3_build_dir + rel + executable)) 8520acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan relExec2 = os.path.join(base, *(xcode4_build_dir + rel + executable)) 8530acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan baiExec = os.path.join(base, *(xcode3_build_dir + bai + executable)) 8540acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan baiExec2 = os.path.join(base, *(xcode4_build_dir + bai + executable)) 8550acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan 8560acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan # The 'lldb' executable built here in the source tree. 8570acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbHere = None 8580acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if is_exe(dbgExec): 8590acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbHere = dbgExec 8600acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan elif is_exe(dbgExec2): 8610acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbHere = dbgExec2 8620acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan elif is_exe(dbcExec): 8630acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbHere = dbcExec 8640acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan elif is_exe(dbcExec2): 8650acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbHere = dbcExec2 8660acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan elif is_exe(relExec): 8670acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbHere = relExec 8680acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan elif is_exe(relExec2): 8690acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbHere = relExec2 8700acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan elif is_exe(baiExec): 8710acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbHere = baiExec 8720acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan elif is_exe(baiExec2): 8730acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbHere = baiExec2 8740acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan elif lldbExec: 8750acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbHere = lldbExec 876502000d088c505fee743213c7262a9442ae0d705Sean Callanan 8770acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan # One last chance to locate the 'lldb' executable. 8780acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if not lldbExec: 8790acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbExec = which('lldb') 8800acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if lldbHere and not lldbExec: 8810acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbExec = lldbHere 8822777b0100ad0c47054e9cd610d321121d8ddae86Daniel Malea if lldbExec and not lldbHere: 8832777b0100ad0c47054e9cd610d321121d8ddae86Daniel Malea lldbHere = lldbExec 884502000d088c505fee743213c7262a9442ae0d705Sean Callanan 885502000d088c505fee743213c7262a9442ae0d705Sean Callanan if lldbHere: 886502000d088c505fee743213c7262a9442ae0d705Sean Callanan os.environ["LLDB_HERE"] = lldbHere 887a964b09dd5fdcd00890cf65df6bf1aa931f1d11dMatt Kopec os.environ["LLDB_LIB_DIR"] = os.path.split(lldbHere)[0] 888502000d088c505fee743213c7262a9442ae0d705Sean Callanan if not noHeaders: 889a964b09dd5fdcd00890cf65df6bf1aa931f1d11dMatt Kopec print "LLDB library dir:", os.environ["LLDB_LIB_DIR"] 890502000d088c505fee743213c7262a9442ae0d705Sean Callanan os.system('%s -v' % lldbHere) 89126901c8c615beb9f2942bae337d927ff38535687Johnny Chen 89226901c8c615beb9f2942bae337d927ff38535687Johnny Chen if not lldbExec: 89326901c8c615beb9f2942bae337d927ff38535687Johnny Chen print "The 'lldb' executable cannot be located. Some of the tests may not be run as a result." 89426901c8c615beb9f2942bae337d927ff38535687Johnny Chen else: 89526901c8c615beb9f2942bae337d927ff38535687Johnny Chen os.environ["LLDB_EXEC"] = lldbExec 8968904eb0c783751cbba9bbda19c30156789b9f6ebJohnny Chen #print "The 'lldb' from PATH env variable", lldbExec 897c056664431d0126f3fb7a57844eee54455807781Filipe Cabecinhas 8982b606ab2881c4d09d2fa66f088b00c9d7de46964Daniel Malea # Skip printing svn/git information when running in parsable (lit-test compatibility) mode 899814c8135ab879d07ebbe69cc099c7181fe2b107cEnrico Granata if not svn_silent and not parsable: 9002b606ab2881c4d09d2fa66f088b00c9d7de46964Daniel Malea if os.path.isdir(os.path.join(base, '.svn')) and which("svn") is not None: 9012b606ab2881c4d09d2fa66f088b00c9d7de46964Daniel Malea pipe = subprocess.Popen([which("svn"), "info", base], stdout = subprocess.PIPE) 9022b606ab2881c4d09d2fa66f088b00c9d7de46964Daniel Malea svn_info = pipe.stdout.read() 9032b606ab2881c4d09d2fa66f088b00c9d7de46964Daniel Malea elif os.path.isdir(os.path.join(base, '.git')) and which("git") is not None: 9042b606ab2881c4d09d2fa66f088b00c9d7de46964Daniel Malea pipe = subprocess.Popen([which("git"), "svn", "info", base], stdout = subprocess.PIPE) 9052b606ab2881c4d09d2fa66f088b00c9d7de46964Daniel Malea svn_info = pipe.stdout.read() 9062b606ab2881c4d09d2fa66f088b00c9d7de46964Daniel Malea if not noHeaders: 9072b606ab2881c4d09d2fa66f088b00c9d7de46964Daniel Malea print svn_info 90826901c8c615beb9f2942bae337d927ff38535687Johnny Chen 90926901c8c615beb9f2942bae337d927ff38535687Johnny Chen global ignore 91026901c8c615beb9f2942bae337d927ff38535687Johnny Chen 9119707bb6e50715489119bd756f208d3e9b7072848Johnny Chen lldbPath = None 9120acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if lldbFrameworkPath: 9130acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan candidatePath = os.path.join(lldbFrameworkPath, 'Resources', 'Python') 9140acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if os.path.isfile(os.path.join(candidatePath, 'lldb/__init__.py')): 9150acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan lldbPath = candidatePath 9160acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if not lldbPath: 9170acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan print 'Resources/Python/lldb/__init__.py was not found in ' + lldbFrameworkPath 9180acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan sys.exit(-1) 9190acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan else: 9200acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan # The '-i' option is used to skip looking for lldb.py in the build tree. 9210acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if ignore: 9220acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan return 923aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham 924aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham # If our lldb supports the -P option, use it to find the python path: 925aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham init_in_python_dir = 'lldb/__init__.py' 926aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham import pexpect 927aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldb_dash_p_result = None 928aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham 929aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham if lldbHere: 930aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldb_dash_p_result = pexpect.run("%s -P"%(lldbHere)) 931aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham elif lldbExec: 932aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldb_dash_p_result = pexpect.run("%s -P"%(lldbExec)) 933aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham 934aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham if lldb_dash_p_result and not lldb_dash_p_result.startswith(("<", "lldb: invalid option:")): 935aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lines = lldb_dash_p_result.splitlines() 936aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham if len(lines) == 1 and os.path.isfile(os.path.join(lines[0], init_in_python_dir)): 937aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldbPath = lines[0] 93821e32a6354ca6a318332e5e0b32d04c984a4708aDaniel Malea if "linux" in sys.platform: 939a964b09dd5fdcd00890cf65df6bf1aa931f1d11dMatt Kopec os.environ['LLDB_LIB_DIR'] = os.path.join(lldbPath, '..', '..') 940aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham 941aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham if not lldbPath: 942aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham dbgPath = os.path.join(base, *(xcode3_build_dir + dbg + python_resource_dir)) 943aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham dbgPath2 = os.path.join(base, *(xcode4_build_dir + dbg + python_resource_dir)) 944aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham dbcPath = os.path.join(base, *(xcode3_build_dir + dbc + python_resource_dir)) 945aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham dbcPath2 = os.path.join(base, *(xcode4_build_dir + dbc + python_resource_dir)) 946aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham relPath = os.path.join(base, *(xcode3_build_dir + rel + python_resource_dir)) 947aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham relPath2 = os.path.join(base, *(xcode4_build_dir + rel + python_resource_dir)) 948aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham baiPath = os.path.join(base, *(xcode3_build_dir + bai + python_resource_dir)) 949aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham baiPath2 = os.path.join(base, *(xcode4_build_dir + bai + python_resource_dir)) 9500acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan 951aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham if os.path.isfile(os.path.join(dbgPath, init_in_python_dir)): 952aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldbPath = dbgPath 953aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham elif os.path.isfile(os.path.join(dbgPath2, init_in_python_dir)): 954aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldbPath = dbgPath2 955aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham elif os.path.isfile(os.path.join(dbcPath, init_in_python_dir)): 956aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldbPath = dbcPath 957aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham elif os.path.isfile(os.path.join(dbcPath2, init_in_python_dir)): 958aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldbPath = dbcPath2 959aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham elif os.path.isfile(os.path.join(relPath, init_in_python_dir)): 960aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldbPath = relPath 961aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham elif os.path.isfile(os.path.join(relPath2, init_in_python_dir)): 962aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldbPath = relPath2 963aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham elif os.path.isfile(os.path.join(baiPath, init_in_python_dir)): 964aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldbPath = baiPath 965aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham elif os.path.isfile(os.path.join(baiPath2, init_in_python_dir)): 966aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldbPath = baiPath2 967aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham 9680acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan if not lldbPath: 9690acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan print 'This script requires lldb.py to be in either ' + dbgPath + ',', 9700acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan print relPath + ', or ' + baiPath 9710acf4c6de1540f316e0c2b1bae02a943dba655deSean Callanan sys.exit(-1) 9729707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 973aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham # Some of the code that uses this path assumes it hasn't resolved the Versions... link. 974aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham # If the path we've constructed looks like that, then we'll strip out the Versions/A part. 975aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham (before, frameWithVersion, after) = lldbPath.rpartition("LLDB.framework/Versions/A") 976aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham if frameWithVersion != "" : 977aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham lldbPath = before + "LLDB.framework" + after 978aa93c931a4c1275b2fecec23ef34f231afda4773Jim Ingham 9790ad929750b530c29de320bf188ec007b5cf5a12eEnrico Granata lldbPath = os.path.abspath(lldbPath) 9800ad929750b530c29de320bf188ec007b5cf5a12eEnrico Granata 98101458ca40d79e33ee440e5d48dfdd92503f77dfeEnrico Granata # If tests need to find LLDB_FRAMEWORK, now they can do it 98201458ca40d79e33ee440e5d48dfdd92503f77dfeEnrico Granata os.environ["LLDB_FRAMEWORK"] = os.path.dirname(os.path.dirname(lldbPath)) 98301458ca40d79e33ee440e5d48dfdd92503f77dfeEnrico Granata 984af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen # This is to locate the lldb.py module. Insert it right after sys.path[0]. 985af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen sys.path[1:1] = [lldbPath] 98650bc638c63c838adf8f7ddf28430bba5cb136c50Johnny Chen if dumpSysPath: 98750bc638c63c838adf8f7ddf28430bba5cb136c50Johnny Chen print "sys.path:", sys.path 9889707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 9899707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 990cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chendef doDelay(delta): 991cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen """Delaying startup for delta-seconds to facilitate debugger attachment.""" 992cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen def alarm_handler(*args): 993cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen raise Exception("timeout") 994cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen 995cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen signal.signal(signal.SIGALRM, alarm_handler) 996cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen signal.alarm(delta) 997cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen sys.stdout.write("pid=%d\n" % os.getpid()) 998cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen sys.stdout.write("Enter RET to proceed (or timeout after %d seconds):" % 999cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen delta) 1000cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen sys.stdout.flush() 1001cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen try: 1002cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen text = sys.stdin.readline() 1003cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen except: 1004cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen text = "" 1005cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen signal.alarm(0) 1006cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen sys.stdout.write("proceeding...\n") 1007cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen pass 1008cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen 1009cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen 10109707bb6e50715489119bd756f208d3e9b7072848Johnny Chendef visit(prefix, dir, names): 10119707bb6e50715489119bd756f208d3e9b7072848Johnny Chen """Visitor function for os.path.walk(path, visit, arg).""" 10129707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 10139707bb6e50715489119bd756f208d3e9b7072848Johnny Chen global suite 10147c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen global regexp 1015c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chen global filters 1016b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen global fs4all 1017e9eae8142a492bb17af559eed5ad1a5e382c3905Johnny Chen global excluded 1018e9eae8142a492bb17af559eed5ad1a5e382c3905Johnny Chen 1019e9eae8142a492bb17af559eed5ad1a5e382c3905Johnny Chen if set(dir.split(os.sep)).intersection(excluded): 1020e9eae8142a492bb17af559eed5ad1a5e382c3905Johnny Chen #print "Detected an excluded dir component: %s" % dir 1021e9eae8142a492bb17af559eed5ad1a5e382c3905Johnny Chen return 10229707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 10239707bb6e50715489119bd756f208d3e9b7072848Johnny Chen for name in names: 10249707bb6e50715489119bd756f208d3e9b7072848Johnny Chen if os.path.isdir(os.path.join(dir, name)): 10259707bb6e50715489119bd756f208d3e9b7072848Johnny Chen continue 10269707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 10279707bb6e50715489119bd756f208d3e9b7072848Johnny Chen if '.py' == os.path.splitext(name)[1] and name.startswith(prefix): 10287c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen # Try to match the regexp pattern, if specified. 10297c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen if regexp: 10307c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen import re 10317c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen if re.search(regexp, name): 10327c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen #print "Filename: '%s' matches pattern: '%s'" % (name, regexp) 10337c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen pass 10347c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen else: 10357c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen #print "Filename: '%s' does not match pattern: '%s'" % (name, regexp) 10367c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen continue 10377c52ff1d83ec262f35c9a825af107735913e7225Johnny Chen 1038953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # We found a match for our test. Add it to the suite. 103979723356800fbab9bf7c7727ef5dfcbf53c3931eJohnny Chen 104079723356800fbab9bf7c7727ef5dfcbf53c3931eJohnny Chen # Update the sys.path first. 1041a85d7eefef64b72eec99a91524dc3942d9683705Johnny Chen if not sys.path.count(dir): 1042548aefd19076bf9205c75cb19b0c54544c2b967bJohnny Chen sys.path.insert(0, dir) 10439707bb6e50715489119bd756f208d3e9b7072848Johnny Chen base = os.path.splitext(name)[0] 1044b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen 1045b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen # Thoroughly check the filterspec against the base module and admit 1046b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen # the (base, filterspec) combination only when it makes sense. 1047c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chen filterspec = None 1048c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chen for filterspec in filters: 1049b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen # Optimistically set the flag to True. 1050b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen filtered = True 1051b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen module = __import__(base) 1052b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen parts = filterspec.split('.') 1053b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen obj = module 1054b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen for part in parts: 1055b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen try: 1056b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen parent, obj = obj, getattr(obj, part) 1057b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen except AttributeError: 1058b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen # The filterspec has failed. 1059b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen filtered = False 1060b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen break 1061c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chen 1062db4be60f02e9bc2af7f3a6f32f612e73856f21eeJohnny Chen # If filtered, we have a good filterspec. Add it. 1063c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chen if filtered: 1064db4be60f02e9bc2af7f3a6f32f612e73856f21eeJohnny Chen #print "adding filter spec %s to module %s" % (filterspec, module) 1065db4be60f02e9bc2af7f3a6f32f612e73856f21eeJohnny Chen suite.addTests( 1066db4be60f02e9bc2af7f3a6f32f612e73856f21eeJohnny Chen unittest2.defaultTestLoader.loadTestsFromName(filterspec, module)) 1067db4be60f02e9bc2af7f3a6f32f612e73856f21eeJohnny Chen continue 1068c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chen 1069c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chen # Forgo this module if the (base, filterspec) combo is invalid 1070c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chen # and no '-g' option is specified 1071c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chen if filters and fs4all and not filtered: 1072c5fa005707f9378e03328fb0ee492b8a6c230057Johnny Chen continue 1073c056664431d0126f3fb7a57844eee54455807781Filipe Cabecinhas 1074db4be60f02e9bc2af7f3a6f32f612e73856f21eeJohnny Chen # Add either the filtered test case(s) (which is done before) or the entire test class. 1075db4be60f02e9bc2af7f3a6f32f612e73856f21eeJohnny Chen if not filterspec or not filtered: 1076b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen # A simple case of just the module name. Also the failover case 1077b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen # from the filterspec branch when the (base, filterspec) combo 1078b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen # doesn't make sense. 1079b62436b4682bb67397213a2cdd0e11f81f5bed49Johnny Chen suite.addTests(unittest2.defaultTestLoader.loadTestsFromName(base)) 10809707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 10819707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 1082cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chendef lldbLoggings(): 1083cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen """Check and do lldb loggings if necessary.""" 1084cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen 1085cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen # Turn on logging for debugging purposes if ${LLDB_LOG} environment variable is 1086cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen # defined. Use ${LLDB_LOG} to specify the log file. 1087cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen ci = lldb.DBG.GetCommandInterpreter() 1088cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen res = lldb.SBCommandReturnObject() 1089cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen if ("LLDB_LOG" in os.environ): 1090cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen if ("LLDB_LOG_OPTION" in os.environ): 1091cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen lldb_log_option = os.environ["LLDB_LOG_OPTION"] 1092cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen else: 10938fd886cc389b95fa15d9f8da3b49ef9a0351c313Johnny Chen lldb_log_option = "event process expr state api" 1094cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen ci.HandleCommand( 1095940b103224f3062578c7a7e6e76d8bf4a7956f2aGreg Clayton "log enable -n -f " + os.environ["LLDB_LOG"] + " lldb " + lldb_log_option, 1096cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen res) 1097cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen if not res.Succeeded(): 1098cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen raise Exception('log enable failed (check LLDB_LOG env variable.') 1099cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen # Ditto for gdb-remote logging if ${GDB_REMOTE_LOG} environment variable is defined. 1100cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen # Use ${GDB_REMOTE_LOG} to specify the log file. 1101cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen if ("GDB_REMOTE_LOG" in os.environ): 1102cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen if ("GDB_REMOTE_LOG_OPTION" in os.environ): 1103cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen gdb_remote_log_option = os.environ["GDB_REMOTE_LOG_OPTION"] 1104cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen else: 11057ab8c85f52db89ea952587ef689f112fe671b619Johnny Chen gdb_remote_log_option = "packets process" 1106cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen ci.HandleCommand( 1107c935a89a5ea2199cdaaf557c4f913a78e25c2797Johnny Chen "log enable -n -f " + os.environ["GDB_REMOTE_LOG"] + " gdb-remote " 1108cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen + gdb_remote_log_option, 1109cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen res) 1110cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen if not res.Succeeded(): 1111cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen raise Exception('log enable failed (check GDB_REMOTE_LOG env variable.') 1112cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen 1113067022b780badba447f1e6991069fb8288df0520Johnny Chendef getMyCommandLine(): 1114782e474a0fad1f1c2864e6b709b9ceb12aa50967Daniel Malea ps = subprocess.Popen([which('ps'), '-o', "command=CMD", str(os.getpid())], stdout=subprocess.PIPE).communicate()[0] 1115067022b780badba447f1e6991069fb8288df0520Johnny Chen lines = ps.split('\n') 1116067022b780badba447f1e6991069fb8288df0520Johnny Chen cmd_line = lines[1] 1117067022b780badba447f1e6991069fb8288df0520Johnny Chen return cmd_line 1118cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen 1119d96b568e6e43bb028e5bf20cd6a81b33db0d6f3cJohnny Chen# ======================================== # 1120cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen# # 1121cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen# Execution of the test driver starts here # 1122cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen# # 1123d96b568e6e43bb028e5bf20cd6a81b33db0d6f3cJohnny Chen# ======================================== # 1124cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen 11252891bb03e1ceafe4f894d7edb01f15b8ba890d27Johnny Chendef checkDsymForUUIDIsNotOn(): 11266a4e087699713b51ef94a2c6322842f30474a526Johnny Chen cmd = ["defaults", "read", "com.apple.DebugSymbols"] 11276a4e087699713b51ef94a2c6322842f30474a526Johnny Chen pipe = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) 11286a4e087699713b51ef94a2c6322842f30474a526Johnny Chen cmd_output = pipe.stdout.read() 1129178c8d99c2fe0fc4b10368329a83b0da44c8a725Johnny Chen if cmd_output and "DBGFileMappedPaths = " in cmd_output: 11306a451485d71f890635a32930d09c7296e665bcbdJohnny Chen print "%s =>" % ' '.join(cmd) 11316a4e087699713b51ef94a2c6322842f30474a526Johnny Chen print cmd_output 11322891bb03e1ceafe4f894d7edb01f15b8ba890d27Johnny Chen print "Disable automatic lookup and caching of dSYMs before running the test suite!" 11332891bb03e1ceafe4f894d7edb01f15b8ba890d27Johnny Chen print "Exiting..." 11342891bb03e1ceafe4f894d7edb01f15b8ba890d27Johnny Chen sys.exit(0) 11352891bb03e1ceafe4f894d7edb01f15b8ba890d27Johnny Chen 11362891bb03e1ceafe4f894d7edb01f15b8ba890d27Johnny Chen# On MacOS X, check to make sure that domain for com.apple.DebugSymbols defaults 11372891bb03e1ceafe4f894d7edb01f15b8ba890d27Johnny Chen# does not exist before proceeding to running the test suite. 11382891bb03e1ceafe4f894d7edb01f15b8ba890d27Johnny Chenif sys.platform.startswith("darwin"): 11392891bb03e1ceafe4f894d7edb01f15b8ba890d27Johnny Chen checkDsymForUUIDIsNotOn() 11402891bb03e1ceafe4f894d7edb01f15b8ba890d27Johnny Chen 11419707bb6e50715489119bd756f208d3e9b7072848Johnny Chen# 1142af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen# Start the actions by first parsing the options while setting up the test 1143af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen# directories, followed by setting up the search paths for lldb utilities; 1144af149a01d06804575de17ceb9c4a4827bbae7046Johnny Chen# then, we walk the directory trees and collect the tests into our test suite. 11459707bb6e50715489119bd756f208d3e9b7072848Johnny Chen# 1146af149a01d06804575de17ceb9c4a4827bbae7046Johnny ChenparseOptionsAndInitTestdirs() 11479707bb6e50715489119bd756f208d3e9b7072848Johnny ChensetupSysPath() 114891960d3b4f1c8ccbc7b2087bc82fe2cc24b45f5aJohnny Chen 114991960d3b4f1c8ccbc7b2087bc82fe2cc24b45f5aJohnny Chen# 115091960d3b4f1c8ccbc7b2087bc82fe2cc24b45f5aJohnny Chen# If '-d' is specified, do a delay of 10 seconds for the debugger to attach. 115191960d3b4f1c8ccbc7b2087bc82fe2cc24b45f5aJohnny Chen# 115291960d3b4f1c8ccbc7b2087bc82fe2cc24b45f5aJohnny Chenif delay: 1153cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen doDelay(10) 115491960d3b4f1c8ccbc7b2087bc82fe2cc24b45f5aJohnny Chen 115549f2f7a02b97be46f2cfbb1236b0645ede3d9ec0Johnny Chen# 115641998197e9d81cba31ac4645c1ec5f0ba7ca1668Johnny Chen# If '-l' is specified, do not skip the long running tests. 1157028d8ebd7e97d46e3de13fd977f8a17d6bf246f5Johnny Chenif not skip_long_running_test: 115841998197e9d81cba31ac4645c1ec5f0ba7ca1668Johnny Chen os.environ["LLDB_SKIP_LONG_RUNNING_TEST"] = "NO" 115941998197e9d81cba31ac4645c1ec5f0ba7ca1668Johnny Chen 116041998197e9d81cba31ac4645c1ec5f0ba7ca1668Johnny Chen# 116179723356800fbab9bf7c7727ef5dfcbf53c3931eJohnny Chen# Walk through the testdirs while collecting tests. 116249f2f7a02b97be46f2cfbb1236b0645ede3d9ec0Johnny Chen# 11639707bb6e50715489119bd756f208d3e9b7072848Johnny Chenfor testdir in testdirs: 11649707bb6e50715489119bd756f208d3e9b7072848Johnny Chen os.path.walk(testdir, visit, 'Test') 11659707bb6e50715489119bd756f208d3e9b7072848Johnny Chen 1166b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen# 11679707bb6e50715489119bd756f208d3e9b7072848Johnny Chen# Now that we have loaded all the test cases, run the whole test suite. 1168b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen# 1169cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen 11701bfbd41ff54438ab23c55637efb37d6a1db0b977Johnny Chen# For the time being, let's bracket the test runner within the 11711bfbd41ff54438ab23c55637efb37d6a1db0b977Johnny Chen# lldb.SBDebugger.Initialize()/Terminate() pair. 117201f2a6a3cea331ed92178bf5bc990022e872e93dJohnny Chenimport lldb, atexit 11736b6f5badb95266c1e22e9581eec3859109376c76Johnny Chen# Update: the act of importing lldb now executes lldb.SBDebugger.Initialize(), 11746b6f5badb95266c1e22e9581eec3859109376c76Johnny Chen# there's no need to call it a second time. 11756b6f5badb95266c1e22e9581eec3859109376c76Johnny Chen#lldb.SBDebugger.Initialize() 117601f2a6a3cea331ed92178bf5bc990022e872e93dJohnny Chenatexit.register(lambda: lldb.SBDebugger.Terminate()) 11771bfbd41ff54438ab23c55637efb37d6a1db0b977Johnny Chen 1178909e5a62b93f6b0462996d35390665339d442f8bJohnny Chen# Create a singleton SBDebugger in the lldb namespace. 1179909e5a62b93f6b0462996d35390665339d442f8bJohnny Chenlldb.DBG = lldb.SBDebugger.Create() 1180909e5a62b93f6b0462996d35390665339d442f8bJohnny Chen 11814f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chen# Put the blacklist in the lldb namespace, to be used by lldb.TestBase. 118282e6b1ef7cdb39c0d0c93142b195969b2dee63f0Johnny Chenlldb.blacklist = blacklist 118382e6b1ef7cdb39c0d0c93142b195969b2dee63f0Johnny Chen 1184ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen# The pre_flight and post_flight come from reading a config file. 1185ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chenlldb.pre_flight = pre_flight 1186ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chenlldb.post_flight = post_flight 1187ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chendef getsource_if_available(obj): 1188ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen """ 1189ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen Return the text of the source code for an object if available. Otherwise, 1190ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen a print representation is returned. 1191ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen """ 1192ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen import inspect 1193ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen try: 1194ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen return inspect.getsource(obj) 1195ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen except: 1196ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen return repr(obj) 1197ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen 1198361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Maleaif not noHeaders: 1199361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea print "lldb.pre_flight:", getsource_if_available(lldb.pre_flight) 1200361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea print "lldb.post_flight:", getsource_if_available(lldb.post_flight) 1201ac97a6bc2910f3e0cbb9958102f0eda04e7894c4Johnny Chen 1202a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chen# Put all these test decorators in the lldb namespace. 12034f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chenlldb.dont_do_python_api_test = dont_do_python_api_test 12044f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chenlldb.just_do_python_api_test = just_do_python_api_test 120582ccf4033d09dc7002637ddc70a3ffcc518a58c9Johnny Chenlldb.just_do_benchmarks_test = just_do_benchmarks_test 1206a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chenlldb.dont_do_dsym_test = dont_do_dsym_test 1207a3ed7d834b0e0c6924ac95629e740682bbcd15baJohnny Chenlldb.dont_do_dwarf_test = dont_do_dwarf_test 12084f93bf1b34e9828ff630eddb908adfb04e05aadfJohnny Chen 1209028d8ebd7e97d46e3de13fd977f8a17d6bf246f5Johnny Chen# Do we need to skip build and cleanup? 1210028d8ebd7e97d46e3de13fd977f8a17d6bf246f5Johnny Chenlldb.skip_build_and_cleanup = skip_build_and_cleanup 1211028d8ebd7e97d46e3de13fd977f8a17d6bf246f5Johnny Chen 12125f2ed17114c1711a23011c160832b318d77db888Johnny Chen# Put bmExecutable, bmBreakpointSpec, and bmIterationCount into the lldb namespace, too. 1213e00c9303c148e3ad4d1e511a27f3104cdd404e07Johnny Chenlldb.bmExecutable = bmExecutable 1214e00c9303c148e3ad4d1e511a27f3104cdd404e07Johnny Chenlldb.bmBreakpointSpec = bmBreakpointSpec 12155f2ed17114c1711a23011c160832b318d77db888Johnny Chenlldb.bmIterationCount = bmIterationCount 1216e00c9303c148e3ad4d1e511a27f3104cdd404e07Johnny Chen 121738f823c14468f8dec5a0568828ab22989240179dJohnny Chen# And don't forget the runHooks! 121838f823c14468f8dec5a0568828ab22989240179dJohnny Chenlldb.runHooks = runHooks 121938f823c14468f8dec5a0568828ab22989240179dJohnny Chen 1220cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen# Turn on lldb loggings if necessary. 1221cd0279daf515ee3d4d6727140987a1554803ea50Johnny ChenlldbLoggings() 1222909e5a62b93f6b0462996d35390665339d442f8bJohnny Chen 12237987ac9e8b880c5a172afe280a72d2dcb4b77830Johnny Chen# Install the control-c handler. 12247987ac9e8b880c5a172afe280a72d2dcb4b77830Johnny Chenunittest2.signals.installHandler() 12257987ac9e8b880c5a172afe280a72d2dcb4b77830Johnny Chen 1226125fc2b1ea49af439e86bbf8f32fce8bbd5a7cddJohnny Chen# If sdir_name is not specified through the '-s sdir_name' option, get a 1227125fc2b1ea49af439e86bbf8f32fce8bbd5a7cddJohnny Chen# timestamp string and export it as LLDB_SESSION_DIR environment var. This will 1228125fc2b1ea49af439e86bbf8f32fce8bbd5a7cddJohnny Chen# be used when/if we want to dump the session info of individual test cases 1229125fc2b1ea49af439e86bbf8f32fce8bbd5a7cddJohnny Chen# later on. 1230ce68146871cf9fe802f41a33102edbe39bd85fa1Johnny Chen# 1231ce68146871cf9fe802f41a33102edbe39bd85fa1Johnny Chen# See also TestBase.dumpSessionInfo() in lldbtest.py. 1232a73ad66a4ee96ccc8e6be4a645cd6b9180a72e4bJohnny Chenimport datetime 1233a73ad66a4ee96ccc8e6be4a645cd6b9180a72e4bJohnny Chen# The windows platforms don't like ':' in the pathname. 1234a73ad66a4ee96ccc8e6be4a645cd6b9180a72e4bJohnny Chentimestamp_started = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S") 1235125fc2b1ea49af439e86bbf8f32fce8bbd5a7cddJohnny Chenif not sdir_name: 1236a73ad66a4ee96ccc8e6be4a645cd6b9180a72e4bJohnny Chen sdir_name = timestamp_started 1237132476f353df957117d463aedb4d68db6c35677ePeter Collingbourneos.environ["LLDB_SESSION_DIRNAME"] = os.path.join(os.getcwd(), sdir_name) 1238067022b780badba447f1e6991069fb8288df0520Johnny Chen 1239fe5f1ed2d4ca6cc0039c1069980c998330c4027cJohnny Chenif not noHeaders: 1240fe5f1ed2d4ca6cc0039c1069980c998330c4027cJohnny Chen sys.stderr.write("\nSession logs for test failures/errors/unexpected successes" 1241fe5f1ed2d4ca6cc0039c1069980c998330c4027cJohnny Chen " will go into directory '%s'\n" % sdir_name) 1242fe5f1ed2d4ca6cc0039c1069980c998330c4027cJohnny Chen sys.stderr.write("Command invoked: %s\n" % getMyCommandLine()) 1243ce68146871cf9fe802f41a33102edbe39bd85fa1Johnny Chen 1244b5fe80c62f0de8b855e0ee4bf25d3325f52e1984Johnny Chenif not os.path.isdir(sdir_name): 1245b5fe80c62f0de8b855e0ee4bf25d3325f52e1984Johnny Chen os.mkdir(sdir_name) 1246571358f0358eca953916c4866db55c3f93d28820Enrico Granatawhere_to_save_session = os.getcwd() 1247a73ad66a4ee96ccc8e6be4a645cd6b9180a72e4bJohnny Chenfname = os.path.join(sdir_name, "TestStarted") 1248b5fe80c62f0de8b855e0ee4bf25d3325f52e1984Johnny Chenwith open(fname, "w") as f: 1249a73ad66a4ee96ccc8e6be4a645cd6b9180a72e4bJohnny Chen print >> f, "Test started at: %s\n" % timestamp_started 1250b5fe80c62f0de8b855e0ee4bf25d3325f52e1984Johnny Chen print >> f, svn_info 1251b5fe80c62f0de8b855e0ee4bf25d3325f52e1984Johnny Chen print >> f, "Command invoked: %s\n" % getMyCommandLine() 1252b5fe80c62f0de8b855e0ee4bf25d3325f52e1984Johnny Chen 1253b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen# 1254b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen# Invoke the default TextTestRunner to run the test suite, possibly iterating 1255b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen# over different configurations. 1256b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen# 1257b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen 1258b40056bb26656a2f23bc6a7668b64213176c20f2Johnny CheniterArchs = False 1259f032d90a4fb11c4b3ba129b05d720f445e2cf0baJohnny CheniterCompilers = False 1260b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen 12611a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chenif not archs and "archs" in config: 1262b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen archs = config["archs"] 12631a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen 12641a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chenif isinstance(archs, list) and len(archs) >= 1: 12651a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen iterArchs = True 12661a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen 12671a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chenif not compilers and "compilers" in config: 1268b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen compilers = config["compilers"] 12691a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen 127092693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen# 127192693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen# Add some intervention here to sanity check that the compilers requested are sane. 127292693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen# If found not to be an executable program, the invalid one is dropped from the list. 127392693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chenfor i in range(len(compilers)): 127492693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen c = compilers[i] 127592693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen if which(c): 127692693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen continue 127792693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen else: 127892693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen if sys.platform.startswith("darwin"): 127992693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen pipe = subprocess.Popen(['xcrun', '-find', c], stdout = subprocess.PIPE, stderr = subprocess.STDOUT) 128092693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen cmd_output = pipe.stdout.read() 128192693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen if cmd_output: 128292693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen if "not found" in cmd_output: 128392693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen print "dropping %s from the compilers used" % c 128492693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen compilers.remove(i) 128592693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen else: 128692693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen compilers[i] = cmd_output.split('\n')[0] 128792693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen print "'xcrun -find %s' returning %s" % (c, compilers[i]) 128892693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen 1289361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Maleaif not parsable: 1290361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea print "compilers=%s" % str(compilers) 129192693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen 129292693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chenif not compilers or len(compilers) == 0: 129392693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen print "No eligible compiler found, exiting." 129492693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen sys.exit(1) 129592693b50c3526f9666bf23e408c53d0456a2f9f0Johnny Chen 12961a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chenif isinstance(compilers, list) and len(compilers) >= 1: 12971a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen iterCompilers = True 1298b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen 1299953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen# Make a shallow copy of sys.path, we need to manipulate the search paths later. 1300953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen# This is only necessary if we are relocated and with different configurations. 13011a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chenif rdir: 1302953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen old_sys_path = sys.path[:] 13031a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen# If we iterate on archs or compilers, there is a chance we want to split stderr/stdout. 13041a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chenif iterArchs or iterCompilers: 1305953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen old_stderr = sys.stderr 1306953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen old_stdout = sys.stdout 1307953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen new_stderr = None 1308953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen new_stdout = None 1309953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen 1310d96b568e6e43bb028e5bf20cd6a81b33db0d6f3cJohnny Chen# Iterating over all possible architecture and compiler combinations. 1311b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chenfor ia in range(len(archs) if iterArchs else 1): 1312b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen archConfig = "" 1313b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen if iterArchs: 131418a921fbdc01dfa8caff65a7006f5b5ae31ab683Johnny Chen os.environ["ARCH"] = archs[ia] 1315b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen archConfig = "arch=%s" % archs[ia] 1316b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen for ic in range(len(compilers) if iterCompilers else 1): 1317b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen if iterCompilers: 131818a921fbdc01dfa8caff65a7006f5b5ae31ab683Johnny Chen os.environ["CC"] = compilers[ic] 1319b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen configString = "%s compiler=%s" % (archConfig, compilers[ic]) 1320b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen else: 1321b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen configString = archConfig 1322b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen 1323b40056bb26656a2f23bc6a7668b64213176c20f2Johnny Chen if iterArchs or iterCompilers: 13241a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen # Translate ' ' to '-' for pathname component. 13251a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen from string import maketrans 13261a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen tbl = maketrans(' ', '-') 13271a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen configPostfix = configString.translate(tbl) 13281a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen 13291a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen # Check whether we need to split stderr/stdout into configuration 13301a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen # specific files. 13311a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen if old_stderr.name != '<stderr>' and config.get('split_stderr'): 13321a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen if new_stderr: 13331a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen new_stderr.close() 13341a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen new_stderr = open("%s.%s" % (old_stderr.name, configPostfix), "w") 13351a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen sys.stderr = new_stderr 13361a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen if old_stdout.name != '<stdout>' and config.get('split_stdout'): 13371a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen if new_stdout: 13381a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen new_stdout.close() 13391a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen new_stdout = open("%s.%s" % (old_stdout.name, configPostfix), "w") 13401a4d5e7b6eb2283b4c7d8e308f4087f39cc05ed6Johnny Chen sys.stdout = new_stdout 1341c056664431d0126f3fb7a57844eee54455807781Filipe Cabecinhas 1342953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # If we specified a relocated directory to run the test suite, do 1343953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # the extra housekeeping to copy the testdirs to a configStringified 1344953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # directory and to update sys.path before invoking the test runner. 1345953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # The purpose is to separate the configuration-specific directories 1346953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # from each other. 1347953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen if rdir: 13483bc7e5e8960a8928b9811a10175627a397aa643dJohnny Chen from shutil import copytree, rmtree, ignore_patterns 1349953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen 1350953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen newrdir = "%s.%s" % (rdir, configPostfix) 1351953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen 1352953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # Copy the tree to a new directory with postfix name configPostfix. 13533bc7e5e8960a8928b9811a10175627a397aa643dJohnny Chen if os.path.exists(newrdir): 13543bc7e5e8960a8928b9811a10175627a397aa643dJohnny Chen rmtree(newrdir) 1355953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen copytree(rdir, newrdir, ignore=ignore_patterns('*.pyc', '*.o', '*.d')) 1356953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen 13570e1d06d55f7e8d8be1fc5da8ec46ee64dda40f19Filipe Cabecinhas # Update the LLDB_TEST environment variable to reflect new top 1358953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # level test directory. 1359953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # 1360953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # See also lldbtest.TestBase.setUpClass(cls). 1361953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen if len(testdirs) == 1 and os.path.basename(testdirs[0]) == 'test': 1362953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen os.environ["LLDB_TEST"] = os.path.join(newrdir, 'test') 1363953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen else: 1364953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen os.environ["LLDB_TEST"] = newrdir 1365953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen 1366953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # And update the Python search paths for modules. 1367953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen sys.path = [x.replace(rdir, newrdir, 1) for x in old_sys_path] 1368953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen 1369953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # Output the configuration. 1370361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea if not parsable: 1371361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea sys.stderr.write("\nConfiguration: " + configString + "\n") 1372953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen 1373953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen #print "sys.stderr name is", sys.stderr.name 1374953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen #print "sys.stdout name is", sys.stdout.name 1375953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen 1376953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen # First, write out the number of collected test cases. 1377361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea if not parsable: 1378361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea sys.stderr.write(separator + "\n") 1379361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea sys.stderr.write("Collected %d test%s\n\n" 1380361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea % (suite.countTestCases(), 1381361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea suite.countTestCases() != 1 and "s" or "")) 1382953864aaa9c9e7313ee5ac935891c8a7a6a22f12Johnny Chen 138384a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen class LLDBTestResult(unittest2.TextTestResult): 138484a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen """ 138526be4532bee7111b52ae4bba6628efed17cd23dbJohnny Chen Enforce a singleton pattern to allow introspection of test progress. 138626be4532bee7111b52ae4bba6628efed17cd23dbJohnny Chen 138726be4532bee7111b52ae4bba6628efed17cd23dbJohnny Chen Overwrite addError(), addFailure(), and addExpectedFailure() methods 138826be4532bee7111b52ae4bba6628efed17cd23dbJohnny Chen to enable each test instance to track its failure/error status. It 138926be4532bee7111b52ae4bba6628efed17cd23dbJohnny Chen is used in the LLDB test framework to emit detailed trace messages 139026be4532bee7111b52ae4bba6628efed17cd23dbJohnny Chen to a log file for easier human inspection of test failres/errors. 139184a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen """ 139284a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen __singleton__ = None 1393360dd372c413c82f651775320bfd4052c31eec00Johnny Chen __ignore_singleton__ = False 139484a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen 1395bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata @staticmethod 1396bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata def getTerminalSize(): 1397bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata import os 1398bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata env = os.environ 1399bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata def ioctl_GWINSZ(fd): 1400bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata try: 1401bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata import fcntl, termios, struct, os 1402bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, 1403bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata '1234')) 1404bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata except: 1405bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata return 1406bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata return cr 1407bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2) 1408bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata if not cr: 1409bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata try: 1410bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata fd = os.open(os.ctermid(), os.O_RDONLY) 1411bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata cr = ioctl_GWINSZ(fd) 1412bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata os.close(fd) 1413bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata except: 1414bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata pass 1415bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata if not cr: 1416bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata cr = (env.get('LINES', 25), env.get('COLUMNS', 80)) 1417bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata return int(cr[1]), int(cr[0]) 1418bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata 141984a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen def __init__(self, *args): 1420360dd372c413c82f651775320bfd4052c31eec00Johnny Chen if not LLDBTestResult.__ignore_singleton__ and LLDBTestResult.__singleton__: 1421d2acdb38ed0f756e8dd846e65fa149bd49a872c3Johnny Chen raise Exception("LLDBTestResult instantiated more than once") 142284a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen super(LLDBTestResult, self).__init__(*args) 142384a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen LLDBTestResult.__singleton__ = self 142484a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen # Now put this singleton into the lldb module namespace. 142584a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen lldb.test_result = self 1426810042efba4eb9b02e5de1529ebfc01ed821cca5Johnny Chen # Computes the format string for displaying the counter. 1427810042efba4eb9b02e5de1529ebfc01ed821cca5Johnny Chen global suite 1428810042efba4eb9b02e5de1529ebfc01ed821cca5Johnny Chen counterWidth = len(str(suite.countTestCases())) 1429810042efba4eb9b02e5de1529ebfc01ed821cca5Johnny Chen self.fmt = "%" + str(counterWidth) + "d: " 1430c87fd49b6a338372fd6667ad09892b70d57b08fdJohnny Chen self.indentation = ' ' * (counterWidth + 2) 1431810042efba4eb9b02e5de1529ebfc01ed821cca5Johnny Chen # This counts from 1 .. suite.countTestCases(). 1432810042efba4eb9b02e5de1529ebfc01ed821cca5Johnny Chen self.counter = 0 1433bc0c5a6c53350736969f9e0c0a7a9d41742f54c9Enrico Granata (width, height) = LLDBTestResult.getTerminalSize() 14347721589ca4408ec6fbf66cbe1191a2bee7266782Enrico Granata self.progressbar = None 143575f260ab03aa7277b100e1bff477b13c6abacbb7Jim Ingham global progress_bar 1436361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea if width > 10 and not parsable and progress_bar: 14377721589ca4408ec6fbf66cbe1191a2bee7266782Enrico Granata try: 14387721589ca4408ec6fbf66cbe1191a2bee7266782Enrico Granata self.progressbar = progress.ProgressWithEvents(stdout=self.stream,start=0,end=suite.countTestCases(),width=width-10) 14397721589ca4408ec6fbf66cbe1191a2bee7266782Enrico Granata except: 14407721589ca4408ec6fbf66cbe1191a2bee7266782Enrico Granata self.progressbar = None 1441810042efba4eb9b02e5de1529ebfc01ed821cca5Johnny Chen 1442361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea def _config_string(self, test): 1443361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea compiler = getattr(test, "getCompiler", None) 1444361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea arch = getattr(test, "getArchitecture", None) 1445361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea return "%s-%s" % (compiler() if compiler else "", arch() if arch else "") 1446361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea 1447be452279960af0a77434e212ce2f38e4821e00f9Johnny Chen def _exc_info_to_string(self, err, test): 1448be452279960af0a77434e212ce2f38e4821e00f9Johnny Chen """Overrides superclass TestResult's method in order to append 1449be452279960af0a77434e212ce2f38e4821e00f9Johnny Chen our test config info string to the exception info string.""" 14501d6437dc04e38fc75a703f188928f95ad7c5d582Daniel Malea if hasattr(test, "getArchitecture") and hasattr(test, "getCompiler"): 14511d6437dc04e38fc75a703f188928f95ad7c5d582Daniel Malea return '%sConfig=%s-%s' % (super(LLDBTestResult, self)._exc_info_to_string(err, test), 14521d6437dc04e38fc75a703f188928f95ad7c5d582Daniel Malea test.getArchitecture(), 14531d6437dc04e38fc75a703f188928f95ad7c5d582Daniel Malea test.getCompiler()) 14541d6437dc04e38fc75a703f188928f95ad7c5d582Daniel Malea else: 14551d6437dc04e38fc75a703f188928f95ad7c5d582Daniel Malea return super(LLDBTestResult, self)._exc_info_to_string(err, test) 1456be452279960af0a77434e212ce2f38e4821e00f9Johnny Chen 1457c87fd49b6a338372fd6667ad09892b70d57b08fdJohnny Chen def getDescription(self, test): 1458c87fd49b6a338372fd6667ad09892b70d57b08fdJohnny Chen doc_first_line = test.shortDescription() 1459c87fd49b6a338372fd6667ad09892b70d57b08fdJohnny Chen if self.descriptions and doc_first_line: 1460c87fd49b6a338372fd6667ad09892b70d57b08fdJohnny Chen return '\n'.join((str(test), self.indentation + doc_first_line)) 1461c87fd49b6a338372fd6667ad09892b70d57b08fdJohnny Chen else: 1462c87fd49b6a338372fd6667ad09892b70d57b08fdJohnny Chen return str(test) 1463c87fd49b6a338372fd6667ad09892b70d57b08fdJohnny Chen 1464ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata def getCategoriesForTest(self,test): 146556e2c56b703f1deb039c44460c0af2af7a3cca6bEnrico Granata if hasattr(test,"_testMethodName"): 146656e2c56b703f1deb039c44460c0af2af7a3cca6bEnrico Granata test_method = getattr(test,"_testMethodName") 146756e2c56b703f1deb039c44460c0af2af7a3cca6bEnrico Granata test_method = getattr(test,test_method) 146856e2c56b703f1deb039c44460c0af2af7a3cca6bEnrico Granata else: 146956e2c56b703f1deb039c44460c0af2af7a3cca6bEnrico Granata test_method = None 147056e2c56b703f1deb039c44460c0af2af7a3cca6bEnrico Granata if test_method != None and hasattr(test_method,"getCategories"): 147156e2c56b703f1deb039c44460c0af2af7a3cca6bEnrico Granata test_categories = test_method.getCategories(test) 147256e2c56b703f1deb039c44460c0af2af7a3cca6bEnrico Granata elif hasattr(test,"getCategories"): 1473ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata test_categories = test.getCategories() 1474ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata elif inspect.ismethod(test) and test.__self__ != None and hasattr(test.__self__,"getCategories"): 1475ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata test_categories = test.__self__.getCategories() 1476ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata else: 1477ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata test_categories = [] 1478ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata if test_categories == None: 1479ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata test_categories = [] 1480ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata return test_categories 1481ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata 1482ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata def shouldSkipBecauseOfCategories(self,test): 1483ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata global useCategories 1484ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata import inspect 1485ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata if useCategories: 1486ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata global categoriesList 1487ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata test_categories = self.getCategoriesForTest(test) 1488ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata if len(test_categories) == 0 or len(categoriesList & set(test_categories)) == 0: 1489ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata return True 14902bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit 14912bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit global skipCategories 14922bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit for category in skipCategories: 14932bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit if category in self.getCategoriesForTest(test): 14942bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit return True 14952bf963306acbe20bd3de14ad150c157243cd3844Stefanus Du Toit 1496ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata return False 1497ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata 1498ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata def hardMarkAsSkipped(self,test): 1499ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata getattr(test, test._testMethodName).__func__.__unittest_skip__ = True 1500ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata getattr(test, test._testMethodName).__func__.__unittest_skip_why__ = "test case does not fall in any category of interest for this run" 1501571358f0358eca953916c4866db55c3f93d28820Enrico Granata test.__class__.__unittest_skip__ = True 1502571358f0358eca953916c4866db55c3f93d28820Enrico Granata test.__class__.__unittest_skip_why__ = "test case does not fall in any category of interest for this run" 1503ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata 1504810042efba4eb9b02e5de1529ebfc01ed821cca5Johnny Chen def startTest(self, test): 1505ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata if self.shouldSkipBecauseOfCategories(test): 1506ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata self.hardMarkAsSkipped(test) 1507810042efba4eb9b02e5de1529ebfc01ed821cca5Johnny Chen self.counter += 1 1508810042efba4eb9b02e5de1529ebfc01ed821cca5Johnny Chen if self.showAll: 1509810042efba4eb9b02e5de1529ebfc01ed821cca5Johnny Chen self.stream.write(self.fmt % self.counter) 1510810042efba4eb9b02e5de1529ebfc01ed821cca5Johnny Chen super(LLDBTestResult, self).startTest(test) 151184a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen 1512361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea def addSuccess(self, test): 1513361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea global parsable 1514361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea super(LLDBTestResult, self).addSuccess(test) 1515361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea if parsable: 1516361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea self.stream.write("PASS: LLDB (%s) :: %s\n" % (self._config_string(test), str(test))) 1517361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea 1518ce68146871cf9fe802f41a33102edbe39bd85fa1Johnny Chen def addError(self, test, err): 151963c2cba24d3dd924211a4ea7a9ef3ff64555cfbbJohnny Chen global sdir_has_content 1520361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea global parsable 152163c2cba24d3dd924211a4ea7a9ef3ff64555cfbbJohnny Chen sdir_has_content = True 1522ce68146871cf9fe802f41a33102edbe39bd85fa1Johnny Chen super(LLDBTestResult, self).addError(test, err) 1523ce68146871cf9fe802f41a33102edbe39bd85fa1Johnny Chen method = getattr(test, "markError", None) 1524ce68146871cf9fe802f41a33102edbe39bd85fa1Johnny Chen if method: 1525ce68146871cf9fe802f41a33102edbe39bd85fa1Johnny Chen method() 1526361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea if parsable: 1527e1dd3e5262a74fd31db6c3ba62b0fb0af763dc2eDaniel Malea self.stream.write("FAIL: LLDB (%s) :: %s\n" % (self._config_string(test), str(test))) 1528ce68146871cf9fe802f41a33102edbe39bd85fa1Johnny Chen 152984a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen def addFailure(self, test, err): 153063c2cba24d3dd924211a4ea7a9ef3ff64555cfbbJohnny Chen global sdir_has_content 1531ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata global failuresPerCategory 1532361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea global parsable 153363c2cba24d3dd924211a4ea7a9ef3ff64555cfbbJohnny Chen sdir_has_content = True 153484a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen super(LLDBTestResult, self).addFailure(test, err) 153584a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen method = getattr(test, "markFailure", None) 153684a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen if method: 153784a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen method() 1538361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea if parsable: 1539361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea self.stream.write("FAIL: LLDB (%s) :: %s\n" % (self._config_string(test), str(test))) 1540ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata if useCategories: 1541ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata test_categories = self.getCategoriesForTest(test) 1542ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata for category in test_categories: 1543ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata if category in failuresPerCategory: 1544ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata failuresPerCategory[category] = failuresPerCategory[category] + 1 1545ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata else: 1546ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata failuresPerCategory[category] = 1 154784a6d6f10f3010accf9b717b2995f9acb6bee60cJohnny Chen 154821416a1d09aad1e25401e54578c3343bb0f0c25fEnrico Granata def addExpectedFailure(self, test, err, bugnumber): 1549dd2bb2c033f9bca22443faa53f0b769b59f95b8fJohnny Chen global sdir_has_content 1550361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea global parsable 1551dd2bb2c033f9bca22443faa53f0b769b59f95b8fJohnny Chen sdir_has_content = True 155221416a1d09aad1e25401e54578c3343bb0f0c25fEnrico Granata super(LLDBTestResult, self).addExpectedFailure(test, err, bugnumber) 1553dd2bb2c033f9bca22443faa53f0b769b59f95b8fJohnny Chen method = getattr(test, "markExpectedFailure", None) 1554dd2bb2c033f9bca22443faa53f0b769b59f95b8fJohnny Chen if method: 155521416a1d09aad1e25401e54578c3343bb0f0c25fEnrico Granata method(err, bugnumber) 1556361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea if parsable: 1557361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea self.stream.write("XFAIL: LLDB (%s) :: %s\n" % (self._config_string(test), str(test))) 1558dd2bb2c033f9bca22443faa53f0b769b59f95b8fJohnny Chen 1559f5b89098f19f0600a7495215bc35af5cd6130ca2Johnny Chen def addSkip(self, test, reason): 1560f5b89098f19f0600a7495215bc35af5cd6130ca2Johnny Chen global sdir_has_content 1561361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea global parsable 1562f5b89098f19f0600a7495215bc35af5cd6130ca2Johnny Chen sdir_has_content = True 1563f5b89098f19f0600a7495215bc35af5cd6130ca2Johnny Chen super(LLDBTestResult, self).addSkip(test, reason) 1564f5b89098f19f0600a7495215bc35af5cd6130ca2Johnny Chen method = getattr(test, "markSkippedTest", None) 1565f5b89098f19f0600a7495215bc35af5cd6130ca2Johnny Chen if method: 1566f5b89098f19f0600a7495215bc35af5cd6130ca2Johnny Chen method() 1567361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea if parsable: 1568361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea self.stream.write("UNSUPPORTED: LLDB (%s) :: %s (%s) \n" % (self._config_string(test), str(test), reason)) 1569f5b89098f19f0600a7495215bc35af5cd6130ca2Johnny Chen 157021416a1d09aad1e25401e54578c3343bb0f0c25fEnrico Granata def addUnexpectedSuccess(self, test, bugnumber): 1571ab2f066e43817ca0f4b225a24c1a3e7b8166e2d4Johnny Chen global sdir_has_content 1572361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea global parsable 1573ab2f066e43817ca0f4b225a24c1a3e7b8166e2d4Johnny Chen sdir_has_content = True 157421416a1d09aad1e25401e54578c3343bb0f0c25fEnrico Granata super(LLDBTestResult, self).addUnexpectedSuccess(test, bugnumber) 1575ab2f066e43817ca0f4b225a24c1a3e7b8166e2d4Johnny Chen method = getattr(test, "markUnexpectedSuccess", None) 1576ab2f066e43817ca0f4b225a24c1a3e7b8166e2d4Johnny Chen if method: 157721416a1d09aad1e25401e54578c3343bb0f0c25fEnrico Granata method(bugnumber) 1578361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea if parsable: 1579361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea self.stream.write("XPASS: LLDB (%s) :: %s\n" % (self._config_string(test), str(test))) 1580361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea 1581361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea if parsable: 1582361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea v = 0 1583361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea elif progress_bar: 1584361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea v = 1 1585361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea else: 1586361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea v = verbose 1587ab2f066e43817ca0f4b225a24c1a3e7b8166e2d4Johnny Chen 158826be4532bee7111b52ae4bba6628efed17cd23dbJohnny Chen # Invoke the test runner. 1589d2acdb38ed0f756e8dd846e65fa149bd49a872c3Johnny Chen if count == 1: 15907d6d84435a99d8cc59523b0c1985a8eb4f2af5bfJohnny Chen result = unittest2.TextTestRunner(stream=sys.stderr, 1591361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea verbosity=v, 15927d6d84435a99d8cc59523b0c1985a8eb4f2af5bfJohnny Chen failfast=failfast, 1593d2acdb38ed0f756e8dd846e65fa149bd49a872c3Johnny Chen resultclass=LLDBTestResult).run(suite) 1594d2acdb38ed0f756e8dd846e65fa149bd49a872c3Johnny Chen else: 1595d6e7ca2be8c5f4afa94059851a9617d3b950396aJohnny Chen # We are invoking the same test suite more than once. In this case, 1596d6e7ca2be8c5f4afa94059851a9617d3b950396aJohnny Chen # mark __ignore_singleton__ flag as True so the signleton pattern is 1597d6e7ca2be8c5f4afa94059851a9617d3b950396aJohnny Chen # not enforced. 1598360dd372c413c82f651775320bfd4052c31eec00Johnny Chen LLDBTestResult.__ignore_singleton__ = True 1599d2acdb38ed0f756e8dd846e65fa149bd49a872c3Johnny Chen for i in range(count): 1600361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea 16017d6d84435a99d8cc59523b0c1985a8eb4f2af5bfJohnny Chen result = unittest2.TextTestRunner(stream=sys.stderr, 1602361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Malea verbosity=v, 16037d6d84435a99d8cc59523b0c1985a8eb4f2af5bfJohnny Chen failfast=failfast, 1604360dd372c413c82f651775320bfd4052c31eec00Johnny Chen resultclass=LLDBTestResult).run(suite) 1605c056664431d0126f3fb7a57844eee54455807781Filipe Cabecinhas 160624765573e1f52b45f789e5358fd56aab577e429bDaniel Malea failed = failed or not result.wasSuccessful() 16071bfbd41ff54438ab23c55637efb37d6a1db0b977Johnny Chen 1608361eb4320ab96f29bc58973a30bc460e031c32a1Daniel Maleaif sdir_has_content and not parsable: 1609ab2f066e43817ca0f4b225a24c1a3e7b8166e2d4Johnny Chen sys.stderr.write("Session logs for test failures/errors/unexpected successes" 1610ab2f066e43817ca0f4b225a24c1a3e7b8166e2d4Johnny Chen " can be found in directory '%s'\n" % sdir_name) 161163c2cba24d3dd924211a4ea7a9ef3ff64555cfbbJohnny Chen 1612ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granataif useCategories and len(failuresPerCategory) > 0: 1613ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata sys.stderr.write("Failures per category:\n") 1614ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata for category in failuresPerCategory: 1615ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata sys.stderr.write("%s - %d\n" % (category,failuresPerCategory[category])) 1616ac3a8e2b8f5df868f86921d7231bda6356a1366bEnrico Granata 1617571358f0358eca953916c4866db55c3f93d28820Enrico Granataos.chdir(where_to_save_session) 1618a73ad66a4ee96ccc8e6be4a645cd6b9180a72e4bJohnny Chenfname = os.path.join(sdir_name, "TestFinished") 1619a73ad66a4ee96ccc8e6be4a645cd6b9180a72e4bJohnny Chenwith open(fname, "w") as f: 1620a73ad66a4ee96ccc8e6be4a645cd6b9180a72e4bJohnny Chen print >> f, "Test finished at: %s\n" % datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S") 1621a73ad66a4ee96ccc8e6be4a645cd6b9180a72e4bJohnny Chen 1622cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen# Terminate the test suite if ${LLDB_TESTSUITE_FORCE_FINISH} is defined. 1623cd0279daf515ee3d4d6727140987a1554803ea50Johnny Chen# This should not be necessary now. 162483f6e51363d5ccb37933147be00da1c74f0b1351Johnny Chenif ("LLDB_TESTSUITE_FORCE_FINISH" in os.environ): 162583f6e51363d5ccb37933147be00da1c74f0b1351Johnny Chen print "Terminating Test suite..." 162683f6e51363d5ccb37933147be00da1c74f0b1351Johnny Chen subprocess.Popen(["/bin/sh", "-c", "kill %s; exit 0" % (os.getpid())]) 162783f6e51363d5ccb37933147be00da1c74f0b1351Johnny Chen 162801f2a6a3cea331ed92178bf5bc990022e872e93dJohnny Chen# Exiting. 162924765573e1f52b45f789e5358fd56aab577e429bDaniel Maleasys.exit(failed) 1630