xref: /netbsd-src/external/gpl3/gcc/dist/libphobos/testsuite/libphobos.shared/link.d (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
1*181254a7Smrg import lib;
2*181254a7Smrg 
testEH()3*181254a7Smrg void testEH()
4*181254a7Smrg {
5*181254a7Smrg     bool passed;
6*181254a7Smrg     try
7*181254a7Smrg         lib.throwException();
8*181254a7Smrg     catch (Exception e)
9*181254a7Smrg         passed = true;
10*181254a7Smrg     assert(passed); passed = false;
11*181254a7Smrg 
12*181254a7Smrg     assert(lib.collectException({throw new Exception(null);}) !is null);
13*181254a7Smrg     assert(lib.collectException({lib.throwException();}) !is null);
14*181254a7Smrg }
15*181254a7Smrg 
testGC()16*181254a7Smrg void testGC()
17*181254a7Smrg {
18*181254a7Smrg     import core.memory;
19*181254a7Smrg     lib.alloc();
20*181254a7Smrg     lib.tls_alloc();
21*181254a7Smrg     lib.access();
22*181254a7Smrg     lib.tls_access();
23*181254a7Smrg     GC.collect();
24*181254a7Smrg     lib.tls_access();
25*181254a7Smrg     lib.access();
26*181254a7Smrg     lib.tls_free();
27*181254a7Smrg     lib.free();
28*181254a7Smrg }
29*181254a7Smrg 
30*181254a7Smrg import core.atomic : atomicOp;
this()31*181254a7Smrg shared static this() { assert(lib.shared_static_ctor == 1); }
~this()32*181254a7Smrg shared static ~this() { assert(lib.shared_static_dtor == 0); }
33*181254a7Smrg shared uint static_ctor, static_dtor;
this()34*181254a7Smrg static this() { assert(lib.static_ctor == atomicOp!"+="(static_ctor, 1)); }
~this()35*181254a7Smrg static ~this() { assert(lib.static_dtor + 1 == atomicOp!"+="(static_dtor, 1)); }
36*181254a7Smrg 
testInit()37*181254a7Smrg void testInit()
38*181254a7Smrg {
39*181254a7Smrg     import core.thread;
40*181254a7Smrg 
41*181254a7Smrg     assert(lib.static_ctor == 1);
42*181254a7Smrg     assert(lib.static_dtor == 0);
43*181254a7Smrg     static void foo()
44*181254a7Smrg     {
45*181254a7Smrg         assert(lib.shared_static_ctor == 1);
46*181254a7Smrg         assert(lib.shared_static_dtor == 0);
47*181254a7Smrg         assert(lib.static_ctor == 2);
48*181254a7Smrg         assert(lib.static_dtor == 0);
49*181254a7Smrg     }
50*181254a7Smrg     auto thr = new Thread(&foo);
51*181254a7Smrg     thr.start();
52*181254a7Smrg     assert(thr.join() is null);
53*181254a7Smrg     assert(lib.shared_static_ctor == 1);
54*181254a7Smrg     assert(lib.shared_static_dtor == 0);
55*181254a7Smrg     assert(lib.static_ctor == 2);
56*181254a7Smrg     assert(lib.static_dtor == 1);
57*181254a7Smrg }
58*181254a7Smrg 
main()59*181254a7Smrg void main()
60*181254a7Smrg {
61*181254a7Smrg     testEH();
62*181254a7Smrg     testGC();
63*181254a7Smrg     testInit();
64*181254a7Smrg }
65