forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstress.jl
106 lines (99 loc) · 2.99 KB
/
stress.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# This file is a part of Julia. License is MIT: https://julialang.org/license
# test for proper handling of FD exhaustion
if Sys.isunix()
let ps = Pipe[]
ulimit_n = tryparse(Int, readchomp(`sh -c 'ulimit -n'`))
try
for i = 1:100*something(ulimit_n, 1000)
p = Pipe()
Base.link_pipe!(p)
push!(ps, p)
end
if ulimit_n === nothing
@warn "`ulimit -n` is set to unlimited, fd exhaustion cannot be tested"
@test_broken false
else
@test false
end
catch ex
isa(ex, Base.IOError) || rethrow(ex)
@test ex.code in (Base.UV_EMFILE, Base.UV_ENFILE)
finally
foreach(close, ps)
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
if !Sys.iswindows()
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