Attempt to prevent a race condition with dmd test runner when same file but different extension is used (#16330)

This commit is contained in:
Richard (Rikki) Andrew Cattermole 2024-03-26 21:54:00 +13:00 committed by GitHub
parent ab4e5f54f8
commit bc7dd498dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 6 deletions

View file

@ -3,7 +3,9 @@
source tools/common_funcs.sh source tools/common_funcs.sh
expect_file=${EXTRA_FILES}/${TEST_NAME}.out expect_file=${EXTRA_FILES}/${TEST_NAME}.out
obj_file=${OUTPUT_BASE}_0.o # We are only used by cdcmp, which is a D test,
# otherwise we could use ${OUTPUT_BASE} and then figure out language.
obj_file=${RESULTS_TEST_DIR}/d/${TEST_NAME}_0.o
echo Creating objdump echo Creating objdump
objdump --disassemble --disassembler-options=intel "${obj_file}" > "${obj_file}.dump" objdump --disassemble --disassembler-options=intel "${obj_file}" > "${obj_file}.dump"
@ -14,4 +16,4 @@ echo SANITIZING Objdump...
diff -up --strip-trailing-cr "${expect_file}" "${obj_file}.dump.sanitized" diff -up --strip-trailing-cr "${expect_file}" "${obj_file}.dump.sanitized"
rm_retry "${OUTPUT_BASE}.o"{,.dump,.dump,.sanitized} rm_retry ${obj_file}{,.dump,.dump,.sanitized}

View file

@ -1598,10 +1598,22 @@ int tryMain(string[] args)
const input_dir = input_file.dirName(); const input_dir = input_file.dirName();
const test_base_name = input_file.baseName(); const test_base_name = input_file.baseName();
const test_name = test_base_name.stripExtension(); const test_name = test_base_name.stripExtension();
const test_ext = test_base_name.extension();
const result_path = envData.results_dir ~ envData.sep; // Previously we did not take into account the test file extension,
const output_dir = result_path ~ input_dir; // because of ImportC we now have the ability to have conflicting source file basenames (when ignoring extension).
const output_file = result_path ~ input_file ~ ".out"; // This can cause a race condition with the concurrent test runner,
// in which whilst one test is running another will try to clobber it and fail.
// Unfortunately dshell does not take into account our output directory,
// at least not in a way that'll allow us to take advantage of the test extension.
// However since its not really an issue for clobbering, we'll ignore it.
const result_path = envData.results_dir ~ envData.sep;
const output_dir_base = result_path ~ input_dir;
const output_dir = (input_dir == "dshell" ? output_dir_base : (output_dir_base ~ envData.sep ~ test_ext[1 .. $]));
const output_file = result_path ~ input_file ~ ".out";
// We are potentially creating a test extension specific directory
mkdirRecurse(output_dir);
TestArgs testArgs; TestArgs testArgs;
switch (input_dir) switch (input_dir)
@ -1622,7 +1634,7 @@ int tryMain(string[] args)
return 1; return 1;
} }
if (test_base_name.extension() == ".sh") if (test_ext == ".sh")
{ {
string file = cast(string) std.file.read(input_file); string file = cast(string) std.file.read(input_file);
string disabledPlatforms; string disabledPlatforms;