summaryrefslogtreecommitdiff
path: root/testsuite/tests/rts/pause-resume
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/rts/pause-resume')
-rw-r--r--testsuite/tests/rts/pause-resume/all.T5
-rw-r--r--testsuite/tests/rts/pause-resume/list_threads_and_misc_roots.hs6
-rw-r--r--testsuite/tests/rts/pause-resume/list_threads_and_misc_roots_c.c54
-rw-r--r--testsuite/tests/rts/pause-resume/list_threads_and_misc_roots_c.h5
4 files changed, 70 insertions, 0 deletions
diff --git a/testsuite/tests/rts/pause-resume/all.T b/testsuite/tests/rts/pause-resume/all.T
index 3099a8f12c..88c6f6e483 100644
--- a/testsuite/tests/rts/pause-resume/all.T
+++ b/testsuite/tests/rts/pause-resume/all.T
@@ -18,3 +18,8 @@ test('pause_and_use_rts_api',
, extra_files(['pause_resume.c','pause_resume.h'])
],
multi_compile_and_run, ['pause_and_use_rts_api', [('pause_resume.c','')], ''])
+test('list_threads_and_misc_roots',
+ [ only_ways(['threaded1', 'threaded2'])
+ , extra_files(['list_threads_and_misc_roots_c.c','list_threads_and_misc_roots_c.h'])
+ ],
+ multi_compile_and_run, ['list_threads_and_misc_roots', [('list_threads_and_misc_roots_c.c','')], '']) \ No newline at end of file
diff --git a/testsuite/tests/rts/pause-resume/list_threads_and_misc_roots.hs b/testsuite/tests/rts/pause-resume/list_threads_and_misc_roots.hs
new file mode 100644
index 0000000000..1de3fa926b
--- /dev/null
+++ b/testsuite/tests/rts/pause-resume/list_threads_and_misc_roots.hs
@@ -0,0 +1,6 @@
+
+foreign import ccall safe "list_threads_and_misc_roots_c.h checkGcRoots"
+ checkGcRoots :: IO ()
+
+main :: IO ()
+main = checkGcRoots
diff --git a/testsuite/tests/rts/pause-resume/list_threads_and_misc_roots_c.c b/testsuite/tests/rts/pause-resume/list_threads_and_misc_roots_c.c
new file mode 100644
index 0000000000..634bab75e2
--- /dev/null
+++ b/testsuite/tests/rts/pause-resume/list_threads_and_misc_roots_c.c
@@ -0,0 +1,54 @@
+
+#include "list_threads_and_misc_roots_c.h"
+
+static int tsoCount = 0;
+static StgTSO** tsos;
+
+static int miscRootsCount = 0;
+static StgClosure** miscRoots;
+
+void collectTSOsCallback(void *user, StgTSO* tso){
+ tsoCount++;
+ tsos = realloc(tsos, sizeof(StgTSO*) * tsoCount);
+ tsos[tsoCount - 1] = tso;
+}
+
+void collectMiscRootsCallback(void *user, StgClosure* closure){
+ miscRootsCount++;
+ miscRoots = realloc(miscRoots, sizeof(StgClosure*) * miscRootsCount);
+ miscRoots[miscRootsCount - 1] = closure;
+}
+
+void checkGcRoots(void)
+{
+ PauseToken * token = rts_pause();
+
+ // Check TSO collection.
+ rts_listThreads(&collectTSOsCallback, NULL);
+ for (int i = 0; i < tsoCount; i++)
+ {
+ StgTSO *tso = UNTAG_CLOSURE(tsos[i]);
+ if (get_itbl(tso)->type != TSO)
+ {
+ fprintf(stderr, "tso returned a non-TSO type %zu at index %i\n",
+ tso->header.info->type,
+ i);
+ exit(1);
+ }
+ }
+
+ // Check misc GC roots collection.
+ rts_listMiscRoots(&collectMiscRootsCallback, NULL);
+ for (int i = 0; i < miscRootsCount; i++)
+ {
+ StgClosure *root = UNTAG_CLOSURE(miscRoots[i]);
+ if (get_itbl(root)->type == TSO)
+ {
+ fprintf(stderr, "rts_listThreads unexpectedly returned an TSO type at index %i (TSO=%zu)\n", i, TSO);
+ exit(1);
+ }
+ }
+
+
+ rts_resume(token);
+}
diff --git a/testsuite/tests/rts/pause-resume/list_threads_and_misc_roots_c.h b/testsuite/tests/rts/pause-resume/list_threads_and_misc_roots_c.h
new file mode 100644
index 0000000000..408c3a79ca
--- /dev/null
+++ b/testsuite/tests/rts/pause-resume/list_threads_and_misc_roots_c.h
@@ -0,0 +1,5 @@
+
+#include "Rts.h"
+#include "RtsAPI.h"
+
+void checkGcRoots(void);