From 66eef195a5823b437747a270e865ec7e812bbee0 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 24 Jul 2018 20:25:02 -0700 Subject: [PATCH] Move tests for #13559, #22566, and jl_exit_on_sigint to stress.jl --- test/core.jl | 12 -------- test/file.jl | 67 ----------------------------------------- test/stress.jl | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 79 deletions(-) diff --git a/test/core.jl b/test/core.jl index e27bf9c13afc1..5719527dcd68b 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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() diff --git a/test/file.jl b/test/file.jl index f639357366087..e80af7e7c9bd6 100644 --- a/test/file.jl +++ b/test/file.jl @@ -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 diff --git a/test/stress.jl b/test/stress.jl index f9df39c117d0a..ea47799e383a3 100644 --- a/test/stress.jl +++ b/test/stress.jl @@ -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