@@ -1217,6 +1217,16 @@ end
12171217
12181218 @test readchomp (` $(Base. julia_cmd ()) --startup-file=no --heap-size-hint=10M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"` ) == " $(1 * 1024 * 1024 ) "
12191219end
1220+
1221+ @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
1229+ end
12201230end
12211231
12221232# # `Main.main` entrypoint
@@ -1256,6 +1266,72 @@ end
12561266 end
12571267end
12581268
1269+ @testset " --hard-heap-limit" begin
1270+ exename = ` $(Base. julia_cmd ()) `
1271+ @test errors_not_signals (` $exename --hard-heap-limit -e "exit(0)"` )
1272+ @testset " --hard-heap-limit=$str " for str in [" asdf" ," " ," 0" ," 1.2vb" ," b" ," GB" ," 2.5GB̂" ," 1.2gb2" ," 42gigabytes" ," 5gig" ," 2GiB" ," NaNt" ]
1273+ @test errors_not_signals (` $exename --hard-heap-limit=$str -e "exit(0)"` )
1274+ end
1275+ k = 1024
1276+ m = 1024 k
1277+ g = 1024 m
1278+ t = 1024 g
1279+ # Express one hundred megabytes as 100MB, 100m, 100e6, etc.
1280+ one_hundred_mb_strs_and_vals = [
1281+ (" 100000000" , 100000000 ), (" 1e8" , 1e8 ), (" 100MB" , 100 m), (" 100m" , 100 m), (" 1e5kB" , 1e5 k),
1282+ ]
1283+ @testset " --hard-heap-limit=$str " for (str, val) in one_hundred_mb_strs_and_vals
1284+ @test parse (UInt64,read (` $exename --hard-heap-limit=$str -E "Base.JLOptions().hard_heap_limit"` , String)) == val
1285+ end
1286+ # Express two and a half gigabytes as 2.5g, 2.5GB, etc.
1287+ two_and_a_half_gigabytes_strs_and_vals = [
1288+ (" 2500000000" , 2500000000 ), (" 2.5e9" , 2.5e9 ), (" 2.5g" , 2.5 g), (" 2.5GB" , 2.5 g), (" 2.5e6mB" , 2.5e6 m),
1289+ ]
1290+ @testset " --hard-heap-limit=$str " for (str, val) in two_and_a_half_gigabytes_strs_and_vals
1291+ @test parse (UInt64,read (` $exename --hard-heap-limit=$str -E "Base.JLOptions().hard_heap_limit"` , String)) == val
1292+ end
1293+ # Express one terabyte as 1TB, 1e12, etc.
1294+ one_terabyte_strs_and_vals = [
1295+ (" 1000000000000" , 1000000000000 ), (" 1e12" , 1e12 ), (" 1TB" , 1 t), (" 1e9gB" , 1e9 g),
1296+ ]
1297+ @testset " --hard-heap-limit=$str " for (str, val) in one_terabyte_strs_and_vals
1298+ @test parse (UInt64,read (` $exename --hard-heap-limit=$str -E "Base.JLOptions().hard_heap_limit"` , String)) == val
1299+ end
1300+ end
1301+
1302+ @testset " --heap-target-increment" begin
1303+ exename = ` $(Base. julia_cmd ()) `
1304+ @test errors_not_signals (` $exename --heap-target-increment -e "exit(0)"` )
1305+ @testset " --heap-target-increment=$str " for str in [" asdf" ," " ," 0" ," 1.2vb" ," b" ," GB" ," 2.5GB̂" ," 1.2gb2" ," 42gigabytes" ," 5gig" ," 2GiB" ," NaNt" ]
1306+ @test errors_not_signals (` $exename --heap-target-increment=$str -e "exit(0)"` )
1307+ end
1308+ k = 1024
1309+ m = 1024 k
1310+ g = 1024 m
1311+ t = 1024 g
1312+ # Express one hundred megabytes as 100MB, 100m, 100e6, etc.
1313+ one_hundred_mb_strs_and_vals = [
1314+ (" 100000000" , 100000000 ), (" 1e8" , 1e8 ), (" 100MB" , 100 m), (" 100m" , 100 m), (" 1e5kB" , 1e5 k),
1315+ ]
1316+ @testset " --heap-target-increment=$str " for (str, val) in one_hundred_mb_strs_and_vals
1317+ @test parse (UInt64,read (` $exename --heap-target-increment=$str -E "Base.JLOptions().heap_target_increment"` , String)) == val
1318+ end
1319+ # Express two and a half gigabytes as 2.5g, 2.5GB, etc.
1320+ two_and_a_half_gigabytes_strs_and_vals = [
1321+ (" 2500000000" , 2500000000 ), (" 2.5e9" , 2.5e9 ), (" 2.5g" , 2.5 g), (" 2.5GB" , 2.5 g), (" 2.5e6mB" , 2.5e6 m),
1322+ ]
1323+ @testset " --heap-target-increment=$str " for (str, val) in two_and_a_half_gigabytes_strs_and_vals
1324+ @test parse (UInt64,read (` $exename --heap-target-increment=$str -E "Base.JLOptions().heap_target_increment"` , String)) == val
1325+ end
1326+ # Express one terabyte as 1TB, 1e12, etc.
1327+ one_terabyte_strs_and_vals = [
1328+ (" 1000000000000" , 1000000000000 ), (" 1e12" , 1e12 ), (" 1TB" , 1 t), (" 1e9gB" , 1e9 g),
1329+ ]
1330+ @testset " --heap-target-increment=$str " for (str, val) in one_terabyte_strs_and_vals
1331+ @test parse (UInt64,read (` $exename --heap-target-increment=$str -E "Base.JLOptions().heap_target_increment"` , String)) == val
1332+ end
1333+ end
1334+
12591335@testset " --timeout-for-safepoint-straggler" begin
12601336 exename = ` $(Base. julia_cmd ()) `
12611337 timeout = 120
0 commit comments