Alexey Samsonov | 7274ff8 | 2012-07-31 15:43:11 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | import os |
| 4 | |
Daniel Dunbar | a1b15b4 | 2013-08-09 22:14:01 +0000 | [diff] [blame] | 5 | import lit.util |
| 6 | |
Alexey Samsonov | 57434a3 | 2013-05-27 09:35:24 +0000 | [diff] [blame] | 7 | def get_required_attr(config, attr_name): |
| 8 | attr_value = getattr(config, attr_name, None) |
| 9 | if not attr_value: |
Daniel Dunbar | a1b15b4 | 2013-08-09 22:14:01 +0000 | [diff] [blame] | 10 | lit_config.fatal( |
| 11 | "No attribute %r in test configuration! You may need to run " |
| 12 | "tests from your build directory or add this attribute " |
| 13 | "to lit.site.cfg " % attr_name) |
Alexey Samsonov | 57434a3 | 2013-05-27 09:35:24 +0000 | [diff] [blame] | 14 | return attr_value |
| 15 | |
Alexey Samsonov | 7274ff8 | 2012-07-31 15:43:11 +0000 | [diff] [blame] | 16 | # Setup config name. |
Alexey Samsonov | 244a8e0 | 2013-08-07 09:31:28 +0000 | [diff] [blame] | 17 | config.name = 'AddressSanitizer' + config.bits |
Alexey Samsonov | 7274ff8 | 2012-07-31 15:43:11 +0000 | [diff] [blame] | 18 | |
| 19 | # Setup source root. |
| 20 | config.test_source_root = os.path.dirname(__file__) |
| 21 | |
Alexey Samsonov | 4a78b1e | 2012-09-05 10:41:25 +0000 | [diff] [blame] | 22 | def DisplayNoConfigMessage(): |
Daniel Dunbar | a1b15b4 | 2013-08-09 22:14:01 +0000 | [diff] [blame] | 23 | lit_config.fatal("No site specific configuration available! " + |
| 24 | "Try running your test from the build tree or running " + |
| 25 | "make check-asan") |
Alexey Samsonov | 4a78b1e | 2012-09-05 10:41:25 +0000 | [diff] [blame] | 26 | |
| 27 | # Figure out LLVM source root. |
| 28 | llvm_src_root = getattr(config, 'llvm_src_root', None) |
| 29 | if llvm_src_root is None: |
| 30 | # We probably haven't loaded the site-specific configuration: the user |
| 31 | # is likely trying to run a test file directly, and the site configuration |
| 32 | # wasn't created by the build system. |
Daniel Dunbar | a1b15b4 | 2013-08-09 22:14:01 +0000 | [diff] [blame] | 33 | asan_site_cfg = lit_config.params.get('asan_site_config', None) |
Alexey Samsonov | 4a78b1e | 2012-09-05 10:41:25 +0000 | [diff] [blame] | 34 | if (asan_site_cfg) and (os.path.exists(asan_site_cfg)): |
Daniel Dunbar | a1b15b4 | 2013-08-09 22:14:01 +0000 | [diff] [blame] | 35 | lit_config.load_config(config, asan_site_cfg) |
Alexey Samsonov | 4a78b1e | 2012-09-05 10:41:25 +0000 | [diff] [blame] | 36 | raise SystemExit |
| 37 | |
| 38 | # Try to guess the location of site-specific configuration using llvm-config |
| 39 | # util that can point where the build tree is. |
| 40 | llvm_config = lit.util.which("llvm-config", config.environment["PATH"]) |
| 41 | if not llvm_config: |
| 42 | DisplayNoConfigMessage() |
| 43 | |
Alexey Samsonov | 4a78b1e | 2012-09-05 10:41:25 +0000 | [diff] [blame] | 44 | # Find out the presumed location of generated site config. |
| 45 | llvm_obj_root = lit.util.capture(["llvm-config", "--obj-root"]).strip() |
| 46 | asan_site_cfg = os.path.join(llvm_obj_root, "projects", "compiler-rt", |
| 47 | "lib", "asan", "lit_tests", "lit.site.cfg") |
| 48 | if (not asan_site_cfg) or (not os.path.exists(asan_site_cfg)): |
| 49 | DisplayNoConfigMessage() |
| 50 | |
Daniel Dunbar | a1b15b4 | 2013-08-09 22:14:01 +0000 | [diff] [blame] | 51 | lit_config.load_config(config, asan_site_cfg) |
Alexey Samsonov | 4a78b1e | 2012-09-05 10:41:25 +0000 | [diff] [blame] | 52 | raise SystemExit |
| 53 | |
Richard Smith | f10a79a | 2012-11-06 02:31:42 +0000 | [diff] [blame] | 54 | # Setup default compiler flags used with -fsanitize=address option. |
Alexey Samsonov | 7274ff8 | 2012-07-31 15:43:11 +0000 | [diff] [blame] | 55 | # FIXME: Review the set of required flags and check if it can be reduced. |
Alexey Samsonov | 6efa4d6 | 2013-06-07 09:38:55 +0000 | [diff] [blame] | 56 | bits_cflag = " -m" + config.bits |
| 57 | clang_asan_cflags = (" -fsanitize=address" |
| 58 | + " -mno-omit-leaf-frame-pointer" |
| 59 | + " -fno-omit-frame-pointer" |
| 60 | + " -fno-optimize-sibling-calls" |
| 61 | + " -g" |
| 62 | + bits_cflag) |
Hans Wennborg | f021f4f | 2013-07-18 20:48:50 +0000 | [diff] [blame] | 63 | clang_asan_cxxflags = " --driver-mode=g++" + clang_asan_cflags |
Alexey Samsonov | 6efa4d6 | 2013-06-07 09:38:55 +0000 | [diff] [blame] | 64 | config.substitutions.append( ("%clang ", " " + config.clang + bits_cflag + " ")) |
Hans Wennborg | f021f4f | 2013-07-18 20:48:50 +0000 | [diff] [blame] | 65 | config.substitutions.append( ("%clangxx ", (" " + config.clang + |
| 66 | " --driver-mode=g++" + |
Alexey Samsonov | 6efa4d6 | 2013-06-07 09:38:55 +0000 | [diff] [blame] | 67 | bits_cflag + " ")) ) |
| 68 | config.substitutions.append( ("%clang_asan ", (" " + config.clang + " " + |
| 69 | clang_asan_cflags + " ")) ) |
Alexey Samsonov | 589231c | 2012-08-15 08:54:14 +0000 | [diff] [blame] | 70 | config.substitutions.append( ("%clangxx_asan ", (" " + config.clang + " " + |
| 71 | clang_asan_cxxflags + " ")) ) |
Alexey Samsonov | 7274ff8 | 2012-07-31 15:43:11 +0000 | [diff] [blame] | 72 | |
Alexey Samsonov | 997aede | 2013-07-01 09:15:19 +0000 | [diff] [blame] | 73 | # Setup path to asan_symbolize.py script. |
| 74 | asan_source_dir = get_required_attr(config, "asan_source_dir") |
| 75 | asan_symbolize = os.path.join(asan_source_dir, "scripts", "asan_symbolize.py") |
| 76 | if not os.path.exists(asan_symbolize): |
Daniel Dunbar | a1b15b4 | 2013-08-09 22:14:01 +0000 | [diff] [blame] | 77 | lit_config.fatal("Can't find script on path %r" % asan_symbolize) |
Will Dietz | 782cbdc | 2013-10-17 05:33:22 +0000 | [diff] [blame^] | 78 | python_exec = get_required_attr(config, "python_executable") |
| 79 | config.substitutions.append( ("%asan_symbolize", python_exec + " " + asan_symbolize + " ") ) |
Alexey Samsonov | 997aede | 2013-07-01 09:15:19 +0000 | [diff] [blame] | 80 | |
Alexey Samsonov | 41f85b9 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 81 | # Define CHECK-%os to check for OS-dependent output. |
| 82 | config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os))) |
| 83 | |
Alexey Samsonov | 6efa4d6 | 2013-06-07 09:38:55 +0000 | [diff] [blame] | 84 | config.available_features.add("asan-" + config.bits + "-bits") |
| 85 | |
Alexey Samsonov | 1a24918 | 2013-09-08 13:23:29 +0000 | [diff] [blame] | 86 | # Turn on leak detection on 64-bit Linux. |
| 87 | if config.host_os == 'Linux' and config.bits == '64': |
| 88 | config.environment['ASAN_OPTIONS'] = 'detect_leaks=1' |
| 89 | |
Alexey Samsonov | 7274ff8 | 2012-07-31 15:43:11 +0000 | [diff] [blame] | 90 | # Default test suffixes. |
| 91 | config.suffixes = ['.c', '.cc', '.cpp'] |
Alexey Samsonov | 41f85b9 | 2012-08-15 08:29:17 +0000 | [diff] [blame] | 92 | |
| 93 | # AddressSanitizer tests are currently supported on Linux and Darwin only. |
| 94 | if config.host_os not in ['Linux', 'Darwin']: |
| 95 | config.unsupported = True |