summaryrefslogtreecommitdiff
path: root/source/test/unittests/atomic.test.c
diff options
context:
space:
mode:
authorMitya Selivanov <0x7fffff@guattari.ru>2022-08-14 04:50:43 +0400
committerMitya Selivanov <0x7fffff@guattari.ru>2022-08-14 04:50:43 +0400
commit117001b8986d46040da5c7b07330b5fb99fc7f70 (patch)
tree96508e21d552d496ebb31baca354b64e6b2eb4ec /source/test/unittests/atomic.test.c
parent0b1c0f3eb647a7630b473bfec75a3411dab89583 (diff)
downloadkit-117001b8986d46040da5c7b07330b5fb99fc7f70.zip
thread, atomic
Diffstat (limited to 'source/test/unittests/atomic.test.c')
-rw-r--r--source/test/unittests/atomic.test.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/source/test/unittests/atomic.test.c b/source/test/unittests/atomic.test.c
new file mode 100644
index 0000000..9f1a10b
--- /dev/null
+++ b/source/test/unittests/atomic.test.c
@@ -0,0 +1,26 @@
+#include "../../kit/atomic.h"
+
+#define KIT_TEST_FILE atomic
+#include "../../kit_test/test.h"
+
+TEST("atomic store and load") {
+ ATOMIC(int) value;
+ atomic_store_explicit(&value, 20, memory_order_relaxed);
+ REQUIRE(atomic_load_explicit(&value, memory_order_relaxed) == 20);
+}
+
+TEST("atomic exchange") {
+ ATOMIC(int) value;
+ atomic_store_explicit(&value, 20, memory_order_relaxed);
+ REQUIRE(atomic_exchange_explicit(&value, 42,
+ memory_order_relaxed) == 20);
+ REQUIRE(atomic_load_explicit(&value, memory_order_relaxed) == 42);
+}
+
+TEST("atomic fetch add") {
+ ATOMIC(int) value;
+ atomic_store_explicit(&value, 20, memory_order_relaxed);
+ REQUIRE(atomic_fetch_add_explicit(&value, 22,
+ memory_order_relaxed) == 20);
+ REQUIRE(atomic_load_explicit(&value, memory_order_relaxed) == 42);
+}