summaryrefslogtreecommitdiff
path: root/lib/thread
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-09-17 20:34:06 -0700
committerOri Bernstein <ori@eigenstate.org>2015-09-17 20:34:06 -0700
commitb4a8cf6eb24355953d0510d74a19966938907de8 (patch)
treec0d431b99d75ddace216f930344ed2793bafba15 /lib/thread
parentab327dfacd49c61feb0311e064c79bee7e8aec27 (diff)
downloadmc-b4a8cf6eb24355953d0510d74a19966938907de8.tar.gz
Update tests.
Diffstat (limited to 'lib/thread')
-rw-r--r--lib/thread/bld.proj3
-rw-r--r--lib/thread/smoketest.myr68
-rw-r--r--lib/thread/test/atomic.myr30
-rw-r--r--lib/thread/test/mutex.myr34
-rw-r--r--lib/thread/test/util.myr12
5 files changed, 76 insertions, 71 deletions
diff --git a/lib/thread/bld.proj b/lib/thread/bld.proj
index 3e9e3b1..84295f3 100644
--- a/lib/thread/bld.proj
+++ b/lib/thread/bld.proj
@@ -10,6 +10,3 @@ lib thread =
atomic.myr
;;
-test smoketest =
- smoketest.myr
-;;
diff --git a/lib/thread/smoketest.myr b/lib/thread/smoketest.myr
deleted file mode 100644
index c98ebe7..0000000
--- a/lib/thread/smoketest.myr
+++ /dev/null
@@ -1,68 +0,0 @@
-use std
-use sys
-use thread
-
-var val : uint64 = 0
-var done : uint32 = 0
-var mtx : thread.mutex
-
-const Nherd = 20
-
-const main = {
- atomictest()
- mtxtest()
-}
-
-
-const atomictest = {
- done = 0
- val = 0
- mkherd(Nherd, atomicincvar)
- while thread.xget(&done) != Nherd
- /* nothing */
- ;;
- std.assert(val == 20_000_000, "atomics are broken\n")
-}
-
-const atomicincvar = {
- var i
-
- for i = 0; i < 1_000_000; i++
- thread.xadd(&val, 1)
- ;;
- std.write(1, "done\n")
- thread.xadd(&done, 1)
-}
-
-
-const mtxincvar = {
- var i
-
- for i = 0; i < 100_000; i++
- thread.mtxlock(&mtx)
- val++
- thread.mtxunlock(&mtx)
- ;;
- std.write(1, "done\n")
- thread.xadd(&done, 1)
-}
-
-const mtxtest = {
- done = 0
- val = 0
-
- mtx = thread.mkmtx()
- mkherd(Nherd, mtxincvar)
- while thread.xget(&done) != Nherd
- /* nothing */
- ;;
- if val != 100_000 * 20
- std.fatal("mutexes are broken, got {}\n", val)
- ;;
-}
-
-const mkherd = {n, fn
- for var i = 0; i < n; i++
- std.try(thread.spawn(fn))
- ;;
-}
diff --git a/lib/thread/test/atomic.myr b/lib/thread/test/atomic.myr
new file mode 100644
index 0000000..a6f72c6
--- /dev/null
+++ b/lib/thread/test/atomic.myr
@@ -0,0 +1,30 @@
+use std
+use thread
+
+use "test/util.use"
+
+const Nherd = 20
+
+var val : uint64 = 0
+var done : uint32 = 0
+
+const main = {
+ done = 0
+ val = 0
+ mkherd(Nherd, incvar)
+ while thread.xget(&done) != Nherd
+ /* nothing */
+ ;;
+ std.assert(val == 20_000_000, "atomics are broken\n")
+}
+
+const incvar = {
+ var i
+
+ for i = 0; i < 1_000_000; i++
+ thread.xadd(&val, 1)
+ ;;
+ std.write(1, "done\n")
+ thread.xadd(&done, 1)
+}
+
diff --git a/lib/thread/test/mutex.myr b/lib/thread/test/mutex.myr
new file mode 100644
index 0000000..e971490
--- /dev/null
+++ b/lib/thread/test/mutex.myr
@@ -0,0 +1,34 @@
+use std
+use thread
+
+use "test/util.use"
+
+const Nherd = 20
+
+var val : uint64 = 0
+var done : uint32 = 0
+var mtx : thread.mutex
+
+const main = {
+ done = 0
+ val = 0
+
+ mtx = thread.mkmtx()
+ mkherd(Nherd, incvar)
+ while thread.xget(&done) != Nherd
+ /* nothing */
+ ;;
+ if val != 100_000 * 20
+ std.fatal("mutexes are broken, got {}\n", val)
+ ;;
+}
+
+const incvar = {
+ for var i = 0; i < 100_000; i++
+ thread.mtxlock(&mtx)
+ val++
+ thread.mtxunlock(&mtx)
+ ;;
+ std.write(1, "done\n")
+ thread.xadd(&done, 1)
+}
diff --git a/lib/thread/test/util.myr b/lib/thread/test/util.myr
new file mode 100644
index 0000000..610a095
--- /dev/null
+++ b/lib/thread/test/util.myr
@@ -0,0 +1,12 @@
+use std
+use thread
+
+pkg =
+ const mkherd : (n : uint32, fn : (-> void) ->void)
+;;
+
+const mkherd = {n, fn
+ for var i = 0; i < n; i++
+ std.try(thread.spawn(fn))
+ ;;
+}