Skip to content

Commit

Permalink
Fix GCExt test (JuliaLang#47699)
Browse files Browse the repository at this point in the history
* Add test/gcext to out-of-tree
* Disable gcext test that uses jl_gc_internal_obj_base_ptr
  • Loading branch information
vchuravy committed Nov 27, 2022
1 parent 60668c5 commit 5495b8d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ all: debug release
# sort is used to remove potential duplicates
DIRS := $(sort $(build_bindir) $(build_depsbindir) $(build_libdir) $(build_private_libdir) $(build_libexecdir) $(build_includedir) $(build_includedir)/julia $(build_sysconfdir)/julia $(build_datarootdir)/julia $(build_datarootdir)/julia/stdlib $(build_man1dir))
ifneq ($(BUILDROOT),$(JULIAHOME))
BUILDDIRS := $(BUILDROOT) $(addprefix $(BUILDROOT)/,base src src/flisp src/support src/clangsa cli doc deps stdlib test test/clangsa test/embedding test/llvmpasses)
BUILDDIRS := $(BUILDROOT) $(addprefix $(BUILDROOT)/,base src src/flisp src/support src/clangsa cli doc deps stdlib test test/clangsa test/embedding test/gcext test/llvmpasses)
BUILDDIRMAKE := $(addsuffix /Makefile,$(BUILDDIRS)) $(BUILDROOT)/sysimage.mk
DIRS += $(BUILDDIRS)
$(BUILDDIRMAKE): | $(BUILDDIRS)
Expand Down
2 changes: 2 additions & 0 deletions src/julia_gcext.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ JL_DLLEXPORT int jl_gc_conservative_gc_support_enabled(void);
// external allocations may not all be valid objects and that for those,
// the user *must* validate that they have a proper type, i.e. that
// jl_typeof(obj) is an actual type object.
//
// NOTE: Only valid to call from within a GC context.
JL_DLLEXPORT jl_value_t *jl_gc_internal_obj_base_ptr(void *p);

// Return a non-null pointer to the start of the stack area if the task
Expand Down
20 changes: 10 additions & 10 deletions test/gcext/LocalTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ function set_aux_root(n :: Int, x :: String)
return ccall(:set_aux_root, Nothing, (UInt, String), n, x)
end

function internal_obj_scan(p :: Any)
if ccall(:internal_obj_scan, Cint, (Any,), p) == 0
global internal_obj_scan_failures += 1
end
end
# function internal_obj_scan(p :: Any)
# if ccall(:internal_obj_scan, Cint, (Any,), p) == 0
# global internal_obj_scan_failures += 1
# end
# end

global internal_obj_scan_failures = 0
# global internal_obj_scan_failures = 0

for i in 0:1000
set_aux_root(i, string(i))
Expand All @@ -70,12 +70,12 @@ function test()
local stack = make()
for i in 1:100000
push(stack, string(i, base=2))
internal_obj_scan(top(stack))
# internal_obj_scan(top(stack))
end
for i in 1:1000
local stack2 = make()
internal_obj_scan(stack2)
internal_obj_scan(blob(stack2))
# internal_obj_scan(stack2)
# internal_obj_scan(blob(stack2))
while !empty(stack)
push(stack2, pop(stack))
end
Expand All @@ -98,5 +98,5 @@ end
print(gc_counter_full(), " full collections.\n")
print(gc_counter_inc(), " partial collections.\n")
print(num_obj_sweeps(), " object sweeps.\n")
print(internal_obj_scan_failures, " internal object scan failures.\n")
# print(internal_obj_scan_failures, " internal object scan failures.\n")
print(corrupted_roots, " corrupted auxiliary roots.\n")
2 changes: 1 addition & 1 deletion test/gcext/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $(BIN)/gcext-debug$(EXE): $(SRCDIR)/gcext.c
ifneq ($(abspath $(BIN)),$(abspath $(SRCDIR)))
# for demonstration purposes, our demo code is also installed
# in $BIN, although this would likely not be typical
$(BIN)/LocalModule.jl: $(SRCDIR)/LocalModule.jl
$(BIN)/LocalTest.jl: $(SRCDIR)/LocalTest.jl
cp $< $@
endif

Expand Down
11 changes: 7 additions & 4 deletions test/gcext/gcext-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ end
errlines = fetch(err_task)
lines = fetch(out_task)
@test length(errlines) == 0
@test length(lines) == 6
# @test length(lines) == 6
@test length(lines) == 5
@test checknum(lines[2], r"([0-9]+) full collections", n -> n >= 10)
@test checknum(lines[3], r"([0-9]+) partial collections", n -> n > 0)
@test checknum(lines[4], r"([0-9]+) object sweeps", n -> n > 0)
@test checknum(lines[5], r"([0-9]+) internal object scan failures",
n -> n == 0)
@test checknum(lines[6], r"([0-9]+) corrupted auxiliary roots",
# @test checknum(lines[5], r"([0-9]+) internal object scan failures",
# n -> n == 0)
# @test checknum(lines[6], r"([0-9]+) corrupted auxiliary roots",
# n -> n == 0)
@test checknum(lines[5], r"([0-9]+) corrupted auxiliary roots",
n -> n == 0)
end
1 change: 1 addition & 0 deletions test/gcext/gcext.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ static size_t gc_alloc_size(jl_value_t *val)

int internal_obj_scan(jl_value_t *val)
{
// FIXME: `jl_gc_internal_obj_base_ptr` is not allowed to be called from outside GC
if (jl_gc_internal_obj_base_ptr(val) == val) {
size_t size = gc_alloc_size(val);
char *addr = (char *)val;
Expand Down

0 comments on commit 5495b8d

Please sign in to comment.