shithub: mc

Download patch

ref: b39e8ca0f806bd6a76f378373cb4d27fcf028190
parent: 17cb502c1578b8e1a94f02b84cf47acfef6b20b1
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Mar 24 18:35:40 EDT 2018

Improve test runner test filtering.

	Filter on what the user sees. Before, we would use the
	internal target names, which bore a resemblance to the
	target names used by the user, but they didn't match
	perfectly.

	This led to unintuitive behavior. Now, we filter on
	a substring of the test name matching. So, you can
	do something like:

		mbld test crypto/sha3

	instead of

		mbld test lib/bio/test:delim

	In addition, not all tests had an explicit target, and
	these would be impossible to match on.

	Still left to do is adding subtest patterns.

--- a/lib/crypto/bld.sub
+++ b/lib/crypto/bld.sub
@@ -22,6 +22,7 @@
 
 	# utilities for subtle bits
 	ct.myr
+	ctbig.myr
 	clear.myr
 
 	lib ../std:std
--- a/lib/crypto/ctbig.myr
+++ b/lib/crypto/ctbig.myr
@@ -9,6 +9,8 @@
 	;;
 
 	generic mkctbign 	: (v : @a, nbit : std.size -> ctbig#) :: numeric,integral @a
+
+	const ctzero	: (nbit : std.size -> ctbig#)
 	const mkctbigle	: (v : byte[:], nbit : std.size -> ctbig#)
 	//const mkctbigbe	: (v : byte[:], nbit : std.size -> ctbig#)
 
@@ -16,13 +18,13 @@
 	const ctbigdup	: (v : ctbig# -> ctbig#)
 	const ctlike	: (v : ctbig# -> ctbig#)
 	const ct2big	: (v : ctbig# -> std.bigint#)
-	const big2ct	: (v : std.bigint#, ndig : std.size -> ctbig#)
+	const big2ct	: (v : std.bigint#, nbit : std.size -> ctbig#)
 
 	const ctadd	: (r : ctbig#, a : ctbig#, b : ctbig# -> void)
 	const ctsub	: (r : ctbig#, a : ctbig#, b : ctbig# -> void)
 	const ctmul	: (r : ctbig#, a : ctbig#, b : ctbig# -> void)
 	//const ctdivmod	: (r : ctbig#, m : ctbig#, a : ctbig#, b : ctbig# -> void)
-	//const ctmodpow	: (r : ctbig#, a : ctbig#, b : ctbig# -> void)
+	const ctmodpow	: (r : ctbig#, a : ctbig#, b : ctbig# -> void)
 
 	const ctiszero	: (v : ctbig# -> bool)
 	const cteq	: (a : ctbig#, b : ctbig# -> bool)
@@ -33,6 +35,7 @@
 	const ctle	: (a : ctbig#, b : ctbig# -> bool)
 ;;
 
+const Bits = 32
 const Base = 0x100000000ul
 
 generic mkctbign = {v : @a, nbit : std.size :: integral,numeric @a
@@ -50,9 +53,16 @@
 	if nbit > 32
 		a.dig[1] = (val >> 32 : uint32)
 	;;
-	-> a
+	-> clip(a)
 }
 
+const ctzero = {nbit
+	-> std.mk([
+		.nbit=nbit,
+		.dig=std.slalloc(ndig(nbit)),
+	])
+}
+
 const ct2big = {ct
 	-> std.mk([
 		.sign=1,
@@ -67,10 +77,10 @@
 	l = std.min(n, ct.dig.len)
 	v = std.slzalloc(n)
 	std.slcp(v, ct.dig[:l])
-	-> std.mk([
+	-> clip(std.mk([
 		.nbit=nbit,
 		.dig=v,
-	])
+	]))
 }
 
 const mkctbigle = {v, nbit
@@ -96,7 +106,7 @@
 		last |= (v[off] : uint32) << (8 *off)
 	;;
 	a[o++] = last
-	-> std.mk([.nbit=nbit, .dig=a])
+	-> clip(std.mk([.nbit=nbit, .dig=a]))
 }
 
 const ctlike = {v
@@ -146,6 +156,7 @@
 		v = mux(borrow, v + Base, v)
 		r.dig[i] = (v  : uint32)
 	;;
+	clip(r)
 }
 
 const ctmul = {r, a, b
@@ -176,18 +187,19 @@
 		std.slfree(a.dig)
 	;;
 	r.dig = w[:a.dig.len]
+	clip(r)
 }
 
-//const ctmodpow = {res, a, b
-//	/* find rinv, mprime */
-//	
-//	/* convert to monty space */
-//
-//	/* do the modpow */
-//
-//	/* and come back */
-//}
+const ctmodpow = {res, a, b
+	/* find rinv, mprime */
+	
+	/* convert to monty space */
 
+	/* do the modpow */
+
+	/* and come back */
+}
+
 const ctiszero = {a
 	var z, zz
 
@@ -269,4 +281,14 @@
 const checksz = {a, b
 	std.assert(a.nbit == b.nbit, "mismatched bit sizes")
 	std.assert(a.dig.len == b.dig.len, "mismatched backing sizes")
+}
+
+const clip = {v
+	var mask, edge
+	
+
+	edge = v.nbit & (Bits - 1)
+	mask = (1 << edge) - 1
+	v.dig[v.dig.len - 1] &= (mask : uint32)
+	-> v
 }
--- a/mbld/test.myr
+++ b/mbld/test.myr
@@ -28,21 +28,11 @@
 	if !buildtarg(b, kind)
 		std.exit(1)
 	;;
-	if targs.len == 0
-		tests = std.htgetv(b.deps.targs, kind, [][:])
-	else
-		tests = [][:]
-		for t : targs
-			match std.htget(b.deps.targs, t)
-			| `std.Some tl:	std.sljoin(&tests, tl)
-			| `std.None:	std.fatal("unknown test {}\n", t)
-			;;
-		;;
-	;;
+	tests = std.htgetv(b.deps.targs, kind, [][:])
 	ok = true
 	failed = [][:]
 	for t : tests
-		if !runtest(b, t, isbench, &failed)
+		if !runtest(b, t, targs, isbench, &failed)
 			ok = false
 		;;
 	;;
@@ -71,10 +61,19 @@
 	;;
 }
 
-const runtest = {b, n, isbench, failed
+const runtest = {b, n, targs, isbench, failed
 	var dir, res, log, logfd
-	var sub
+	var sub, found
 
+	if targs.len > 0
+		found = false
+		for t : targs
+			found = found || matchtest(n.lbl, t)
+		;;
+		if !found
+			-> true
+		;;
+	;;
 	mbldput("run {}: ", n.lbl)
 	dir = std.pathcat(b.basedir, n.wdir)
 	std.chdir(dir)
@@ -116,3 +115,13 @@
 	-> res
 }
 
+const matchtest = {name, pat
+	match std.strfind(pat, ":")
+	| `std.Some i:	pat = pat[:i]
+	| `std.None:	/* ok */
+	;;
+	match std.strfind(name, pat)
+	| `std.Some _:	-> true
+	| `std.None:	-> false
+	;;
+}