[Git][ghc/ghc][wip/T22012] testsuite: Add simple test exercising C11 atomics in GHCi
Ben Gamari (@bgamari)
gitlab at gitlab.haskell.org
Thu Aug 31 20:16:24 UTC 2023
Ben Gamari pushed to branch wip/T22012 at Glasgow Haskell Compiler / GHC
Commits:
9a24e016 by Ben Gamari at 2023-08-31T16:16:13-04:00
testsuite: Add simple test exercising C11 atomics in GHCi
See #22012.
- - - - -
4 changed files:
- + testsuite/tests/rts/T22012.hs
- + testsuite/tests/rts/T22012.stdout
- + testsuite/tests/rts/T22012_c.c
- testsuite/tests/rts/all.T
Changes:
=====================================
testsuite/tests/rts/T22012.hs
=====================================
@@ -0,0 +1,10 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+
+module Test where
+import Foreign.C.Types
+
+foreign import ccall unsafe "test" c_test :: IO CInt
+
+main = c_test >>= print
+
+
=====================================
testsuite/tests/rts/T22012.stdout
=====================================
@@ -0,0 +1,11 @@
++# CAS
++success=1
++old=42
++x=43
++# Swap
++x=2
++y=43
++# Fetch-Add
++x=4
++y=2
+
=====================================
testsuite/tests/rts/T22012_c.c
=====================================
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdatomic.h>
+#include <stdbool.h>
+
+void test (void) {
+ _Atomic uint32_t x = 42;
+ uint32_t y = 42;
+
+ bool success = atomic_compare_exchange_strong(&x, &y, 43);
+ printf("# CAS\n");
+ printf("success=%u\n", (int) success);
+ printf("old=%u\n", y);
+ printf("x=%u\n", x);
+
+ printf("# Swap\n");
+ y = atomic_exchange(&x, 2);
+ printf("x=%u\n", x);
+ printf("y=%u\n", y);
+
+ printf("# Fetch-Add\n");
+ y = atomic_fetch_add(&x, 2);
+ printf("x=%u\n", x);
+ printf("y=%u\n", y);
+}
+
=====================================
testsuite/tests/rts/all.T
=====================================
@@ -581,6 +581,8 @@ test('decodeMyStack_emptyListForMissingFlag',
, js_broken(22261) # cloneMyStack# not yet implemented
], compile_and_run, [''])
+test('T22012', extra_ways(['ghci']), compile_and_run, ['T22012_c.c'])
+
# Skip for JS platform as the JS RTS is always single threaded
test('T22795a', [only_ways(['normal']), js_skip, req_ghc_with_threaded_rts], compile_and_run, ['-threaded'])
test('T22795b', [only_ways(['normal']), js_skip], compile_and_run, ['-single-threaded'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9a24e01677d798cb40dd185963be3e2a232b092f
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9a24e01677d798cb40dd185963be3e2a232b092f
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230831/e0eb7732/attachment-0001.html>
More information about the ghc-commits
mailing list