Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions test/tools/d_do_test.d
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ int tryMain(string[] args)
Result testCombination(bool autoCompileImports, string argSet, size_t permuteIndex, string permutedArgs)
{
string test_app_dmd = test_app_dmd_base ~ to!string(permuteIndex) ~ envData.exe;

string command; // copy of the last executed command so that it can be re-invoked on failures
try
{
string[] toCleanup;
Expand Down Expand Up @@ -706,7 +706,7 @@ int tryMain(string[] args)
string objfile = output_dir ~ envData.sep ~ test_name ~ "_" ~ to!string(permuteIndex) ~ envData.obj;
toCleanup ~= objfile;

string command = format("%s -conf= -m%s -I%s %s %s -od%s -of%s %s %s%s %s", envData.dmd, envData.model, input_dir,
command = format("%s -conf= -m%s -I%s %s %s -od%s -of%s %s %s%s %s", envData.dmd, envData.model, input_dir,
reqArgs, permutedArgs, output_dir,
(testArgs.mode == TestMode.RUN || testArgs.link ? test_app_dmd : objfile),
argSet,
Expand All @@ -724,15 +724,15 @@ int tryMain(string[] args)
string newo= result_path ~ replace(replace(filename, ".d", envData.obj), envData.sep~"imports"~envData.sep, envData.sep);
toCleanup ~= newo;

string command = format("%s -conf= -m%s -I%s %s %s -od%s -c %s %s", envData.dmd, envData.model, input_dir,
command = format("%s -conf= -m%s -I%s %s %s -od%s -c %s %s", envData.dmd, envData.model, input_dir,
reqArgs, permutedArgs, output_dir, argSet, filename);
compile_output ~= execute(fThisRun, command, testArgs.mode != TestMode.FAIL_COMPILE, result_path);
}

if (testArgs.mode == TestMode.RUN || testArgs.link)
{
// link .o's into an executable
string command = format("%s -conf= -m%s%s%s %s %s -od%s -of%s %s", envData.dmd, envData.model,
command = format("%s -conf= -m%s%s%s %s %s -od%s -of%s %s", envData.dmd, envData.model,
autoCompileImports ? " -i" : "",
autoCompileImports ? "extraSourceIncludePaths" : "",
envData.required_args, testArgs.requiredArgsForLink, output_dir, test_app_dmd, join(toCleanup, " "));
Expand All @@ -748,6 +748,8 @@ int tryMain(string[] args)

auto m = std.regex.match(compile_output, `Internal error: .*$`);
enforce(!m, m.hit);
m = std.regex.match(compile_output, `core.exception.AssertError@dmd.*`);
enforce(!m, m.hit);

if (testArgs.compileOutput !is null)
{
Expand All @@ -767,7 +769,7 @@ int tryMain(string[] args)

if (testArgs.gdbScript is null)
{
string command = test_app_dmd;
command = test_app_dmd;
if (testArgs.executeArgs) command ~= " " ~ testArgs.executeArgs;

execute(fThisRun, command, true, result_path);
Expand All @@ -781,8 +783,8 @@ int tryMain(string[] args)
writeln("set disable-randomization off");
write(testArgs.gdbScript);
}
string command = "gdb "~test_app_dmd~" --batch -x "~script;
auto gdb_output = execute(fThisRun, command, true, result_path);
string gdbCommand = "gdb "~test_app_dmd~" --batch -x "~script;
auto gdb_output = execute(fThisRun, gdbCommand, true, result_path);
if (testArgs.gdbMatch !is null)
{
enforce(match(gdb_output, regex(testArgs.gdbMatch)),
Expand Down Expand Up @@ -836,6 +838,17 @@ int tryMain(string[] args)
writefln("Test %s failed. The logged output:", input_file);
writeln(output_file.readText);
output_file.remove();

// automatically rerun a segfaulting test and print its stack trace
version(linux)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only Linux?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I didn't know whether it would work on other platforms and I thought it's good to start with something that I can test. Also most of our CIs are Linux ones, so it would already have a measurable impact.
IIRC OSX uses lldb and Windows has who knows what debugger available?

(+I didn't feel like fighting the auto-tester for something that hasn't received feedback yet.)

if (e.msg.canFind("exited with rc == 139"))
{
auto gdbCommand = "gdb -q -n -ex 'set backtrace limit 100' -ex run -ex bt -batch -args " ~ command;
import std.process : executeShell;
auto res = executeShell(gdbCommand);
res.output.writeln;
}

return Result.return1;
}
}
Expand Down