diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-02-07 08:39:44 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-02-07 11:45:25 +0300 |
commit | 4a5c9217b48ae3d491de88dd2c6998a055a31284 (patch) | |
tree | 7c588de7a4ee14e9c6977859e14acdab9e342942 /tests/staticroots.c | |
parent | 5c1625c8e60d7de2cde59708b16f2a330a78b0c3 (diff) | |
download | bdwgc-4a5c9217b48ae3d491de88dd2c6998a055a31284.tar.gz |
Name all tests consistently
(refactoring)
In brief, the tests naming as follows: all test executable files end
with "test" (not "_test"); all test source files do not have "test"
suffix (except for gctest); test.c is named now as gctest.c.
* CMakeLists.txt: Rename leak_test.c to leak.c; rename huge_test.c to
huge.c; rename leak_test.c to leak.c; rename realloc_test.c to
realloc.c; rename smash_test.c to smash.c; rename staticrootslib.c to
staticroots_lib.c; rename trace_test.c to trace.c; rename
thread_leak_test.c to threadleak.c; rename threadkey_test to
threadkey_test; rename threadkey_test.c to threadkey.c; rename
subthreadcreate_test to subthreadcreatetest; rename subthread_create.c
to subthreadcreate.c; rename initsecondarythread_test to
initfromthreadtest; rename initsecondarythread.c to initfromthread.c;
rename disclaim_test to disclaimtest; rename disclaim_test.c to
disclaim.c; rename disclaim_weakmap_test to weakmaptest; rename
disclaim_weakmap_test.c to weakmap.c.
* tests/tests.am: Likewise.
* CMakeLists.txt: Rename test.c to gctest.c; rename test_cpp to
cpptest; rename test_cpp.cc to cpp.cc.
* Makefile.direct: Likewise.
* NT_MAKEFILE: Likewise.
* README.md (Installation and Portability): Likewise.
* WCC_MAKEFILE: Likewise.
* digimars.mak: Likewise.
* doc/README.Mac: Likewise.
* tests/tests.am: Likewise.
* CMakeLists.txt: rename test_atomic_ops.c to atomicops.c; rename
test_atomic_ops to atomicopstest.
* configure.ac [$with_libatomic_ops=check]: Likewise.
* ChangeLog (8.3.0): Rename threadkey_test to threadkeytest; rename
test_atomic_ops to atomicopstest; rename test_cpp to cpptest.
* Makefile.direct: Rename test.o to gctest.o.
* NT_MAKEFILE: Rename test_cpp.exe to cpptest.exe; rename test.obj to
gctest.obj.
* WCC_MAKEFILE: Likewise.
* digimars.mak: Likewise.
* doc/README.win64: Likewise.
* configure.ac: Rename test_cpp to cpptest in comment.
* doc/leak.md: Rename leak_test.c to leak.c.
* tests/test_atomic_ops.c: Rename to atomicops.c; remove test name in
"skipped" message.
* tests/test_cpp.cc: Rename to cpp.cc; rename test_cpp to cpptest.
* tests/disclaim_test.c: Rename to disclaim.c.
* tests/test.c: Rename to gctest.c.
* tests/huge_test.c: Rename to huge.c.
* tests/initsecondarythread.c: Rename to initfromthread.c.
* tests/leak_test.c: Rename to leak.c.
* tests/realloc_test.c: Rename to realloc.c.
* tests/smash_test.c: Rename to smash.c.
* tests/staticrootstest.c: Rename to staticroots.c.
* tests/staticrootslib.c: Rename to staticroots_lib.c.
* tests/subthread_create.c: Rename to subthreadcreate.c; remove test
name in printed messages.
* tests/threadkey_test.c: Rename to threadkey.c; remove test name in
"skipped" message.
* tests/thread_leak_test.c: Rename to threadleak.c.
* tests/trace_test.c: Rename to trace.c.
* tests/disclaim_weakmap_test.c: Rename to weakmap.c; rename
disclaim_test.c to disclaim.c in comment.
Diffstat (limited to 'tests/staticroots.c')
-rw-r--r-- | tests/staticroots.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/staticroots.c b/tests/staticroots.c new file mode 100644 index 00000000..cac863da --- /dev/null +++ b/tests/staticroots.c @@ -0,0 +1,78 @@ + +#include <stdio.h> +#include <string.h> + +#ifndef GC_DEBUG +# define GC_DEBUG +#endif + +#include "gc.h" +#include "gc/gc_backptr.h" + +#ifndef GC_TEST_IMPORT_API +# define GC_TEST_IMPORT_API extern +#endif + +/* Should match that in staticroots_lib.c. */ +struct treenode { + struct treenode *x; + struct treenode *y; +}; + +struct treenode *root[10] = { NULL }; + +/* Same as "root" variable but initialized to some non-zero value (to */ +/* be placed to .data section instead of .bss). */ +struct treenode *root_nz[10] = { (struct treenode *)(GC_word)1 }; + +static char *staticroot; /* intentionally static */ + +GC_TEST_IMPORT_API struct treenode * libsrl_mktree(int i); +GC_TEST_IMPORT_API void * libsrl_init(void); +GC_TEST_IMPORT_API struct treenode ** libsrl_getpelem(int i, int j); + +GC_TEST_IMPORT_API struct treenode ** libsrl_getpelem2(int i, int j); + +void init_staticroot(void) +{ + /* Intentionally put staticroot initialization in a function other */ + /* than main to prevent CSA warning that staticroot variable can be */ + /* changed to be a local one). */ + staticroot = (char *)libsrl_init(); +} + +int main(void) +{ + int i, j; + +# ifdef STATICROOTSLIB_INIT_IN_MAIN + GC_INIT(); +# endif + init_staticroot(); + if (GC_get_find_leak()) + printf("This test program is not designed for leak detection mode\n"); + if (NULL == staticroot) { + fprintf(stderr, "GC_malloc returned NULL\n"); + return 2; + } + memset(staticroot, 0x42, sizeof(struct treenode)); + GC_gcollect(); + for (j = 0; j < 4; j++) { + for (i = 0; i < (int)(sizeof(root) / sizeof(root[0])); ++i) { +# ifdef STATICROOTSLIB2 + *libsrl_getpelem2(i, j) = libsrl_mktree(12); +# endif + *libsrl_getpelem(i, j) = libsrl_mktree(12); + ((j & 1) != 0 ? root_nz : root)[i] = libsrl_mktree(12); + GC_gcollect(); + } + for (i = 0; i < (int)sizeof(struct treenode); ++i) { + if (staticroot[i] != 0x42) { + fprintf(stderr, "Memory check failed\n"); + return 1; + } + } + } + printf("SUCCEEDED\n"); + return 0; +} |