Skip to content

Commit

Permalink
Keep expected crash in misc test from producing a core dump (JuliaLan…
Browse files Browse the repository at this point in the history
…g#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.
  • Loading branch information
ararslan committed Nov 8, 2021
1 parent aca020b commit fa6dcb0
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1037,12 +1037,25 @@ end
# Test that read fault on a prot-none region does not incorrectly give
# ReadOnlyMemoryEror, but rather crashes the program
const MAP_ANONYMOUS_PRIVATE = Sys.isbsd() ? 0x1002 : 0x22
let script = :(let ptr = Ptr{Cint}(ccall(:jl_mmap, Ptr{Cvoid},
(Ptr{Cvoid}, Csize_t, Cint, Cint, Cint, Int),
C_NULL, 16*1024, 0, $MAP_ANONYMOUS_PRIVATE, -1, 0)); try
unsafe_load(ptr)
catch e; println(e) end; end)
@test !success(`$(Base.julia_cmd()) -e $script`)
let script = :(
let ptr = Ptr{Cint}(ccall(:jl_mmap, Ptr{Cvoid},
(Ptr{Cvoid}, Csize_t, Cint, Cint, Cint, Int),
C_NULL, 16*1024, 0, $MAP_ANONYMOUS_PRIVATE, -1, 0))
try
unsafe_load(ptr)
catch e
println(e)
end
end
)
cmd = if Sys.isunix()
# Set the maximum core dump size to 0 to keep this expected crash from
# producing a (and potentially overwriting an existing) core dump file
`sh -c "ulimit -c 0; $(Base.shell_escape(Base.julia_cmd())) -e '$script'"`
else
`$(Base.julia_cmd()) -e '$script'`
end
@test !success(cmd)
end

# issue #41656
Expand Down

0 comments on commit fa6dcb0

Please sign in to comment.