[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:12:24 UTC 2023



Ben Gamari pushed to branch wip/T22012 at Glasgow Haskell Compiler / GHC


Commits:
cd702c39 by Ben Gamari at 2023-08-31T16:12:08-04:00
testsuite: Add simple test exercising C11 atomics in GHCi

See #22012.

- - - - -


3 changed files:

- + testsuite/tests/rts/T22012.hs
- + 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_c.c
=====================================
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdatomic.h>
+#include <stdbool.h>
+
+int 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);
+
+    return 0;
+}
+


=====================================
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/cd702c3986d5849127321aef8f24aebff512c065

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cd702c3986d5849127321aef8f24aebff512c065
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/f07377c9/attachment-0001.html>


More information about the ghc-commits mailing list