Skip to content

Commit

Permalink
Move tests for #13559, #22566, and jl_exit_on_sigint to stress.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Jul 25, 2018
1 parent 42d5194 commit 66eef19
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 79 deletions.
12 changes: 0 additions & 12 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2436,18 +2436,6 @@ let x = [1,2,3]
@test (ccall(:jl_new_bits, Any, (Any,Ptr{Cvoid},), Tuple{Int16,Tuple{Cvoid},Int8,Tuple{},Int,Cvoid,Int}, x)::Tuple)[[2,4,5,6,7]] === ((nothing,),(),2,nothing,3)
end

# sig 2 is SIGINT per the POSIX.1-1990 standard
if !Sys.iswindows()
ccall(:jl_exit_on_sigint, Cvoid, (Cint,), 0)
@test_throws InterruptException begin
ccall(:kill, Cvoid, (Cint, Cint,), getpid(), 2)
for i in 1:10
Libc.systemsleep(0.1)
ccall(:jl_gc_safepoint, Cvoid, ()) # wait for SIGINT to arrive
end
end
ccall(:jl_exit_on_sigint, Cvoid, (Cint,), 1)
end
let
# Exception frame automatically restores sigatomic counter.
Base.sigatomic_begin()
Expand Down
67 changes: 0 additions & 67 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1029,71 +1029,4 @@ let n = tempname()
rm(n)
end

# issue 13559
if !Sys.iswindows()
function test_13559()
fn = tempname()
run(`mkfifo $fn`)
# use subprocess to write 127 bytes to FIFO
writer_cmds = """
using Test
x = open($(repr(fn)), "w")
for i in 1:120
write(x, 0xaa)
end
flush(x)
Test.@test read(stdin, Int8) == 31
for i in 1:7
write(x, 0xaa)
end
close(x)
"""
p = open(pipeline(`$(Base.julia_cmd()) --startup-file=no -e $writer_cmds`, stderr=stderr), "w")
# quickly read FIFO, draining it and blocking but not failing with EOFError yet
r = open(fn, "r")
# 15 proper reads
for i in 1:15
@test read(r, UInt64) === 0xaaaaaaaaaaaaaaaa
end
write(p, 0x1f)
# last read should throw EOFError when FIFO closes, since there are only 7 bytes (or less) available.
@test_throws EOFError read(r, UInt64)
close(r)
@test success(p)
rm(fn)
end
test_13559()
end
@test_throws ArgumentError mkpath("fakepath", mode = -1)

# issue #22566
# issue #24037 (disabling on FreeBSD)
if !Sys.iswindows() && !(Sys.isbsd() && !Sys.isapple())
function test_22566()
fn = tempname()
run(`mkfifo $fn`)

script = """
using Test
x = open($(repr(fn)), "w")
write(x, 0x42)
flush(x)
Test.@test read(stdin, Int8) == 21
close(x)
"""
cmd = `$(Base.julia_cmd()) --startup-file=no -e $script`
p = open(pipeline(cmd, stderr=stderr), "w")

r = open(fn, "r")
@test read(r, Int8) == 66
write(p, 0x15)
close(r)
@test success(p)
rm(fn)
end

# repeat opening/closing fifo file, ensure no EINTR popped out
for i 1:50
test_22566()
end
end # !Sys.iswindows
81 changes: 81 additions & 0 deletions test/stress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,84 @@ if Sys.isunix()
end
end
end

# issue 13559
if !Sys.iswindows()
function test_13559()
fn = tempname()
run(`mkfifo $fn`)
# use subprocess to write 127 bytes to FIFO
writer_cmds = """
using Test
x = open($(repr(fn)), "w")
for i in 1:120
write(x, 0xaa)
end
flush(x)
Test.@test read(stdin, Int8) == 31
for i in 1:7
write(x, 0xaa)
end
close(x)
"""
p = open(pipeline(`$(Base.julia_cmd()) --startup-file=no -e $writer_cmds`, stderr=stderr), "w")
# quickly read FIFO, draining it and blocking but not failing with EOFError yet
r = open(fn, "r")
# 15 proper reads
for i in 1:15
@test read(r, UInt64) === 0xaaaaaaaaaaaaaaaa
end
write(p, 0x1f)
# last read should throw EOFError when FIFO closes, since there are only 7 bytes (or less) available.
@test_throws EOFError read(r, UInt64)
close(r)
@test success(p)
rm(fn)
end
test_13559()
end

# issue #22566
# issue #24037 (disabling on FreeBSD)
if !Sys.iswindows() && !(Sys.isbsd() && !Sys.isapple())
function test_22566()
fn = tempname()
run(`mkfifo $fn`)

script = """
using Test
x = open($(repr(fn)), "w")
write(x, 0x42)
flush(x)
Test.@test read(stdin, Int8) == 21
close(x)
"""
cmd = `$(Base.julia_cmd()) --startup-file=no -e $script`
p = open(pipeline(cmd, stderr=stderr), "w")

r = open(fn, "r")
@test read(r, Int8) == 66
write(p, 0x15)
close(r)
@test success(p)
rm(fn)
end

# repeat opening/closing fifo file, ensure no EINTR popped out
for i = 1:50
test_22566()
end
end # !Sys.iswindows

# sig 2 is SIGINT per the POSIX.1-1990 standard
if !Sys.iswindows()
ccall(:jl_exit_on_sigint, Cvoid, (Cint,), 0)
@test_throws InterruptException begin
ccall(:kill, Cvoid, (Cint, Cint,), getpid(), 2)
for i in 1:10
Libc.systemsleep(0.1)
ccall(:jl_gc_safepoint, Cvoid, ()) # wait for SIGINT to arrive
end
end
ccall(:jl_exit_on_sigint, Cvoid, (Cint,), 1)
end

0 comments on commit 66eef19

Please sign in to comment.