Files
swift-mirror/test/swift_test.py
Bob Wilson 7b75291625 Fix Swift lit tests after LLVM r299775
LLVM's lit implementation switched to use process pools in r299775.
This exposed some pickling problems in Swift's lit files. For a function
or class to be pickle-able, it has to be in the top-level of a real
Python module.

* The SwiftTest lit format class was embedded in the lit.cfg file, so
I moved it out to a separate Python file.

* The inferSwiftBinary function was being stashed in the
config.inferSwiftBinary field and later used to find tools for SourceKit
testing. I moved the config settings for those tools into the top-level
lit.cfg file. I expect this will cause warnings about them not existing
in some cases, but that should be fairly harmless. Maybe someone can
come up with a better solution later.

* The config.substitutions for SourceKit's lit.local.cfg was storing a
reference to an embedded sed_clean function, which just returned a
constant string. I changed the function to be a string, using Python's
raw string feature to avoid the problems that likely led to it being a
function in the first place. (Just guessing.)
2017-04-10 11:07:42 -07:00

62 lines
2.4 KiB
Python

# swift/test/swift_test.py - SwiftTest format for lit tests -*- python -*-
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# -----------------------------------------------------------------------------
#
# This is a test format file for the 'lit' test runner.
#
# -----------------------------------------------------------------------------
import os
import lit
import lit.formats
import lit.util
class SwiftTest(lit.formats.ShTest, object):
def __init__(self, coverage_mode=None, execute_external=True):
super(SwiftTest, self).__init__(execute_external=execute_external)
if coverage_mode == "FALSE":
self.coverage_mode = None
else:
self.coverage_mode = coverage_mode
self.skipped_tests = set()
def before_test(self, test, litConfig):
if self.coverage_mode:
# FIXME: The compiler crashers run so fast they fill up the
# merger's queue (and therefore the build bot's disk)
if 'crasher' in test.getSourcePath():
test.config.environment["LLVM_PROFILE_FILE"] = os.devnull
self.skipped_tests.add(test.getSourcePath())
return
_, tmp_base = lit.TestRunner.getTempPaths(test)
if self.coverage_mode == "NOT_MERGED":
profdir = tmp_base + '.profdir'
if not os.path.exists(profdir):
os.makedirs(profdir)
test.config.environment["LLVM_PROFILE_FILE"] = \
os.path.join(profdir, "swift-%p.profraw")
else:
test.config.environment["LLVM_PROFILE_FILE"] = \
os.path.join(config.swift_test_results_dir,
"swift-%4m.profraw")
def after_test(self, test, litConfig, result):
if test.getSourcePath() in self.skipped_tests:
self.skipped_tests.remove(test.getSourcePath())
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)