Skip to content

Commit 9723f82

Browse files
ararslanKristofferC
authored andcommitted
Keep expected crash in misc test from producing a core dump (#42990)
Currently the test in `test/misc.jl` that tests that a particular kind of read fault crashes has two issues: 1. It works for the wrong reason. It's testing for `!success` when evaluating code interpolated directly into the `Cmd`, but it isn't quoting the code, so the subprocess fails with a syntax error instead of the type of crash the test is expecting. 2. On some platforms (such as our good ol' pal FreeBSD), this kind of read fault produces a core dump. This a bit annoying because it means that the repo state becomes dirty after running the tests and it may overwrite an existing core dump that was left behind by an earlier issue we'd like to diagnose. To fix these, we can wrap the code passed to the subprocess in single quotes and on Unix-like systems wrap the subprocess in `ulimit -c 0` to avoid producing a core dump. (cherry picked from commit fa6dcb0)
1 parent ee25032 commit 9723f82

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

test/misc.jl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,12 +1008,25 @@ end
10081008
# Test that read fault on a prot-none region does not incorrectly give
10091009
# ReadOnlyMemoryEror, but rather crashes the program
10101010
const MAP_ANONYMOUS_PRIVATE = Sys.isbsd() ? 0x1002 : 0x22
1011-
let script = :(let ptr = Ptr{Cint}(ccall(:jl_mmap, Ptr{Cvoid},
1012-
(Ptr{Cvoid}, Csize_t, Cint, Cint, Cint, Int),
1013-
C_NULL, 16*1024, 0, $MAP_ANONYMOUS_PRIVATE, -1, 0)); try
1014-
unsafe_load(ptr)
1015-
catch e; println(e) end; end)
1016-
@test !success(`$(Base.julia_cmd()) -e $script`)
1011+
let script = :(
1012+
let ptr = Ptr{Cint}(ccall(:jl_mmap, Ptr{Cvoid},
1013+
(Ptr{Cvoid}, Csize_t, Cint, Cint, Cint, Int),
1014+
C_NULL, 16*1024, 0, $MAP_ANONYMOUS_PRIVATE, -1, 0))
1015+
try
1016+
unsafe_load(ptr)
1017+
catch e
1018+
println(e)
1019+
end
1020+
end
1021+
)
1022+
cmd = if Sys.isunix()
1023+
# Set the maximum core dump size to 0 to keep this expected crash from
1024+
# producing a (and potentially overwriting an existing) core dump file
1025+
`sh -c "ulimit -c 0; $(Base.shell_escape(Base.julia_cmd())) -e '$script'"`
1026+
else
1027+
`$(Base.julia_cmd()) -e '$script'`
1028+
end
1029+
@test !success(cmd)
10171030
end
10181031

10191032
# issue #41656

0 commit comments

Comments
 (0)