Skip to content

Commit bb00540

Browse files
committed
Skipping some tests that are currently incompatible with MMTk
1 parent 2ca125f commit bb00540

File tree

5 files changed

+142
-102
lines changed

5 files changed

+142
-102
lines changed

stdlib/Profile/test/allocs.jl

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Test
22
using Profile: Allocs
33

4+
const USING_STOCK_GC = occursin("stock", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ())))
5+
46
Allocs.clear()
57
let iobuf = IOBuffer()
68
for format in (:tree, :flat)
@@ -73,8 +75,12 @@ end
7375
@test length(first_alloc.stacktrace) > 0
7476
@test length(string(first_alloc.type)) > 0
7577

76-
@testset for type in (Task, Vector{Float64},)
77-
@test length(filter(a->a.type <: type, profile.allocs)) >= NUM_TASKS
78+
# This test does not work with MMTk because of fastpath allocation
79+
# which never calls the allocation profiler.
80+
if USING_STOCK_GC
81+
@testset for type in (Task, Vector{Float64},)
82+
@test length(filter(a->a.type <: type, profile.allocs)) >= NUM_TASKS
83+
end
7884
end
7985

8086
# TODO: it would be nice to assert that these tasks
@@ -143,24 +149,29 @@ end
143149
@test length([a for a in prof.allocs if a.type == String]) >= 1
144150
end
145151

152+
# FIXME: We currently do not call the allocation profiler
153+
# in the fastpath allocation for MMTk in codegen. Therefore, this
154+
# test has been disabled for MMTk.
146155
@testset "alloc profiler catches allocs from codegen" begin
147-
@eval begin
148-
struct MyType x::Int; y::Int end
149-
Base.:(+)(n::Number, x::MyType) = n + x.x + x.y
150-
foo(a, x) = a[1] + x
151-
wrapper(a) = foo(a, MyType(0,1))
152-
end
153-
a = Any[1,2,3]
154-
# warmup
155-
wrapper(a)
156+
if USING_STOCK_GC
157+
@eval begin
158+
struct MyType x::Int; y::Int end
159+
Base.:(+)(n::Number, x::MyType) = n + x.x + x.y
160+
foo(a, x) = a[1] + x
161+
wrapper(a) = foo(a, MyType(0,1))
162+
end
163+
a = Any[1,2,3]
164+
# warmup
165+
wrapper(a)
156166

157-
@eval Allocs.@profile sample_rate=1 wrapper($a)
167+
@eval Allocs.@profile sample_rate=1 wrapper($a)
158168

159-
prof = Allocs.fetch()
160-
Allocs.clear()
169+
prof = Allocs.fetch()
170+
Allocs.clear()
161171

162-
@test length(prof.allocs) >= 1
163-
@test length([a for a in prof.allocs if a.type == MyType]) >= 1
172+
@test length(prof.allocs) >= 1
173+
@test length([a for a in prof.allocs if a.type == MyType]) >= 1
174+
end
164175
end
165176

166177
@testset "alloc profiler catches allocs from buffer resize" begin

stdlib/Profile/test/runtests.jl

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -344,35 +344,41 @@ end
344344
@test only(node.down).first == lidict[8]
345345
end
346346

347+
const USING_STOCK_GC = occursin("stock", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ())))
348+
349+
# FIXME: This test that expects specific information from
350+
# heap snapshots, which is currently supported in MMTk
347351
@testset "HeapSnapshot" begin
348-
tmpdir = mktempdir()
352+
if USING_STOCK_GC
353+
tmpdir = mktempdir()
349354

350-
# ensure that we can prevent redacting data
351-
fname = cd(tmpdir) do
352-
read(`$(Base.julia_cmd()) --startup-file=no -e "using Profile; const x = \"redact_this\"; print(Profile.take_heap_snapshot(; redact_data=false))"`, String)
353-
end
355+
# ensure that we can prevent redacting data
356+
fname = cd(tmpdir) do
357+
read(`$(Base.julia_cmd()) --startup-file=no -e "using Profile; const x = \"redact_this\"; print(Profile.take_heap_snapshot(; redact_data=false))"`, String)
358+
end
354359

355-
@test isfile(fname)
360+
@test isfile(fname)
356361

357-
sshot = read(fname, String)
358-
@test sshot != ""
359-
@test contains(sshot, "redact_this")
362+
sshot = read(fname, String)
363+
@test sshot != ""
364+
@test contains(sshot, "redact_this")
360365

361-
rm(fname)
366+
rm(fname)
362367

363-
# ensure that string data is redacted by default
364-
fname = cd(tmpdir) do
365-
read(`$(Base.julia_cmd()) --startup-file=no -e "using Profile; const x = \"redact_this\"; print(Profile.take_heap_snapshot())"`, String)
366-
end
368+
# ensure that string data is redacted by default
369+
fname = cd(tmpdir) do
370+
read(`$(Base.julia_cmd()) --startup-file=no -e "using Profile; const x = \"redact_this\"; print(Profile.take_heap_snapshot())"`, String)
371+
end
367372

368-
@test isfile(fname)
373+
@test isfile(fname)
369374

370-
sshot = read(fname, String)
371-
@test sshot != ""
372-
@test !contains(sshot, "redact_this")
375+
sshot = read(fname, String)
376+
@test sshot != ""
377+
@test !contains(sshot, "redact_this")
373378

374-
rm(fname)
375-
rm(tmpdir, force = true, recursive = true)
379+
rm(fname)
380+
rm(tmpdir, force = true, recursive = true)
381+
end
376382
end
377383

378384
@testset "PageProfile" begin

test/cmdlineargs.jl

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ let
6060
@test format_filename("%a%%b") == "a%b"
6161
end
6262

63+
const USING_STOCK_GC = occursin("stock", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ())))
64+
6365
@testset "julia_cmd" begin
6466
julia_basic = Base.julia_cmd()
6567
function get_julia_cmd(arg)
@@ -383,29 +385,33 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
383385
@test p.exitcode == 1 && p.termsignal == 0
384386
end
385387

386-
# --gcthreads
387-
code = "print(Threads.ngcthreads())"
388-
cpu_threads = ccall(:jl_effective_threads, Int32, ())
389-
@test string(cpu_threads) ==
390-
read(`$exename --threads auto -e $code`, String) ==
391-
read(`$exename --threads=auto -e $code`, String) ==
392-
read(`$exename -tauto -e $code`, String) ==
393-
read(`$exename -t auto -e $code`, String)
394-
for nt in (nothing, "1")
395-
withenv("JULIA_NUM_GC_THREADS" => nt) do
396-
@test read(`$exename --gcthreads=2 -e $code`, String) == "2"
397-
end
398-
withenv("JULIA_NUM_GC_THREADS" => nt) do
399-
@test read(`$exename --gcthreads=2,1 -e $code`, String) == "3"
388+
# FIXME: --gc-threads does not have the same semantics
389+
# for Stock GC and MMTk, so the tests below are specific to the Stock GC
390+
if USING_STOCK_GC
391+
# --gcthreads
392+
code = "print(Threads.ngcthreads())"
393+
cpu_threads = ccall(:jl_effective_threads, Int32, ())
394+
@test string(cpu_threads) ==
395+
read(`$exename --threads auto -e $code`, String) ==
396+
read(`$exename --threads=auto -e $code`, String) ==
397+
read(`$exename -tauto -e $code`, String) ==
398+
read(`$exename -t auto -e $code`, String)
399+
for nt in (nothing, "1")
400+
withenv("JULIA_NUM_GC_THREADS" => nt) do
401+
@test read(`$exename --gcthreads=2 -e $code`, String) == "2"
402+
end
403+
withenv("JULIA_NUM_GC_THREADS" => nt) do
404+
@test read(`$exename --gcthreads=2,1 -e $code`, String) == "3"
405+
end
400406
end
401-
end
402407

403-
withenv("JULIA_NUM_GC_THREADS" => 2) do
404-
@test read(`$exename -e $code`, String) == "2"
405-
end
408+
withenv("JULIA_NUM_GC_THREADS" => 2) do
409+
@test read(`$exename -e $code`, String) == "2"
410+
end
406411

407-
withenv("JULIA_NUM_GC_THREADS" => "2,1") do
408-
@test read(`$exename -e $code`, String) == "3"
412+
withenv("JULIA_NUM_GC_THREADS" => "2,1") do
413+
@test read(`$exename -e $code`, String) == "3"
414+
end
409415
end
410416

411417
# --machine-file
@@ -1182,24 +1188,29 @@ end
11821188
end
11831189
end
11841190

1191+
# FIXME: MMTK currently does not use --heap-size-hint since it only
1192+
# supports setting up a hard limit unlike the Stock GC
1193+
# which takes it as a soft limit. For now, we skip the tests below for MMTk
11851194
@testset "heap size hint" begin
1186-
#heap-size-hint, we reserve 250 MB for non GC memory (llvm, etc.)
1187-
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=500M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "$((500-250)*1024*1024)"
1195+
if USING_STOCK_GC
1196+
#heap-size-hint, we reserve 250 MB for non GC memory (llvm, etc.)
1197+
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=500M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "$((500-250)*1024*1024)"
1198+
1199+
mem = ccall(:uv_get_total_memory, UInt64, ())
1200+
cmem = ccall(:uv_get_constrained_memory, UInt64, ())
1201+
if cmem > 0 && cmem < mem
1202+
mem = cmem
1203+
end
1204+
maxmem = parse(UInt64, readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=25% -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`))
1205+
hint = max(mem÷4, 251*1024*1024) - 250*1024*1024
1206+
MAX32HEAP = 1536 * 1024 * 1024
1207+
if Int === Int32 && hint > MAX32HEAP
1208+
hint = MAX32HEAP
1209+
end
1210+
@test abs(Float64(maxmem) - hint)/maxmem < 0.05
11881211

1189-
mem = ccall(:uv_get_total_memory, UInt64, ())
1190-
cmem = ccall(:uv_get_constrained_memory, UInt64, ())
1191-
if cmem > 0 && cmem < mem
1192-
mem = cmem
1193-
end
1194-
maxmem = parse(UInt64, readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=25% -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`))
1195-
hint = max(mem÷4, 251*1024*1024) - 250*1024*1024
1196-
MAX32HEAP = 1536 * 1024 * 1024
1197-
if Int === Int32 && hint > MAX32HEAP
1198-
hint = MAX32HEAP
1212+
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=10M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "$(1*1024*1024)"
11991213
end
1200-
@test abs(Float64(maxmem) - hint)/maxmem < 0.05
1201-
1202-
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=10M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "$(1*1024*1024)"
12031214
end
12041215

12051216
## `Main.main` entrypoint

test/gc.jl

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
using Test
44

5+
const USING_STOCK_GC = occursin("stock", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ())))
6+
57
function run_gctest(file)
68
let cmd = `$(Base.julia_cmd()) --depwarn=error --rr-detach --startup-file=no $file`
79
@testset for test_nthreads in (1, 2, 4)
@@ -18,10 +20,12 @@ function run_gctest(file)
1820
end
1921

2022
function run_nonzero_page_utilization_test()
21-
GC.gc()
22-
page_utilization = Base.gc_page_utilization_data()
23-
# at least one of the pools should have nonzero page_utilization
24-
@test any(page_utilization .> 0)
23+
if USING_STOCK_GC
24+
GC.gc()
25+
page_utilization = Base.gc_page_utilization_data()
26+
# at least one of the pools should have nonzero page_utilization
27+
@test any(page_utilization .> 0)
28+
end
2529
end
2630

2731
function run_pg_size_test()
@@ -35,25 +39,29 @@ function issue_54275_alloc_string()
3539
end
3640

3741
function issue_54275_test()
38-
GC.gc(true)
39-
baseline = Base.gc_live_bytes()
40-
live_bytes_has_grown_too_much = false
41-
for _ in 1:10
42-
issue_54275_alloc_string()
42+
if USING_STOCK_GC
4343
GC.gc(true)
44-
if Base.gc_live_bytes() - baseline > 1_000_000
45-
live_bytes_has_grown_too_much = true
46-
break
44+
baseline = Base.gc_live_bytes()
45+
live_bytes_has_grown_too_much = false
46+
for _ in 1:10
47+
issue_54275_alloc_string()
48+
GC.gc(true)
49+
if Base.gc_live_bytes() - baseline > 1_000_000
50+
live_bytes_has_grown_too_much = true
51+
break
52+
end
4753
end
54+
@test !live_bytes_has_grown_too_much
4855
end
49-
@test !live_bytes_has_grown_too_much
5056
end
5157

5258
function full_sweep_reasons_test()
53-
GC.gc()
54-
reasons = Base.full_sweep_reasons()
55-
@test reasons[:FULL_SWEEP_REASON_FORCED_FULL_SWEEP] >= 1
56-
@test keys(reasons) == Set(Base.FULL_SWEEP_REASONS)
59+
if USING_STOCK_GC
60+
GC.gc()
61+
reasons = Base.full_sweep_reasons()
62+
@test reasons[:FULL_SWEEP_REASON_FORCED_FULL_SWEEP] >= 1
63+
@test keys(reasons) == Set(Base.FULL_SWEEP_REASONS)
64+
end
5765
end
5866

5967
# !!! note:

test/misc.jl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,24 +1453,28 @@ end
14531453
@test_throws ErrorException finalizer(x->nothing, 1)
14541454
@test_throws ErrorException finalizer(C_NULL, 1)
14551455

1456+
const USING_STOCK_GC = occursin("stock", unsafe_string(ccall(:jl_gc_active_impl, Ptr{UInt8}, ())))
14561457

14571458
@testset "GC utilities" begin
1458-
GC.gc()
1459-
GC.gc(true); GC.gc(false)
1460-
1461-
GC.safepoint()
1462-
1463-
mktemp() do tmppath, _
1464-
open(tmppath, "w") do tmpio
1465-
redirect_stderr(tmpio) do
1466-
GC.enable_logging(true)
1467-
@test GC.logging_enabled()
1468-
GC.gc()
1469-
GC.enable_logging(false)
1470-
@test !GC.logging_enabled()
1459+
# Test is specific to Stock GC
1460+
if USING_STOCK_GC
1461+
GC.gc()
1462+
GC.gc(true); GC.gc(false)
1463+
1464+
GC.safepoint()
1465+
1466+
mktemp() do tmppath, _
1467+
open(tmppath, "w") do tmpio
1468+
redirect_stderr(tmpio) do
1469+
GC.enable_logging(true)
1470+
@test GC.logging_enabled()
1471+
GC.gc()
1472+
GC.enable_logging(false)
1473+
@test !GC.logging_enabled()
1474+
end
14711475
end
1476+
@test occursin("GC: pause", read(tmppath, String))
14721477
end
1473-
@test occursin("GC: pause", read(tmppath, String))
14741478
end
14751479
end
14761480

0 commit comments

Comments
 (0)