summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2013-05-04 11:56:34 +0200
committerIvan Maidanski <ivmai@mail.ru>2013-05-04 11:56:34 +0200
commit67393532be3ed80d7b59fc453e6ba91953c50b91 (patch)
treee2fe6b27c0a1b9675b90823f1c99375fd2064476
parent16c986bd775c1490ec1d09a41cf69159e0b95b05 (diff)
Enable staticrootstest for the case of GC shared library build
* tests/staticrootslib.c (GC_TEST_EXPORT_API): New macro (defined to set GCC default visibility attribute if GC_VISIBILITY_HIDDEN_SET unless Win32). * tests/staticrootslib.c (root): Remove unused global variable. * tests/staticrootslib.c (libsrl_mktree, libsrl_init): Decorate with GC_TEST_EXPORT_API. * tests/staticrootstest.c (GC_VISIBILITY_HIDDEN_SET): Do not check (do not skip the test). * tests/staticrootstest.c (GC_TEST_IMPORT_API): New macro. * tests/staticrootstest.c (root): Explicitly specify zero initializer. * tests/staticrootstest.c (libsrl_mktree, libsrl_init): Decorate with GC_TEST_IMPORT_API. * tests/staticrootstest.c (mktree, main): Remove commented out code. * tests/staticrootstest.c (main): Avoid code duplication. * tests/tests.am (staticrootstest_LDADD, check_LTLIBRARIES, libstaticrootslib_la): Rename libstaticrootslib to libstaticrootslib_test.
-rw-r--r--tests/staticrootslib.c16
-rw-r--r--tests/staticrootstest.c70
-rw-r--r--tests/tests.am13
3 files changed, 42 insertions, 57 deletions
diff --git a/tests/staticrootslib.c b/tests/staticrootslib.c
index 2a8fcd4..c80d79c 100644
--- a/tests/staticrootslib.c
+++ b/tests/staticrootslib.c
@@ -9,12 +9,22 @@
#include "gc.h"
+#ifndef GC_TEST_EXPORT_API
+# if defined(GC_VISIBILITY_HIDDEN_SET) \
+ && !defined(__CEGCC__) && !defined(__CYGWIN__) && !defined(__MINGW32__)
+# define GC_TEST_EXPORT_API \
+ extern __attribute__((__visibility__("default")))
+# else
+# define GC_TEST_EXPORT_API extern
+# endif
+#endif
+
struct treenode {
struct treenode *x;
struct treenode *y;
-} * root[10];
+};
-struct treenode * libsrl_mktree(int i)
+GC_TEST_EXPORT_API struct treenode * libsrl_mktree(int i)
{
struct treenode * r = GC_MALLOC(sizeof(struct treenode));
if (0 == i) return 0;
@@ -26,7 +36,7 @@ struct treenode * libsrl_mktree(int i)
return r;
}
-void * libsrl_init(void)
+GC_TEST_EXPORT_API void * libsrl_init(void)
{
GC_INIT();
return GC_MALLOC(sizeof(struct treenode));
diff --git a/tests/staticrootstest.c b/tests/staticrootstest.c
index 5d5cb3e..162f02b 100644
--- a/tests/staticrootstest.c
+++ b/tests/staticrootstest.c
@@ -9,33 +9,27 @@
#include "gc.h"
#include "gc_backptr.h"
-#ifndef GC_VISIBILITY_HIDDEN_SET
+#ifndef GC_TEST_IMPORT_API
+# define GC_TEST_IMPORT_API extern
+#endif
+/* Should match that in staticrootslib.c. */
struct treenode {
struct treenode *x;
struct treenode *y;
-} * root[10];
+};
-static char *staticroot = 0;
+struct treenode *root[10] = { NULL };
-extern struct treenode * libsrl_mktree(int i);
-extern void * libsrl_init(void);
+static char *staticroot = 0;
-/*
-struct treenode * mktree(int i) {
- struct treenode * r = GC_MALLOC(sizeof(struct treenode));
- if (0 == i) return 0;
- if (1 == i) r = GC_MALLOC_ATOMIC(sizeof(struct treenode));
- r -> x = mktree(i-1);
- r -> y = mktree(i-1);
- return r;
-}*/
+GC_TEST_IMPORT_API struct treenode * libsrl_mktree(int i);
+GC_TEST_IMPORT_API void * libsrl_init(void);
int main(void)
{
- int i;
- /*GC_INIT();
- staticroot = GC_MALLOC(sizeof(struct treenode));*/
+ int i, j;
+
staticroot = libsrl_init();
if (NULL == staticroot) {
fprintf(stderr, "GC_malloc returned NULL\n");
@@ -43,37 +37,17 @@ int main(void)
}
memset(staticroot, 0x42, sizeof(struct treenode));
GC_gcollect();
- for (i = 0; i < 10; ++i) {
- root[i] = libsrl_mktree(12);
- GC_gcollect();
+ for (j = 0; j < 2; j++) {
+ for (i = 0; i < 10; ++i) {
+ 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;
+ }
+ }
}
- for (i = 0; i < (int)sizeof(struct treenode); ++i) {
- if (staticroot[i] != 0x42) {
- fprintf(stderr, "Memory check failed\n");
- return -1;
- }
- }
- for (i = 0; i < 10; ++i) {
- 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;
- }
- }
- return 0;
-}
-
-#else
-
-/* Skip since symbols defined in staticrootslib are not visible */
-
-int main(void)
-{
- printf("staticrootstest skipped\n");
return 0;
}
-
-#endif
diff --git a/tests/tests.am b/tests/tests.am
index 85999ec..b63e0b3 100644
--- a/tests/tests.am
+++ b/tests/tests.am
@@ -48,12 +48,13 @@ realloc_test_LDADD = $(test_ldadd)
TESTS += staticrootstest$(EXEEXT)
check_PROGRAMS += staticrootstest
staticrootstest_SOURCES = tests/staticrootstest.c
-staticrootstest_LDADD = $(test_ldadd) libstaticrootslib.la
-check_LTLIBRARIES += libstaticrootslib.la
-libstaticrootslib_la_SOURCES = tests/staticrootslib.c
-libstaticrootslib_la_LIBADD = $(test_ldadd)
-libstaticrootslib_la_LDFLAGS = -version-info 1:3:0 -no-undefined -rpath /nowhere
-libstaticrootslib_la_DEPENDENCIES = $(top_builddir)/libgc.la
+staticrootstest_LDADD = $(test_ldadd) libstaticrootslib_test.la
+check_LTLIBRARIES += libstaticrootslib_test.la
+libstaticrootslib_test_la_SOURCES = tests/staticrootslib.c
+libstaticrootslib_test_la_LIBADD = $(test_ldadd)
+libstaticrootslib_test_la_LDFLAGS = -version-info 1:3:0 -no-undefined \
+ -rpath /nowhere
+libstaticrootslib_test_la_DEPENDENCIES = $(top_builddir)/libgc.la
if KEEP_BACK_PTRS
TESTS += tracetest$(EXEEXT)