Skip to content

Commit

Permalink
Skipping some tests that are currently incompatible with MMTk
Browse files Browse the repository at this point in the history
  • Loading branch information
udesou committed Jan 20, 2025
1 parent cbc47c9 commit 874d41d
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 85 deletions.
43 changes: 27 additions & 16 deletions stdlib/Profile/test/allocs.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Test
using Profile: Allocs

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

Allocs.clear()
let iobuf = IOBuffer()
for format in (:tree, :flat)
Expand Down Expand Up @@ -73,8 +75,12 @@ end
@test length(first_alloc.stacktrace) > 0
@test length(string(first_alloc.type)) > 0

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

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

# FIXME: We currently do not call the allocation profiler
# in the fastpath allocation for MMTk in codegen. Therefore, this
# test has been disabled for MMTk.
@testset "alloc profiler catches allocs from codegen" begin
@eval begin
struct MyType x::Int; y::Int end
Base.:(+)(n::Number, x::MyType) = n + x.x + x.y
foo(a, x) = a[1] + x
wrapper(a) = foo(a, MyType(0,1))
end
a = Any[1,2,3]
# warmup
wrapper(a)
if USING_STOCK_GC
@eval begin
struct MyType x::Int; y::Int end
Base.:(+)(n::Number, x::MyType) = n + x.x + x.y
foo(a, x) = a[1] + x
wrapper(a) = foo(a, MyType(0,1))
end
a = Any[1,2,3]
# warmup
wrapper(a)

@eval Allocs.@profile sample_rate=1 wrapper($a)
@eval Allocs.@profile sample_rate=1 wrapper($a)

prof = Allocs.fetch()
Allocs.clear()
prof = Allocs.fetch()
Allocs.clear()

@test length(prof.allocs) >= 1
@test length([a for a in prof.allocs if a.type == MyType]) >= 1
@test length(prof.allocs) >= 1
@test length([a for a in prof.allocs if a.type == MyType]) >= 1
end
end

@testset "alloc profiler catches allocs from buffer resize" begin
Expand Down
46 changes: 26 additions & 20 deletions stdlib/Profile/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,35 +344,41 @@ end
@test only(node.down).first == lidict[8]
end

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

# FIXME: This test that expects specific information from
# heap snapshots, which is currently supported in MMTk
@testset "HeapSnapshot" begin
tmpdir = mktempdir()
if USING_STOCK_GC
tmpdir = mktempdir()

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

@test isfile(fname)
@test isfile(fname)

sshot = read(fname, String)
@test sshot != ""
@test contains(sshot, "redact_this")
sshot = read(fname, String)
@test sshot != ""
@test contains(sshot, "redact_this")

rm(fname)
rm(fname)

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

@test isfile(fname)
@test isfile(fname)

sshot = read(fname, String)
@test sshot != ""
@test !contains(sshot, "redact_this")
sshot = read(fname, String)
@test sshot != ""
@test !contains(sshot, "redact_this")

rm(fname)
rm(tmpdir, force = true, recursive = true)
rm(fname)
rm(tmpdir, force = true, recursive = true)
end
end

@testset "PageProfile" begin
Expand Down
81 changes: 46 additions & 35 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ let
@test format_filename("%a%%b") == "a%b"
end

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

@testset "julia_cmd" begin
julia_basic = Base.julia_cmd()
function get_julia_cmd(arg)
Expand Down Expand Up @@ -383,29 +385,33 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
@test p.exitcode == 1 && p.termsignal == 0
end

# --gcthreads
code = "print(Threads.ngcthreads())"
cpu_threads = ccall(:jl_effective_threads, Int32, ())
@test string(cpu_threads) ==
read(`$exename --threads auto -e $code`, String) ==
read(`$exename --threads=auto -e $code`, String) ==
read(`$exename -tauto -e $code`, String) ==
read(`$exename -t auto -e $code`, String)
for nt in (nothing, "1")
withenv("JULIA_NUM_GC_THREADS" => nt) do
@test read(`$exename --gcthreads=2 -e $code`, String) == "2"
end
withenv("JULIA_NUM_GC_THREADS" => nt) do
@test read(`$exename --gcthreads=2,1 -e $code`, String) == "3"
# FIXME: --gc-threads does not have the same semantics
# for Stock GC and MMTk, so the tests below are specific to the Stock GC
if USING_STOCK_GC
# --gcthreads
code = "print(Threads.ngcthreads())"
cpu_threads = ccall(:jl_effective_threads, Int32, ())
@test string(cpu_threads) ==
read(`$exename --threads auto -e $code`, String) ==
read(`$exename --threads=auto -e $code`, String) ==
read(`$exename -tauto -e $code`, String) ==
read(`$exename -t auto -e $code`, String)
for nt in (nothing, "1")
withenv("JULIA_NUM_GC_THREADS" => nt) do
@test read(`$exename --gcthreads=2 -e $code`, String) == "2"
end
withenv("JULIA_NUM_GC_THREADS" => nt) do
@test read(`$exename --gcthreads=2,1 -e $code`, String) == "3"
end
end
end

withenv("JULIA_NUM_GC_THREADS" => 2) do
@test read(`$exename -e $code`, String) == "2"
end
withenv("JULIA_NUM_GC_THREADS" => 2) do
@test read(`$exename -e $code`, String) == "2"
end

withenv("JULIA_NUM_GC_THREADS" => "2,1") do
@test read(`$exename -e $code`, String) == "3"
withenv("JULIA_NUM_GC_THREADS" => "2,1") do
@test read(`$exename -e $code`, String) == "3"
end
end

# --machine-file
Expand Down Expand Up @@ -1182,24 +1188,29 @@ end
end
end

# FIXME: MMTK currently does not use --heap-size-hint since it only
# supports setting up a hard limit unlike the Stock GC
# which takes it as a soft limit. For now, we skip the tests below for MMTk
@testset "heap size hint" begin
#heap-size-hint, we reserve 250 MB for non GC memory (llvm, etc.)
@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)"
if USING_STOCK_GC
#heap-size-hint, we reserve 250 MB for non GC memory (llvm, etc.)
@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)"

mem = ccall(:uv_get_total_memory, UInt64, ())
cmem = ccall(:uv_get_constrained_memory, UInt64, ())
if cmem > 0 && cmem < mem
mem = cmem
end
maxmem = parse(UInt64, readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=25% -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`))
hint = max(mem÷4, 251*1024*1024) - 250*1024*1024
MAX32HEAP = 1536 * 1024 * 1024
if Int === Int32 && hint > MAX32HEAP
hint = MAX32HEAP
end
@test abs(Float64(maxmem) - hint)/maxmem < 0.05

mem = ccall(:uv_get_total_memory, UInt64, ())
cmem = ccall(:uv_get_constrained_memory, UInt64, ())
if cmem > 0 && cmem < mem
mem = cmem
end
maxmem = parse(UInt64, readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=25% -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`))
hint = max(mem÷4, 251*1024*1024) - 250*1024*1024
MAX32HEAP = 1536 * 1024 * 1024
if Int === Int32 && hint > MAX32HEAP
hint = MAX32HEAP
@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=10M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "$(1*1024*1024)"
end
@test abs(Float64(maxmem) - hint)/maxmem < 0.05

@test readchomp(`$(Base.julia_cmd()) --startup-file=no --heap-size-hint=10M -e "println(@ccall jl_gc_get_max_memory()::UInt64)"`) == "$(1*1024*1024)"
end

## `Main.main` entrypoint
Expand Down
32 changes: 18 additions & 14 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1453,24 +1453,28 @@ end
@test_throws ErrorException finalizer(x->nothing, 1)
@test_throws ErrorException finalizer(C_NULL, 1)

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

@testset "GC utilities" begin
GC.gc()
GC.gc(true); GC.gc(false)

GC.safepoint()

mktemp() do tmppath, _
open(tmppath, "w") do tmpio
redirect_stderr(tmpio) do
GC.enable_logging(true)
@test GC.logging_enabled()
GC.gc()
GC.enable_logging(false)
@test !GC.logging_enabled()
# Test is specific to Stock GC
if USING_STOCK_GC
GC.gc()
GC.gc(true); GC.gc(false)

GC.safepoint()

mktemp() do tmppath, _
open(tmppath, "w") do tmpio
redirect_stderr(tmpio) do
GC.enable_logging(true)
@test GC.logging_enabled()
GC.gc()
GC.enable_logging(false)
@test !GC.logging_enabled()
end
end
@test occursin("GC: pause", read(tmppath, String))
end
@test occursin("GC: pause", read(tmppath, String))
end
end

Expand Down

0 comments on commit 874d41d

Please sign in to comment.