lit.cfg 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # -*- Python -*-
  2. # Configuration file for the 'lit' test runner.
  3. import os
  4. import platform
  5. import lit.formats
  6. import lit.util
  7. # name: The name of this test suite.
  8. config.name = 'Clang-Unit'
  9. # suffixes: A list of file extensions to treat as test files.
  10. config.suffixes = []
  11. # test_source_root: The root path where tests are located.
  12. # test_exec_root: The root path where tests should be run.
  13. clang_obj_root = getattr(config, 'clang_obj_root', None)
  14. if clang_obj_root is not None:
  15. config.test_exec_root = os.path.join(clang_obj_root, 'unittests')
  16. config.test_source_root = config.test_exec_root
  17. # testFormat: The test format to use to interpret tests.
  18. llvm_build_mode = getattr(config, 'llvm_build_mode', "Debug")
  19. config.test_format = lit.formats.GoogleTest(llvm_build_mode, 'Tests')
  20. # Propagate the temp directory. Windows requires this because it uses \Windows\
  21. # if none of these are present.
  22. if 'TMP' in os.environ:
  23. config.environment['TMP'] = os.environ['TMP']
  24. if 'TEMP' in os.environ:
  25. config.environment['TEMP'] = os.environ['TEMP']
  26. # Propagate path to symbolizer for ASan/MSan.
  27. for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
  28. if symbolizer in os.environ:
  29. config.environment[symbolizer] = os.environ[symbolizer]
  30. ###
  31. # Check that the object root is known.
  32. if config.test_exec_root is None:
  33. # Otherwise, we haven't loaded the site specific configuration (the user is
  34. # probably trying to run on a test file directly, and either the site
  35. # configuration hasn't been created by the build system, or we are in an
  36. # out-of-tree build situation).
  37. # Check for 'clang_unit_site_config' user parameter, and use that if available.
  38. site_cfg = lit_config.params.get('clang_unit_site_config', None)
  39. if site_cfg and os.path.exists(site_cfg):
  40. lit_config.load_config(config, site_cfg)
  41. raise SystemExit
  42. # Try to detect the situation where we are using an out-of-tree build by
  43. # looking for 'llvm-config'.
  44. #
  45. # FIXME: I debated (i.e., wrote and threw away) adding logic to
  46. # automagically generate the lit.site.cfg if we are in some kind of fresh
  47. # build situation. This means knowing how to invoke the build system
  48. # though, and I decided it was too much magic.
  49. llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
  50. if not llvm_config:
  51. lit_config.fatal('No site specific configuration available!')
  52. # Get the source and object roots.
  53. llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
  54. llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
  55. clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
  56. clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
  57. # Validate that we got a tree which points to here, using the standard
  58. # tools/clang layout.
  59. this_src_root = os.path.join(os.path.dirname(__file__),'..','..')
  60. if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
  61. lit_config.fatal('No site specific configuration available!')
  62. # Check that the site specific configuration exists.
  63. site_cfg = os.path.join(clang_obj_root, 'test', 'Unit', 'lit.site.cfg')
  64. if not os.path.exists(site_cfg):
  65. lit_config.fatal('No site specific configuration available!')
  66. # Okay, that worked. Notify the user of the automagic, and reconfigure.
  67. lit_config.note('using out-of-tree build at %r' % clang_obj_root)
  68. lit_config.load_config(config, site_cfg)
  69. raise SystemExit
  70. shlibpath_var = ''
  71. if platform.system() == 'Linux':
  72. shlibpath_var = 'LD_LIBRARY_PATH'
  73. elif platform.system() == 'Darwin':
  74. shlibpath_var = 'DYLD_LIBRARY_PATH'
  75. elif platform.system() == 'Windows':
  76. shlibpath_var = 'PATH'
  77. # Point the dynamic loader at dynamic libraries in 'lib'.
  78. llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
  79. if not llvm_libs_dir:
  80. lit_config.fatal('No LLVM libs dir set!')
  81. shlibpath = os.path.pathsep.join((llvm_libs_dir,
  82. config.environment.get(shlibpath_var,'')))
  83. # Win32 seeks DLLs along %PATH%.
  84. if sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir):
  85. shlibpath = os.path.pathsep.join((config.shlibdir, shlibpath))
  86. config.environment[shlibpath_var] = shlibpath