forked from OSchip/llvm-project
Add better support for custom test runners.
Summary: I finally got around to merging the many, many changes to lit.cfg into Android's libc++. This patch makes it simpler to actually use a custom configuration and test format. First, I've factored out _build, _run, and _clean methods from _execute_test, since these are the likely parts that will need to be overridden. This is likely a first step in the work jroelofs has been doing with improving cross-compiling test execution. Second, I've added a `configuration_variant` to the config. This entry, if present, is a string that forms the prefix of the class that is to be used to configure the test runner. For example, Android sets `config.configuration_variant = 'Android'`, and this causes an object of type `AndroidConfiguration` to be constructed. As an example of how this will be used, see: https://android-review.googlesource.com/#/c/116022/ Reviewers: jroelofs, mclow.lists, EricWF Reviewed By: EricWF Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6373 llvm-svn: 222698
This commit is contained in:
parent
2918fefd1c
commit
86b75a4057
|
@ -45,7 +45,7 @@ class LibcxxTestFormat(lit.formats.FileBasedTest):
|
|||
if in_dir:
|
||||
kwargs['cwd'] = in_dir
|
||||
p = subprocess.Popen(command, **kwargs)
|
||||
out,err = p.communicate()
|
||||
out, err = p.communicate()
|
||||
exitCode = p.wait()
|
||||
|
||||
# Detect Ctrl-C in subprocess.
|
||||
|
@ -108,6 +108,37 @@ class LibcxxTestFormat(lit.formats.FileBasedTest):
|
|||
# Evaluate the test.
|
||||
return self._evaluate_test(test, use_verify, lit_config)
|
||||
|
||||
def _build(self, exec_path, source_path, compile_only=False,
|
||||
use_verify=False):
|
||||
cmd = [self.cxx_under_test, '-o', exec_path,
|
||||
source_path] + self.cpp_flags
|
||||
|
||||
if compile_only:
|
||||
cmd += ['-c']
|
||||
else:
|
||||
cmd += self.ld_flags
|
||||
|
||||
if use_verify:
|
||||
cmd += ['-Xclang', '-verify']
|
||||
|
||||
out, err, rc = self.execute_command(cmd)
|
||||
return cmd, out, err, rc
|
||||
|
||||
def _clean(self, exec_path):
|
||||
os.remove(exec_path)
|
||||
|
||||
def _run(self, exec_path, lit_config, in_dir=None):
|
||||
cmd = []
|
||||
if self.exec_env:
|
||||
cmd.append('env')
|
||||
cmd.extend('%s=%s' % (name, value)
|
||||
for name,value in self.exec_env.items())
|
||||
cmd.append(exec_path)
|
||||
if lit_config.useValgrind:
|
||||
cmd = lit_config.valgrindArgs + cmd
|
||||
out, err, exitCode = self.execute_command(cmd, in_dir)
|
||||
return cmd, out, err, exitCode
|
||||
|
||||
def _evaluate_test(self, test, use_verify, lit_config):
|
||||
name = test.path_in_suite[-1]
|
||||
source_path = test.getSourcePath()
|
||||
|
@ -119,13 +150,10 @@ class LibcxxTestFormat(lit.formats.FileBasedTest):
|
|||
|
||||
# If this is a compile (failure) test, build it and check for failure.
|
||||
if expected_compile_fail:
|
||||
cmd = [self.cxx_under_test, '-c',
|
||||
'-o', '/dev/null', source_path] + self.cpp_flags
|
||||
expected_rc = 1
|
||||
if use_verify:
|
||||
cmd += ['-Xclang', '-verify']
|
||||
expected_rc = 0
|
||||
out, err, rc = self.execute_command(cmd)
|
||||
cmd, out, err, rc = self._build('/dev/null', source_path,
|
||||
compile_only=True,
|
||||
use_verify=use_verify)
|
||||
expected_rc = 0 if use_verify else 1
|
||||
if rc == expected_rc:
|
||||
return lit.Test.PASS, ""
|
||||
else:
|
||||
|
@ -144,14 +172,12 @@ class LibcxxTestFormat(lit.formats.FileBasedTest):
|
|||
exec_file.close()
|
||||
|
||||
try:
|
||||
compile_cmd = [self.cxx_under_test, '-o', exec_path,
|
||||
source_path] + self.cpp_flags + self.ld_flags
|
||||
cmd = compile_cmd
|
||||
out, err, exitCode = self.execute_command(cmd)
|
||||
if exitCode != 0:
|
||||
cmd, out, err, rc = self._build(exec_path, source_path)
|
||||
compile_cmd = cmd
|
||||
if rc != 0:
|
||||
report = """Command: %s\n""" % ' '.join(["'%s'" % a
|
||||
for a in cmd])
|
||||
report += """Exit Code: %d\n""" % exitCode
|
||||
report += """Exit Code: %d\n""" % rc
|
||||
if out:
|
||||
report += """Standard Output:\n--\n%s--""" % out
|
||||
if err:
|
||||
|
@ -159,21 +185,14 @@ class LibcxxTestFormat(lit.formats.FileBasedTest):
|
|||
report += "\n\nCompilation failed unexpectedly!"
|
||||
return lit.Test.FAIL, report
|
||||
|
||||
cmd = []
|
||||
if self.exec_env:
|
||||
cmd.append('env')
|
||||
cmd.extend('%s=%s' % (name, value)
|
||||
for name,value in self.exec_env.items())
|
||||
cmd.append(exec_path)
|
||||
if lit_config.useValgrind:
|
||||
cmd = lit_config.valgrindArgs + cmd
|
||||
out, err, exitCode = self.execute_command(cmd, source_dir)
|
||||
if exitCode != 0:
|
||||
cmd, out, err, rc = self._run(exec_path, lit_config,
|
||||
source_dir)
|
||||
if rc != 0:
|
||||
report = """Compiled With: %s\n""" % \
|
||||
' '.join(["'%s'" % a for a in compile_cmd])
|
||||
report += """Command: %s\n""" % \
|
||||
' '.join(["'%s'" % a for a in cmd])
|
||||
report += """Exit Code: %d\n""" % exitCode
|
||||
report += """Exit Code: %d\n""" % rc
|
||||
if out:
|
||||
report += """Standard Output:\n--\n%s--""" % out
|
||||
if err:
|
||||
|
@ -182,7 +201,9 @@ class LibcxxTestFormat(lit.formats.FileBasedTest):
|
|||
return lit.Test.FAIL, report
|
||||
finally:
|
||||
try:
|
||||
os.remove(exec_path)
|
||||
# Note that cleanup of exec_file happens in `_clean()`. If
|
||||
# you override this, cleanup is your reponsibility.
|
||||
self._clean(exec_path)
|
||||
except:
|
||||
pass
|
||||
return lit.Test.PASS, ""
|
||||
|
@ -514,6 +535,11 @@ config.suffixes = ['.cpp']
|
|||
# test_source_root: The root path where tests are located.
|
||||
config.test_source_root = os.path.dirname(__file__)
|
||||
|
||||
configuration = Configuration(lit_config, config)
|
||||
cfg_variant = getattr(config, 'configuration_variant', '')
|
||||
if cfg_variant:
|
||||
print 'Using configuration variant: %s' % cfg_variant
|
||||
|
||||
# Construct an object of the type named `<VARIANT>Configuration`.
|
||||
configuration = globals()['%sConfiguration' % cfg_variant](lit_config, config)
|
||||
configuration.configure()
|
||||
config.test_format = configuration.get_test_format()
|
||||
|
|
Loading…
Reference in New Issue