Index: libcxx/trunk/test/lit.cfg =================================================================== --- libcxx/trunk/test/lit.cfg +++ libcxx/trunk/test/lit.cfg @@ -45,7 +45,7 @@ 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 @@ # 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 @@ # 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 @@ 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 @@ 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 @@ 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 @@ # 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 `Configuration`. +configuration = globals()['%sConfiguration' % cfg_variant](lit_config, config) configuration.configure() config.test_format = configuration.get_test_format()