Skip to content

Commit 4dcb49d

Browse files
authored
Merge pull request #24330 from apple/preset-for-llvm-tsan-libdispatch-tests
[build][Linux] Create preset to run LLVM's TSan libdispatch tests
2 parents 49b19f5 + 9631700 commit 4dcb49d

File tree

7 files changed

+105
-2
lines changed

7 files changed

+105
-2
lines changed

utils/build-presets.ini

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,21 @@ skip-build-swift
10391039
skip-build-cmark
10401040
llvm-include-tests
10411041

1042+
1043+
[preset: buildbot_incremental_linux,tsan-libdispatch-test]
1044+
mixin-preset=buildbot_incremental_linux,llvm-only
1045+
build-subdir=buildbot_incremental_tsan_libdispatch_test
1046+
1047+
llvm-cmake-options=-DLLVM_INSTALL_UTILS=ON
1048+
llvm-install-components=all
1049+
1050+
libdispatch-cmake-options=-DENABLE_SWIFT=OFF
1051+
libdispatch
1052+
install-libdispatch
1053+
1054+
tsan-libdispatch-test
1055+
1056+
10421057
[preset: buildbot_incremental_linux,asan]
10431058
mixin-preset=buildbot_incremental_linux
10441059
build-subdir=buildbot_incremental_asan

utils/build-script

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ class BuildScriptInvocation(object):
342342
'build_indexstoredb',
343343
'build_sourcekitlsp',
344344
'build_toolchainbenchmarks',
345+
'tsan_libdispatch_test',
345346
]
346347
has_target_needing_toolchain = \
347348
bool(sum(getattr(args, x) for x in targets_needing_toolchain))
@@ -897,6 +898,8 @@ class BuildScriptInvocation(object):
897898
product_classes.append(products.SourceKitLSP)
898899
if self.args.build_toolchainbenchmarks:
899900
product_classes.append(products.Benchmarks)
901+
if self.args.tsan_libdispatch_test:
902+
product_classes.append(products.TSanLibDispatch)
900903
return product_classes
901904

902905
def execute(self):

utils/build-script-impl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,6 +2750,7 @@ for host in "${ALL_HOSTS[@]}"; do
27502750
call rm -rf "${LIBDISPATCH_BUILD_DIR}"
27512751

27522752
cmake_options=(
2753+
-DENABLE_SWIFT=YES
27532754
${cmake_options[@]}
27542755
-DCMAKE_BUILD_TYPE:STRING="${LIBDISPATCH_BUILD_TYPE}"
27552756
-DCMAKE_C_COMPILER:PATH="${LLVM_BIN}/clang"
@@ -2758,7 +2759,6 @@ for host in "${ALL_HOSTS[@]}"; do
27582759
-DCMAKE_INSTALL_PREFIX:PATH="$(get_host_install_prefix ${host})"
27592760
-DCMAKE_INSTALL_LIBDIR:PATH="lib"
27602761

2761-
-DENABLE_SWIFT=YES
27622762
-DSwift_DIR="${SWIFT_BUILD_PATH}/lib/cmake/swift"
27632763

27642764
-DENABLE_TESTING=YES
@@ -3479,7 +3479,11 @@ for host in "${ALL_HOSTS[@]}"; do
34793479
if [[ -z "${LLVM_INSTALL_COMPONENTS}" ]] ; then
34803480
continue
34813481
fi
3482-
INSTALL_TARGETS=install-$(echo ${LLVM_INSTALL_COMPONENTS} | sed -E 's/;/ install-/g')
3482+
if [[ "${LLVM_INSTALL_COMPONENTS}" == "all" ]]; then
3483+
INSTALL_TARGETS=install
3484+
else
3485+
INSTALL_TARGETS=install-$(echo ${LLVM_INSTALL_COMPONENTS} | sed -E 's/;/ install-/g')
3486+
fi
34833487
;;
34843488
libcxx)
34853489
if [[ -z "${INSTALL_LIBCXX}" ]] ; then

utils/build_swift/driver_arguments.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,15 @@ def create_argument_parser():
788788
help='if the Swift Benchmark Suite is run after building, run N '
789789
'iterations with -Onone')
790790

791+
# We want to run the TSan (compiler-rt) libdispatch tests on Linux, where
792+
# libdispatch is just another library and not available by default. To do
793+
# so we build Clang/LLVM/libdispatch and use it to compile/run the TSan
794+
# libdispatch tests.
795+
option('--tsan-libdispatch-test', toggle_true,
796+
help='Builds a new toolchain including the libdispatch C library. '
797+
'Then re-builds the TSan runtime (compiler-rt) using this '
798+
'freshly-built Clang and runs the TSan libdispatch tests.')
799+
791800
option('--skip-test-osx', toggle_false('test_osx'),
792801
help='skip testing Swift stdlibs for Mac OS X')
793802
option('--skip-test-linux', toggle_false('test_linux'),

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
'llvm_max_parallel_lto_link_jobs':
159159
host.max_lto_link_job_counts()['llvm'],
160160
'llvm_targets_to_build': 'X86;ARM;AArch64;PowerPC;SystemZ;Mips',
161+
'tsan_libdispatch_test': False,
161162
'long_test': False,
162163
'lto_type': None,
163164
'show_sdks': False,
@@ -450,6 +451,7 @@ class IgnoreOption(_BaseOption):
450451
EnableOption('--indexstore-db', dest='build_indexstoredb'),
451452
EnableOption('--sourcekit-lsp', dest='build_sourcekitlsp'),
452453
EnableOption('--toolchain-benchmarks', dest='build_toolchainbenchmarks'),
454+
EnableOption('--tsan-libdispatch-test'),
453455
EnableOption('--long-test'),
454456
EnableOption('--show-sdks'),
455457
EnableOption('--stress-test'),

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from .swiftevolve import SwiftEvolve
2828
from .swiftpm import SwiftPM
2929
from .swiftsyntax import SwiftSyntax
30+
from .tsan_libdispatch import TSanLibDispatch
3031
from .xctest import XCTest
3132

3233
__all__ = [
@@ -49,4 +50,5 @@
4950
'IndexStoreDB',
5051
'SourceKitLSP',
5152
'Benchmarks',
53+
'TSanLibDispatch',
5254
]
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# swift_build_support/products/tsan_libdispatch.py --------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
import os
14+
15+
from . import product
16+
from .. import shell
17+
18+
19+
def join_path(*paths):
20+
return os.path.abspath(os.path.join(*paths))
21+
22+
23+
class TSanLibDispatch(product.Product):
24+
@classmethod
25+
def product_source_name(cls):
26+
return "tsan-libdispatch-test"
27+
28+
@classmethod
29+
def is_build_script_impl_product(cls):
30+
return False
31+
32+
def build(self, host_target):
33+
"""Build TSan runtime (compiler-rt)."""
34+
rt_source_dir = join_path(self.source_dir, os.pardir, 'compiler-rt')
35+
toolchain_path = join_path(self.args.install_destdir, 'usr')
36+
clang = join_path(toolchain_path, 'bin', 'clang')
37+
clangxx = join_path(toolchain_path, 'bin', 'clang++')
38+
39+
config_cmd = [
40+
'cmake',
41+
'-GNinja',
42+
'-DCMAKE_PREFIX_PATH=%s' % toolchain_path,
43+
'-DCMAKE_C_COMPILER=%s' % clang,
44+
'-DCMAKE_CXX_COMPILER=%s' % clangxx,
45+
'-DCMAKE_BUILD_TYPE=Release',
46+
'-DLLVM_ENABLE_ASSERTIONS=ON',
47+
'-DCOMPILER_RT_INCLUDE_TESTS=ON',
48+
'-DCOMPILER_RT_BUILD_XRAY=OFF',
49+
'-DCOMPILER_RT_INTERCEPT_LIBDISPATCH=ON',
50+
'-DCOMPILER_RT_LIBDISPATCH_INSTALL_PATH=%s' % toolchain_path,
51+
rt_source_dir]
52+
build_cmd = ['ninja', 'tsan']
53+
54+
# Always rebuild TSan runtime
55+
shell.rmtree(self.build_dir)
56+
shell.makedirs(self.build_dir)
57+
58+
with shell.pushd(self.build_dir):
59+
shell.call(config_cmd)
60+
shell.call(build_cmd)
61+
62+
def test(self, host_target):
63+
"""Run check-tsan target with a LIT filter for libdispatch."""
64+
cmd = ['ninja', 'check-tsan']
65+
env = {'LIT_FILTER': 'libdispatch'}
66+
67+
with shell.pushd(self.build_dir):
68+
shell.call(cmd, env=env)

0 commit comments

Comments
 (0)