lit.cfg 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. # -*- Python -*-
  2. # Configuration file for the 'lit' test runner.
  3. import os
  4. import sys
  5. import re
  6. import platform
  7. import lit.util
  8. import lit.formats
  9. # name: The name of this test suite.
  10. config.name = 'LLVM'
  11. # Tweak PATH for Win32 to decide to use bash.exe or not.
  12. if sys.platform in ['win32']:
  13. # Seek sane tools in directories and set to $PATH.
  14. path = getattr(config, 'lit_tools_dir', None)
  15. path = lit_config.getToolsPath(path,
  16. config.environment['PATH'],
  17. ['cmp.exe', 'grep.exe', 'sed.exe'])
  18. if path is not None:
  19. path = os.path.pathsep.join((path,
  20. config.environment['PATH']))
  21. config.environment['PATH'] = path
  22. # Choose between lit's internal shell pipeline runner and a real shell. If
  23. # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
  24. use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
  25. if use_lit_shell:
  26. # 0 is external, "" is default, and everything else is internal.
  27. execute_external = (use_lit_shell == "0")
  28. else:
  29. # Otherwise we default to internal on Windows and external elsewhere, as
  30. # bash on Windows is usually very slow.
  31. execute_external = (not sys.platform in ['win32'])
  32. # testFormat: The test format to use to interpret tests.
  33. config.test_format = lit.formats.ShTest(execute_external)
  34. # suffixes: A list of file extensions to treat as test files. This is overriden
  35. # by individual lit.local.cfg files in the test subdirectories.
  36. config.suffixes = ['.ll', '.c', '.cxx', '.test', '.txt', '.s']
  37. # excludes: A list of directories to exclude from the testsuite. The 'Inputs'
  38. # subdirectories contain auxiliary inputs for various tests in their parent
  39. # directories.
  40. config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
  41. # test_source_root: The root path where tests are located.
  42. config.test_source_root = os.path.dirname(__file__)
  43. # test_exec_root: The root path where tests should be run.
  44. llvm_obj_root = getattr(config, 'llvm_obj_root', None)
  45. if llvm_obj_root is not None:
  46. config.test_exec_root = os.path.join(llvm_obj_root, 'test')
  47. # Tweak the PATH to include the tools dir.
  48. if llvm_obj_root is not None:
  49. llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
  50. if not llvm_tools_dir:
  51. lit_config.fatal('No LLVM tools dir set!')
  52. path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
  53. config.environment['PATH'] = path
  54. # Propagate 'HOME' through the environment.
  55. if 'HOME' in os.environ:
  56. config.environment['HOME'] = os.environ['HOME']
  57. # Propagate 'INCLUDE' through the environment.
  58. if 'INCLUDE' in os.environ:
  59. config.environment['INCLUDE'] = os.environ['INCLUDE']
  60. # Propagate 'LIB' through the environment.
  61. if 'LIB' in os.environ:
  62. config.environment['LIB'] = os.environ['LIB']
  63. # Propagate the temp directory. Windows requires this because it uses \Windows\
  64. # if none of these are present.
  65. if 'TMP' in os.environ:
  66. config.environment['TMP'] = os.environ['TMP']
  67. if 'TEMP' in os.environ:
  68. config.environment['TEMP'] = os.environ['TEMP']
  69. # Propagate LLVM_SRC_ROOT into the environment.
  70. config.environment['LLVM_SRC_ROOT'] = getattr(config, 'llvm_src_root', '')
  71. # Propagate PYTHON_EXECUTABLE into the environment
  72. config.environment['PYTHON_EXECUTABLE'] = getattr(config, 'python_executable',
  73. '')
  74. # Propagate path to symbolizer for ASan/MSan.
  75. for symbolizer in ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH']:
  76. if symbolizer in os.environ:
  77. config.environment[symbolizer] = os.environ[symbolizer]
  78. # Set up OCAMLPATH to include newly built OCaml libraries.
  79. llvm_lib_dir = getattr(config, 'llvm_lib_dir', None)
  80. if llvm_lib_dir is None:
  81. if llvm_obj_root is not None:
  82. llvm_lib_dir = os.path.join(llvm_obj_root, 'lib')
  83. if llvm_lib_dir is not None:
  84. llvm_ocaml_lib = os.path.join(llvm_lib_dir, 'ocaml')
  85. if llvm_ocaml_lib is not None:
  86. if 'OCAMLPATH' in os.environ:
  87. ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, os.environ['OCAMLPATH']))
  88. config.environment['OCAMLPATH'] = ocamlpath
  89. else:
  90. config.environment['OCAMLPATH'] = llvm_ocaml_lib
  91. if 'CAML_LD_LIBRARY_PATH' in os.environ:
  92. caml_ld_library_path = os.path.pathsep.join((llvm_ocaml_lib,
  93. os.environ['CAML_LD_LIBRARY_PATH']))
  94. config.environment['CAML_LD_LIBRARY_PATH'] = caml_ld_library_path
  95. else:
  96. config.environment['CAML_LD_LIBRARY_PATH'] = llvm_ocaml_lib
  97. # Set up OCAMLRUNPARAM to enable backtraces in OCaml tests.
  98. config.environment['OCAMLRUNPARAM'] = 'b'
  99. ###
  100. import os
  101. # Check that the object root is known.
  102. if config.test_exec_root is None:
  103. # Otherwise, we haven't loaded the site specific configuration (the user is
  104. # probably trying to run on a test file directly, and either the site
  105. # configuration hasn't been created by the build system, or we are in an
  106. # out-of-tree build situation).
  107. # Check for 'llvm_site_config' user parameter, and use that if available.
  108. site_cfg = lit_config.params.get('llvm_site_config', None)
  109. if site_cfg and os.path.exists(site_cfg):
  110. lit_config.load_config(config, site_cfg)
  111. raise SystemExit
  112. # Try to detect the situation where we are using an out-of-tree build by
  113. # looking for 'llvm-config'.
  114. #
  115. # FIXME: I debated (i.e., wrote and threw away) adding logic to
  116. # automagically generate the lit.site.cfg if we are in some kind of fresh
  117. # build situation. This means knowing how to invoke the build system
  118. # though, and I decided it was too much magic.
  119. llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
  120. if not llvm_config:
  121. lit_config.fatal('No site specific configuration available!')
  122. # Get the source and object roots.
  123. llvm_src_root = lit.util.capture(['llvm-config', '--src-root']).strip()
  124. llvm_obj_root = lit.util.capture(['llvm-config', '--obj-root']).strip()
  125. # Validate that we got a tree which points to here.
  126. this_src_root = os.path.dirname(config.test_source_root)
  127. if os.path.realpath(llvm_src_root) != os.path.realpath(this_src_root):
  128. lit_config.fatal('No site specific configuration available!')
  129. # Check that the site specific configuration exists.
  130. site_cfg = os.path.join(llvm_obj_root, 'test', 'lit.site.cfg')
  131. if not os.path.exists(site_cfg):
  132. lit_config.fatal('No site specific configuration available!')
  133. # Okay, that worked. Notify the user of the automagic, and reconfigure.
  134. lit_config.note('using out-of-tree build at %r' % llvm_obj_root)
  135. lit_config.load_config(config, site_cfg)
  136. raise SystemExit
  137. ###
  138. lli = 'lli'
  139. # The target triple used by default by lli is the process target triple (some
  140. # triple appropriate for generating code for the current process) but because
  141. # we don't support COFF in MCJIT well enough for the tests, force ELF format on
  142. # Windows. FIXME: the process target triple should be used here, but this is
  143. # difficult to obtain on Windows.
  144. if re.search(r'cygwin|mingw32|windows-gnu|windows-msvc|win32', config.host_triple):
  145. lli += ' -mtriple='+config.host_triple+'-elf'
  146. config.substitutions.append( ('%lli', lli ) )
  147. # Similarly, have a macro to use llc with DWARF even when the host is win32.
  148. llc_dwarf = 'llc'
  149. if re.search(r'win32', config.target_triple):
  150. llc_dwarf += ' -mtriple='+config.target_triple.replace('-win32', '-mingw32')
  151. config.substitutions.append( ('%llc_dwarf', llc_dwarf) )
  152. # Add site-specific substitutions.
  153. config.substitutions.append( ('%gold', config.gold_executable) )
  154. config.substitutions.append( ('%ld64', config.ld64_executable) )
  155. config.substitutions.append( ('%go', config.go_executable) )
  156. config.substitutions.append( ('%llvmshlibdir', config.llvm_shlib_dir) )
  157. config.substitutions.append( ('%shlibext', config.llvm_shlib_ext) )
  158. config.substitutions.append( ('%exeext', config.llvm_exe_ext) )
  159. config.substitutions.append( ('%python', config.python_executable) )
  160. # OCaml substitutions.
  161. # Support tests for both native and bytecode builds.
  162. config.substitutions.append( ('%ocamlc',
  163. "%s ocamlc -cclib -L%s %s" %
  164. (config.ocamlfind_executable, llvm_lib_dir, config.ocaml_flags)) )
  165. if config.have_ocamlopt in ('1', 'TRUE'):
  166. config.substitutions.append( ('%ocamlopt',
  167. "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" %
  168. (config.ocamlfind_executable, llvm_lib_dir, llvm_lib_dir, config.ocaml_flags)) )
  169. else:
  170. config.substitutions.append( ('%ocamlopt', "true" ) )
  171. # For each occurrence of an llvm tool name as its own word, replace it
  172. # with the full path to the build directory holding that tool. This
  173. # ensures that we are testing the tools just built and not some random
  174. # tools that might happen to be in the user's PATH. Thus this list
  175. # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
  176. # (llvm_tools_dir in lit parlance).
  177. # Avoid matching RUN line fragments that are actually part of
  178. # path names or options or whatever.
  179. # The regex is a pre-assertion to avoid matching a preceding
  180. # dot, hyphen, carat, or slash (.foo, -foo, etc.). Some patterns
  181. # also have a post-assertion to not match a trailing hyphen (foo-).
  182. NOJUNK = r"(?<!\.|-|\^|/)"
  183. for pattern in [r"\bbugpoint\b(?!-)",
  184. NOJUNK + r"\bllc\b",
  185. r"\blli\b",
  186. r"\bllvm-ar\b",
  187. r"\bllvm-as\b",
  188. r"\bllvm-bcanalyzer\b",
  189. r"\bllvm-config\b",
  190. r"\bllvm-cov\b",
  191. r"\bllvm-cxxdump\b",
  192. r"\bllvm-diff\b",
  193. r"\bllvm-dis\b",
  194. r"\bllvm-dsymutil\b",
  195. r"\bllvm-dwarfdump\b",
  196. r"\bllvm-extract\b",
  197. r"\bllvm-go\b",
  198. r"\bllvm-lib\b",
  199. r"\bllvm-link\b",
  200. r"\bllvm-lto\b",
  201. r"\bllvm-mc\b",
  202. r"\bllvm-mcmarkup\b",
  203. r"\bllvm-nm\b",
  204. r"\bllvm-objdump\b",
  205. r"\bllvm-profdata\b",
  206. r"\bllvm-ranlib\b",
  207. r"\bllvm-readobj\b",
  208. r"\bllvm-rtdyld\b",
  209. r"\bllvm-size\b",
  210. r"\bllvm-tblgen\b",
  211. r"\bllvm-c-test\b",
  212. r"\bmacho-dump\b",
  213. NOJUNK + r"\bopt\b",
  214. r"\bFileCheck\b",
  215. r"\bobj2yaml\b",
  216. r"\byaml2obj\b",
  217. r"\byaml-bench\b",
  218. r"\bverify-uselistorder\b",
  219. # Handle these specially as they are strings searched
  220. # for during testing.
  221. r"\| \bcount\b",
  222. r"\| \bnot\b"]:
  223. # Extract the tool name from the pattern. This relies on the tool
  224. # name being surrounded by \b word match operators. If the
  225. # pattern starts with "| ", include it in the string to be
  226. # substituted.
  227. tool_match = re.match(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
  228. pattern)
  229. tool_pipe = tool_match.group(2)
  230. tool_name = tool_match.group(4)
  231. # Did the user specify the tool path + arguments? This allows things like
  232. # llvm-lit "-Dllc=llc -enable-misched -verify-machineinstrs"
  233. tool_path = lit_config.params.get(tool_name)
  234. if tool_path is None:
  235. tool_path = lit.util.which(tool_name, llvm_tools_dir)
  236. if tool_path is None:
  237. # Warn, but still provide a substitution.
  238. lit_config.note('Did not find ' + tool_name + ' in ' + llvm_tools_dir)
  239. tool_path = llvm_tools_dir + '/' + tool_name
  240. if (tool_name == "llc" and
  241. 'LLVM_ENABLE_MACHINE_VERIFIER' in os.environ and
  242. os.environ['LLVM_ENABLE_MACHINE_VERIFIER'] == "1"):
  243. tool_path += " -verify-machineinstrs"
  244. config.substitutions.append((pattern, tool_pipe + tool_path))
  245. ### Targets
  246. config.targets = frozenset(config.targets_to_build.split())
  247. ### Features
  248. # Shell execution
  249. if execute_external:
  250. config.available_features.add('shell')
  251. # Others/can-execute.txt
  252. if sys.platform not in ['win32']:
  253. config.available_features.add('can-execute')
  254. # Loadable module
  255. # FIXME: This should be supplied by Makefile or autoconf.
  256. if sys.platform in ['win32', 'cygwin']:
  257. loadable_module = (config.enable_shared == 1)
  258. else:
  259. loadable_module = True
  260. if loadable_module:
  261. config.available_features.add('loadable_module')
  262. # Sanitizers.
  263. if config.llvm_use_sanitizer == "Address":
  264. config.available_features.add("asan")
  265. if (config.llvm_use_sanitizer == "Memory" or
  266. config.llvm_use_sanitizer == "MemoryWithOrigins"):
  267. config.available_features.add("msan")
  268. if config.llvm_use_sanitizer == "Undefined":
  269. config.available_features.add("ubsan")
  270. else:
  271. config.available_features.add("not_ubsan")
  272. # Check if we should run long running tests.
  273. if lit_config.params.get("run_long_tests", None) == "true":
  274. config.available_features.add("long_tests")
  275. # Direct object generation
  276. # Suppress x86_64-mingw32 while investigating since r219108.
  277. if not 'hexagon' in config.target_triple and not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
  278. config.available_features.add("object-emission")
  279. if config.have_zlib == "1":
  280. config.available_features.add("zlib")
  281. else:
  282. config.available_features.add("nozlib")
  283. # Native compilation: host arch == target arch
  284. # FIXME: Consider cases that target can be executed
  285. # even if host_triple were different from target_triple.
  286. if config.host_triple == config.target_triple:
  287. config.available_features.add("native")
  288. import subprocess
  289. def have_ld_plugin_support():
  290. if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
  291. return False
  292. ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE)
  293. ld_out = ld_cmd.stdout.read().decode()
  294. ld_cmd.wait()
  295. if not '-plugin' in ld_out:
  296. return False
  297. # check that the used emulations are supported.
  298. emu_line = [l for l in ld_out.split('\n') if 'supported emulations' in l]
  299. if len(emu_line) != 1:
  300. return False
  301. emu_line = emu_line[0]
  302. fields = emu_line.split(':')
  303. if len(fields) != 3:
  304. return False
  305. emulations = fields[2].split()
  306. if 'elf_x86_64' not in emulations:
  307. return False
  308. if 'elf32ppc' in emulations:
  309. config.available_features.add('ld_emu_elf32ppc')
  310. ld_version = subprocess.Popen([config.gold_executable, '--version'], stdout = subprocess.PIPE)
  311. if not 'GNU gold' in ld_version.stdout.read().decode():
  312. return False
  313. ld_version.wait()
  314. return True
  315. if have_ld_plugin_support():
  316. config.available_features.add('ld_plugin')
  317. def have_ld64_plugin_support():
  318. if config.ld64_executable == '':
  319. return False
  320. ld_cmd = subprocess.Popen([config.ld64_executable, '-v'], stderr = subprocess.PIPE)
  321. ld_out = ld_cmd.stderr.read().decode()
  322. ld_cmd.wait()
  323. if 'ld64' not in ld_out or 'LTO' not in ld_out:
  324. return False
  325. return True
  326. if have_ld64_plugin_support():
  327. config.available_features.add('ld64_plugin')
  328. # Ask llvm-config about assertion mode.
  329. try:
  330. llvm_config_cmd = subprocess.Popen(
  331. [os.path.join(llvm_tools_dir, 'llvm-config'), '--assertion-mode'],
  332. stdout = subprocess.PIPE,
  333. env=config.environment)
  334. except OSError:
  335. print("Could not find llvm-config in " + llvm_tools_dir)
  336. exit(42)
  337. if re.search(r'ON', llvm_config_cmd.stdout.read().decode('ascii')):
  338. config.available_features.add('asserts')
  339. llvm_config_cmd.wait()
  340. if 'darwin' == sys.platform:
  341. try:
  342. sysctl_cmd = subprocess.Popen(['sysctl', 'hw.optional.fma'],
  343. stdout = subprocess.PIPE)
  344. except OSError:
  345. print("Could not exec sysctl")
  346. result = sysctl_cmd.stdout.read().decode('ascii')
  347. if -1 != result.find("hw.optional.fma: 1"):
  348. config.available_features.add('fma3')
  349. sysctl_cmd.wait()
  350. # .debug_frame is not emitted for targeting Windows x64.
  351. if not re.match(r'^x86_64.*-(mingw32|windows-gnu|win32)', config.target_triple):
  352. config.available_features.add('debug_frame')
  353. # Check if we should use gmalloc.
  354. use_gmalloc_str = lit_config.params.get('use_gmalloc', None)
  355. if use_gmalloc_str is not None:
  356. if use_gmalloc_str.lower() in ('1', 'true'):
  357. use_gmalloc = True
  358. elif use_gmalloc_str.lower() in ('', '0', 'false'):
  359. use_gmalloc = False
  360. else:
  361. lit_config.fatal('user parameter use_gmalloc should be 0 or 1')
  362. else:
  363. # Default to not using gmalloc
  364. use_gmalloc = False
  365. # Allow use of an explicit path for gmalloc library.
  366. # Will default to '/usr/lib/libgmalloc.dylib' if not set.
  367. gmalloc_path_str = lit_config.params.get('gmalloc_path',
  368. '/usr/lib/libgmalloc.dylib')
  369. if use_gmalloc:
  370. config.environment.update({'DYLD_INSERT_LIBRARIES' : gmalloc_path_str})