Skip to content

Commit f75a27a

Browse files
d-nettoqinsoon
authored andcommitted
reland: hard heap limit flag (JuliaLang#58600)
Relands: JuliaLang#58487.
1 parent e5bfe36 commit f75a27a

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

test/cmdlineargs.jl

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,13 +1219,9 @@ end
12191219
end
12201220

12211221
@testset "hard heap limit" begin
1222-
# Set the hard heap limit to 100MB, try to allocate an array of 200MB
1223-
# and assert that the process is aborted, by checking the exit code.
1224-
cmd = `$(Base.julia_cmd()) --startup-file=no --hard-heap-limit=100M -e "a = Array{UInt8}(undef, 200*1024*1024); GC.gc()"`
1225-
p = open(pipeline(cmd, stderr=devnull, stdout=devnull))
1226-
exitcode = wait(p)
1227-
# The process should be aborted with an error code
1228-
@test exitcode != 0
1222+
cmd = `$(Base.julia_cmd()) --hard-heap-limit=30M -E "mutable struct ListNode; v::Int64; next::Union{ListNode, Nothing}; end\n
1223+
l = ListNode(0, nothing); while true; l = ListNode(0, l); end"`
1224+
@test !success(cmd)
12291225
end
12301226
end
12311227

@@ -1272,27 +1268,24 @@ end
12721268
@testset "--hard-heap-limit=$str" for str in ["asdf","","0","1.2vb","b","GB","2.5GB̂","1.2gb2","42gigabytes","5gig","2GiB","NaNt"]
12731269
@test errors_not_signals(`$exename --hard-heap-limit=$str -e "exit(0)"`)
12741270
end
1275-
k = 1024
1276-
m = 1024k
1277-
g = 1024m
1278-
t = 1024g
1279-
# Express one hundred megabytes as 100MB, 100m, 100e6, etc.
1271+
k = UInt64(1) << 10
1272+
m = UInt64(1) << 20
1273+
g = UInt64(1) << 30
1274+
t = UInt64(1) << 40
12801275
one_hundred_mb_strs_and_vals = [
12811276
("100000000", 100000000), ("1e8", 1e8), ("100MB", 100m), ("100m", 100m), ("1e5kB", 1e5k),
12821277
]
12831278
@testset "--hard-heap-limit=$str" for (str, val) in one_hundred_mb_strs_and_vals
12841279
@test parse(UInt64,read(`$exename --hard-heap-limit=$str -E "Base.JLOptions().hard_heap_limit"`, String)) == val
12851280
end
1286-
# Express two and a half gigabytes as 2.5g, 2.5GB, etc.
12871281
two_and_a_half_gigabytes_strs_and_vals = [
12881282
("2500000000", 2500000000), ("2.5e9", 2.5e9), ("2.5g", 2.5g), ("2.5GB", 2.5g), ("2.5e6mB", 2.5e6m),
12891283
]
12901284
@testset "--hard-heap-limit=$str" for (str, val) in two_and_a_half_gigabytes_strs_and_vals
12911285
@test parse(UInt64,read(`$exename --hard-heap-limit=$str -E "Base.JLOptions().hard_heap_limit"`, String)) == val
12921286
end
1293-
# Express one terabyte as 1TB, 1e12, etc.
12941287
one_terabyte_strs_and_vals = [
1295-
("1000000000000", 1000000000000), ("1e12", 1e12), ("1TB", 1t), ("1e9gB", 1e9g),
1288+
("1TB", 1t), ("1024GB", 1t),
12961289
]
12971290
@testset "--hard-heap-limit=$str" for (str, val) in one_terabyte_strs_and_vals
12981291
@test parse(UInt64,read(`$exename --hard-heap-limit=$str -E "Base.JLOptions().hard_heap_limit"`, String)) == val
@@ -1305,27 +1298,24 @@ end
13051298
@testset "--heap-target-increment=$str" for str in ["asdf","","0","1.2vb","b","GB","2.5GB̂","1.2gb2","42gigabytes","5gig","2GiB","NaNt"]
13061299
@test errors_not_signals(`$exename --heap-target-increment=$str -e "exit(0)"`)
13071300
end
1308-
k = 1024
1309-
m = 1024k
1310-
g = 1024m
1311-
t = 1024g
1312-
# Express one hundred megabytes as 100MB, 100m, 100e6, etc.
1301+
k = UInt64(1) << 10
1302+
m = UInt64(1) << 20
1303+
g = UInt64(1) << 30
1304+
t = UInt64(1) << 40
13131305
one_hundred_mb_strs_and_vals = [
13141306
("100000000", 100000000), ("1e8", 1e8), ("100MB", 100m), ("100m", 100m), ("1e5kB", 1e5k),
13151307
]
13161308
@testset "--heap-target-increment=$str" for (str, val) in one_hundred_mb_strs_and_vals
13171309
@test parse(UInt64,read(`$exename --heap-target-increment=$str -E "Base.JLOptions().heap_target_increment"`, String)) == val
13181310
end
1319-
# Express two and a half gigabytes as 2.5g, 2.5GB, etc.
13201311
two_and_a_half_gigabytes_strs_and_vals = [
13211312
("2500000000", 2500000000), ("2.5e9", 2.5e9), ("2.5g", 2.5g), ("2.5GB", 2.5g), ("2.5e6mB", 2.5e6m),
13221313
]
13231314
@testset "--heap-target-increment=$str" for (str, val) in two_and_a_half_gigabytes_strs_and_vals
13241315
@test parse(UInt64,read(`$exename --heap-target-increment=$str -E "Base.JLOptions().heap_target_increment"`, String)) == val
13251316
end
1326-
# Express one terabyte as 1TB, 1e12, etc.
13271317
one_terabyte_strs_and_vals = [
1328-
("1000000000000", 1000000000000), ("1e12", 1e12), ("1TB", 1t), ("1e9gB", 1e9g),
1318+
("1TB", 1t), ("1024GB", 1t),
13291319
]
13301320
@testset "--heap-target-increment=$str" for (str, val) in one_terabyte_strs_and_vals
13311321
@test parse(UInt64,read(`$exename --heap-target-increment=$str -E "Base.JLOptions().heap_target_increment"`, String)) == val

0 commit comments

Comments
 (0)