-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[coverage] Automatic merger for LLVM profile data #1126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
eb27ca1
2cf852f
c6c0b3d
32fda29
a41ec1a
78612e5
03964cc
3ea61fb
9eb729c
fb6ee1a
259af4d
c83fb1c
1b30a49
5a2a809
9fccf50
bb8160a
b4c7678
e997fc3
44be500
7608f88
b1d6e17
0e6f798
e9d009e
44e44ad
b8a2249
96d4261
1777c20
d41bd9a
f99fd75
d7eff48
693d7da
6572267
dea48f4
eb9fb9c
45df849
873af8e
f713042
c75fa76
6ec0dd3
cf30318
13bae93
2b22040
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,7 @@ if(PYTHONINTERP_FOUND) | |
|
||
set(TEST_MODES optimize_none optimize optimize_unchecked) | ||
|
||
|
||
foreach(SDK ${SWIFT_SDKS}) | ||
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES}) | ||
foreach(TEST_MODE ${TEST_MODES}) | ||
|
@@ -196,30 +197,50 @@ if(PYTHONINTERP_FOUND) | |
"${CMAKE_CURRENT_SOURCE_DIR}/../validation-test/lit.site.cfg.in" | ||
"${validation_test_bin_dir}/lit.site.cfg" | ||
"validation-test${VARIANT_SUFFIX}.lit.site.cfg") | ||
set(profdata_merge_worker | ||
"${CMAKE_CURRENT_SOURCE_DIR}/../utils/profdata_merge_worker.py") | ||
|
||
if(SWIFT_ANALYZE_CODE_COVERAGE STREQUAL "MERGED") | ||
set(command_profdata_merge_start | ||
COMMAND ${PYTHON_EXECUTABLE} ${profdata_merge_worker} start -o ${swift_test_results_dir}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please quote variables. |
||
set(command_profdata_merge_stop | ||
COMMAND ${PYTHON_EXECUTABLE} ${profdata_merge_worker} stop) | ||
else() | ||
set(command_profdata_merge_start) | ||
set(command_profdata_merge_stop) | ||
endif() | ||
|
||
add_custom_target("check-swift${test_mode_target_suffix}${VARIANT_SUFFIX}" | ||
${command_upload_stdlib} | ||
${command_clean_test_results_dir} | ||
${command_profdata_merge_start} | ||
COMMAND ${lit_command} "${test_bin_dir}" | ||
${command_profdata_merge_stop} | ||
DEPENDS ${test_dependencies} | ||
COMMENT "Running Swift tests for ${VARIANT_TRIPLE}" | ||
${cmake_3_2_USES_TERMINAL}) | ||
|
||
add_custom_target("check-swift-validation${test_mode_target_suffix}${VARIANT_SUFFIX}" | ||
${command_upload_stdlib} | ||
${command_clean_test_results_dir} | ||
${command_profdata_merge_start} | ||
COMMAND ${lit_command} "${validation_test_bin_dir}" | ||
${command_profdata_merge_stop} | ||
DEPENDS ${test_dependencies} ${validation_test_dependencies} | ||
COMMENT "Running Swift validation tests for ${VARIANT_TRIPLE}" | ||
${cmake_3_2_USES_TERMINAL}) | ||
|
||
add_custom_target("check-swift-all${test_mode_target_suffix}${VARIANT_SUFFIX}" | ||
${command_upload_stdlib} | ||
${command_clean_test_results_dir} | ||
${command_profdata_merge_start} | ||
COMMAND ${lit_command} "${validation_test_bin_dir}" "${test_bin_dir}" | ||
${command_profdata_merge_stop} | ||
DEPENDS ${test_dependencies} ${validation_test_dependencies} | ||
COMMENT "Running all Swift tests for ${VARIANT_TRIPLE}" | ||
${cmake_3_2_USES_TERMINAL}) | ||
|
||
|
||
endforeach() | ||
endforeach() | ||
endforeach() | ||
|
@@ -245,6 +266,7 @@ if(PYTHONINTERP_FOUND) | |
|
||
add_custom_target(check-swift-all${test_mode_target_suffix} | ||
DEPENDS "check-swift-all${test_mode_target_suffix}${SWIFT_PRIMARY_VARIANT_SUFFIX}") | ||
|
||
endforeach() | ||
|
||
endif() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,10 @@ import re | |
import subprocess | ||
import sys | ||
import tempfile | ||
import socket | ||
import glob | ||
|
||
import lit | ||
import lit.formats | ||
import lit.util | ||
|
||
|
@@ -129,6 +132,39 @@ if config.test_exec_root is None: | |
|
||
### | ||
|
||
class SwiftTest(lit.formats.ShTest): | ||
def __init__(self, coverage_mode=None, execute_external=True): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It comes from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, whoops! I deleted my comment too late--I had misread 😅 |
||
lit.formats.ShTest.__init__(self, execute_external) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the keyword arg required here? |
||
self.coverage_mode = None if coverage_mode == "NONE" else coverage_mode | ||
|
||
def profdir_for_test(self, test): | ||
_, tmp_base = lit.TestRunner.getTempPaths(test) | ||
return tmp_base + ".profdir" | ||
|
||
def before_test(self, test, litConfig): | ||
if self.coverage_mode: | ||
profdir = self.profdir_for_test(test) | ||
if not os.path.exists(profdir): | ||
os.makedirs(profdir) | ||
|
||
test.config.environment["LLVM_PROFILE_FILE"] = os.path.join(profdir, "swift-%p.profraw") | ||
|
||
def after_test(self, test, litConfig, result): | ||
if self.coverage_mode == "MERGED": | ||
profdir = self.profdir_for_test(test) | ||
files = glob.glob(os.path.join(profdir, "*.profraw")) | ||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
sock.connect(('localhost', 12400)) | ||
sock.send("\n".join(files)) | ||
sock.close() | ||
return result | ||
|
||
|
||
def execute(self, test, litConfig): | ||
self.before_test(test, litConfig) | ||
result = super(SwiftTest, self).execute(test, litConfig) | ||
return self.after_test(test, litConfig, result) | ||
|
||
# name: The name of this test suite. | ||
config.name = 'Swift' | ||
|
||
|
@@ -138,7 +174,7 @@ if platform.system() == 'Darwin': | |
config.environment['TOOLCHAINS'] = 'default' | ||
|
||
# testFormat: The test format to use to interpret tests. | ||
config.test_format = lit.formats.ShTest(execute_external=True) | ||
config.test_format = SwiftTest(coverage_mode=config.coverage_mode) | ||
|
||
# suffixes: A list of file extensions to treat as test files. | ||
config.suffixes = ['.swift', '.ll', '.sil', '.gyb', '.m'] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,9 +239,9 @@ macro(add_sourcekit_executable name) | |
PROPERTIES | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you change this invocation to be |
||
LINK_FLAGS "-Wl,-exported_symbol,_main") | ||
|
||
if(SWIFT_ANALYZE_CODE_COVERAGE) | ||
set_property(TARGET "${name}" APPEND_STRING PROPERTY | ||
LINK_FLAGS " -fprofile-instr-generate=swift-%p.profraw -fcoverage-mapping") | ||
if(NOT SWIFT_ANALYZE_CODE_COVERAGE STREQUAL "NONE") | ||
set_property(TARGET "${name}" APPEND_STRING PROPERTY | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 spaces. |
||
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping") | ||
endif() | ||
endif() | ||
endif() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,9 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") | |
PROPERTIES | ||
LINK_FLAGS "-Wl,-rpath -Wl,@executable_path/../lib") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if you change this to append to |
||
|
||
if(SWIFT_ANALYZE_CODE_COVERAGE) | ||
if(NOT SWIFT_ANALYZE_CODE_COVERAGE STREQUAL "NONE") | ||
set_property(TARGET sourcekitd-test APPEND_STRING PROPERTY | ||
LINK_FLAGS " -fprofile-instr-generate=swift-%p.profraw -fcoverage-mapping") | ||
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping") | ||
endif() | ||
endif() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -512,11 +512,12 @@ also build for Apple watchos, but disallow tests that require an watchOS device" | |
action="store_true") | ||
|
||
parser.add_argument("--swift-analyze-code-coverage", | ||
help="enable code coverage analysis in Swift", | ||
action="store_const", | ||
const=True, | ||
dest="swift_analyze_code_coverage", | ||
default=False) | ||
help="""enable code coverage analysis in Swift (set to `merged` to merge | ||
and remove intermediary profdata files)""", | ||
const="default", | ||
choices=["default", "merged"], | ||
nargs='?', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we always require the option value? This is an expert-only option and adding subtle implicit behavior only adds debugging time. |
||
dest="swift_analyze_code_coverage") | ||
|
||
parser.add_argument("--build-subdir", | ||
help=""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ KNOWN_SETTINGS=( | |
llvm-enable-assertions "1" "enable assertions in LLVM and Clang" | ||
swift-build-type "Debug" "the CMake build variant for Swift" | ||
swift-enable-assertions "1" "enable assertions in Swift" | ||
swift-analyze-code-coverage "0" "enable code coverage analysis in Swift" | ||
swift-analyze-code-coverage "default" "enable code coverage analysis in Swift (set to \`merged\` to merge profdata files and remove intermediaries)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are the possible option values? What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The possible values are:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... so let's document them here :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And would you mind renaming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem! 👍 |
||
swift-stdlib-build-type "Debug" "the CMake build variant for Swift" | ||
swift-stdlib-enable-assertions "1" "enable assertions in Swift" | ||
lldb-build-type "Debug" "the CMake build variant for LLDB" | ||
|
@@ -1600,7 +1600,7 @@ for deployment_target in "${HOST_TARGET}" "${CROSS_TOOLS_DEPLOYMENT_TARGETS[@]}" | |
-DCMAKE_CXX_FLAGS="$(swift_c_flags ${deployment_target})" | ||
-DCMAKE_BUILD_TYPE:STRING="${SWIFT_BUILD_TYPE}" | ||
-DLLVM_ENABLE_ASSERTIONS:BOOL=$(true_false "${SWIFT_ENABLE_ASSERTIONS}") | ||
-DSWIFT_ANALYZE_CODE_COVERAGE:BOOL=$(true_false "${SWIFT_ANALYZE_CODE_COVERAGE}") | ||
-DSWIFT_ANALYZE_CODE_COVERAGE:STRING=$(toupper "${SWIFT_ANALYZE_CODE_COVERAGE}") | ||
-DSWIFT_STDLIB_BUILD_TYPE:STRING="${SWIFT_STDLIB_BUILD_TYPE}" | ||
-DSWIFT_STDLIB_ASSERTIONS:BOOL=$(true_false "${SWIFT_STDLIB_ENABLE_ASSERTIONS}") | ||
-DSWIFT_NATIVE_LLVM_TOOLS_PATH:STRING="${native_llvm_tools_path}" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 spaces of indentation.