shithub: mc

Download patch

ref: b4a8cf6eb24355953d0510d74a19966938907de8
parent: ab327dfacd49c61feb0311e064c79bee7e8aec27
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Sep 17 16:34:06 EDT 2015

Update tests.

--- a/lib/thread/bld.proj
+++ b/lib/thread/bld.proj
@@ -10,6 +10,3 @@
 	atomic.myr
 ;;
 
-test smoketest =
-	smoketest.myr
-;;
--- a/lib/thread/smoketest.myr
+++ /dev/null
@@ -1,68 +1,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))
-	;;
-}
--- /dev/null
+++ b/lib/thread/test/atomic.myr
@@ -1,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)
+}
+
--- /dev/null
+++ b/lib/thread/test/mutex.myr
@@ -1,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)
+}
--- /dev/null
+++ b/lib/thread/test/util.myr
@@ -1,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))
+	;;
+}