Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
fix regression tests for fixed Issue 15513
Browse files Browse the repository at this point in the history
- the existing tls GC test weren't working b/c the scanned stack region
  still contained references to the allocated values
  • Loading branch information
MartinNowak committed Mar 13, 2016
1 parent bbd797a commit 09419a1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 16 deletions.
35 changes: 25 additions & 10 deletions test/shared/src/lib.d
Expand Up @@ -26,6 +26,28 @@ void tls_alloc() { tls_root = new Object(); }
void tls_access() { assert(tls_root.toString() !is null); } // vtbl call will fail if finalized
void tls_free() { tls_root = null; }

void stack(alias func)()
{
// allocate some extra stack space to not keep references to GC memory on the scanned stack
ubyte[1024] buf = void;
func();
}

void testGC()
{
import core.memory;

stack!alloc();
stack!tls_alloc();
stack!access();
stack!tls_access();
GC.collect();
stack!tls_access();
stack!access();
stack!tls_free();
stack!free();
}

// test Init
import core.atomic : atomicOp;
shared uint shared_static_ctor, shared_static_dtor, static_ctor, static_dtor;
Expand All @@ -45,7 +67,7 @@ extern(C) int runTests()

void runTestsImpl()
{
import core.memory, core.thread;
import core.thread;

bool passed;
try
Expand All @@ -55,22 +77,15 @@ void runTestsImpl()
assert(passed);
assert(collectException({throwException();}) !is null);

alloc();
tls_alloc();
access();
tls_access();
GC.collect();
tls_access();
access();
tls_free();
free();
testGC();

assert(shared_static_ctor == 1);
assert(static_ctor == 1);
static void run()
{
assert(static_ctor == 2);
assert(shared_static_ctor == 1);
testGC();
}
auto thr = new Thread(&run);
thr.start();
Expand Down
40 changes: 34 additions & 6 deletions test/shared/src/plugin.d
@@ -1,15 +1,44 @@
import core.thread, core.memory, core.atomic;

// test init
shared uint gctor, gdtor, tctor, tdtor;
shared static this() { if (atomicOp!"+="(gctor, 1) != 1) assert(0); }
shared static ~this() { if (atomicOp!"+="(gdtor, 1) != 1) assert(0); }
static this() { atomicOp!"+="(tctor, 1); }
static ~this() { atomicOp!"+="(tdtor, 1); }

Thread t;
// test GC
__gshared Object root;
void alloc() { root = new Object(); }
void access() { assert(root.toString() !is null); } // vtbl call will fail if finalized
void free() { root = null; }

void launchThread() { (t = new Thread({})).start(); }
void joinThread() { t.join(); }
Object tls_root;
void tls_alloc() { tls_root = new Object(); }
void tls_access() { assert(tls_root.toString() !is null); } // vtbl call will fail if finalized
void tls_free() { tls_root = null; }

void stack(alias func)()
{
// allocate some extra stack space to not keep references to GC memory on the scanned stack
ubyte[1024] buf = void;
func();
}

void testGC()
{
import core.memory;

stack!alloc();
stack!tls_alloc();
stack!access();
stack!tls_access();
GC.collect();
stack!tls_access();
stack!access();
stack!tls_free();
stack!free();
}

extern(C) int runTests()
{
Expand All @@ -20,9 +49,8 @@ extern(C) int runTests()
assert(atomicLoad!(MemoryOrder.acq)(tctor) >= 1);
assert(atomicLoad!(MemoryOrder.acq)(tdtor) >= 0);
// test some runtime functionality
launchThread();
GC.collect();
joinThread();
testGC();
new Thread(&testGC).start.join;
}
catch (Throwable)
{
Expand Down

0 comments on commit 09419a1

Please sign in to comment.