shithub: mc

Download patch

ref: 85f8cd1246e4df870f8767bf64f3f1fe5f006101
parent: 4c2029561abd571e9a4853f113ec776d79523c5b
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Aug 24 17:41:56 EDT 2015

Move test suite to mbld

--- a/libcryptohash/test/Makefile
+++ /dev/null
@@ -1,20 +1,0 @@
-# don't build anything for 'all'
-all: 
-	$(MAKE) -C ..
-
-check:
-	./runtest.sh
-
-.PHONY: %
-%:
-	./runtest.sh $@
-
-.PHONY: clean
-clean:
-	rm -f testmatch.use testmatch.o
-	@for i in `awk '/^[A-Z]/{print $$2}' tests`; do \
-	    echo rm -f $$i; \
-	    rm -f $$i; \
-	done
-
-install:
--- a/libcryptohash/test/data/md5-test-expected
+++ /dev/null
@@ -1,4 +1,0 @@
-d41d8cd98f00b204e9800998ecf8427e
-2510c39011c5be704182423e3a695e91
-014842d480b571495a4a0363793f7367
-3b0bb4c5ece4a6568caa7266e740a140
--- a/libcryptohash/test/data/sha1-test-expected
+++ /dev/null
@@ -1,4 +1,0 @@
-da39a3ee5e6b4b0d3255bfef60951890d8af0709
-27d5482eebd075de44389774e2fc8c695cf48a75
-0098ba824b5c16427bd7a1125a2a442aec25644d
-4eb17e52bb55910b037869438f69d9c87643d75a
--- a/libcryptohash/test/data/sha224-test-expected
+++ /dev/null
@@ -1,4 +1,0 @@
-d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f
-e0ccaeadfef916630c35576679e4cd4b438e7fc95a60b7361705f708
-a88cd5cde6d6fe9136a4e58b49167461ea95d388ca2bdb7afdc3cbf4
-4a5859b7efa22c3b25710520fc97b0a901f5cdba3e4f0becfeea725e
--- a/libcryptohash/test/data/sha256-test-expected
+++ /dev/null
@@ -1,4 +1,0 @@
-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
-aaa9402664f1a41f40ebbc52c9993eb66aeb366602958fdfaa283b71e64db123
-ffe054fe7ae0cb6dc65c3af9b61d5209f439851db43d0ba5997337df154668eb
-bac8bf0f9794a520a5bf0ec64d3206edd1b9f2ef5ea118c9cad5365d84578de4
--- a/libcryptohash/test/data/sha384-test-expected
+++ /dev/null
@@ -1,4 +1,0 @@
-38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b
-a4eb0778c79fce94c02126543cba398d645b2fd4c6ff6a02eecc026bbe0cc0dd666279722b7615bc15b4c9126b941c04
-2e404b9339da795776e510d96930b3be2904c500395b8cb7413334b82d4dec413b4b8113045a05bbbcff846f027423f6
-f8f4b55a0fb1ac8506d2e5195c714a1ad16c3bf61ad8b2d544344b105a49a77ff3b8eb61e8f970a71864e9dad87042b1
--- a/libcryptohash/test/data/sha512-test-expected
+++ /dev/null
@@ -1,4 +1,0 @@
-cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
-2241bc8fc70705b42efead371fd4982c5ba69917e5b4b895810002644f0386da9c3131793458c2bf47608480d64a07278133c99912e0ba2daf23098f3520eb97
-01d35c10c6c38c2dcf48f7eebb3235fb5ad74a65ec4cd016e2354c637a8fb49b695ef3c1d6f7ae4cd74d78cc9c9bcac9d4f23a73019998a7f73038a5c9b2dbde
-d5c989d2e41299b6bfd57562b4b09cd2efa56f13c8fa109e0ce5ddbd6bfb5b34f8563608d6162104bef750023732581f22704d5df43feecbb05742be1d7c34fa
--- a/libcryptohash/test/md5-test.myr
+++ /dev/null
@@ -1,14 +1,0 @@
-use std
-use cryptohash
-
-use "printhash.use"
-
-const main = {
-	print(cryptohash.md5("")[:])
-	print(cryptohash.md5("h")[:])
-	/* 64 byte block */
-	print(cryptohash.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:])
-	/* tail spanning */
-	print(cryptohash.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:])
-}
-
--- /dev/null
+++ b/libcryptohash/test/md5.myr
@@ -1,0 +1,18 @@
+use std
+use cryptohash
+
+use "test/util.use"
+
+const main = {
+	hasheq(cryptohash.md5("")[:], \
+		"d41d8cd98f00b204e9800998ecf8427e")
+	hasheq(cryptohash.md5("h")[:], \
+		"2510c39011c5be704182423e3a695e91")
+	/* 64 byte block */
+	hasheq(cryptohash.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
+		"014842d480b571495a4a0363793f7367")
+	/* tail spanning */
+	hasheq(cryptohash.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
+		"3b0bb4c5ece4a6568caa7266e740a140")
+}
+
--- a/libcryptohash/test/printhash.myr
+++ /dev/null
@@ -1,12 +1,0 @@
-use std
-
-pkg =
-	const print	: (b : byte[:] -> void)
-;;
-
-const print = {b
-	for x in b
-		std.put("%02xb", x)
-	;;
-        std.put("\n")
-}
--- a/libcryptohash/test/runtest.sh
+++ /dev/null
@@ -1,124 +1,0 @@
-#!/bin/bash
-NFAILURES=0
-NPASSES=0
-
-function build {
-    rm -f $1 $1.o $1.s $1.use
-    myrbuild $FLAGS -b $1 $1.myr $EXTRA_SRC
-}
-
-function pass {
-    PASSED="$PASSED $1"
-    NPASSED=$[$NPASSED + 1]
-}
-
-function fail {
-    echo "FAIL: $1"
-    FAILED="$FAILED $1"
-    NFAILED=$[$NFAILED + 1]
-}
-
-function expectstatus {
-    ./$1 $3
-    if [ $? -eq $2 ]; then
-        pass $1
-        return
-    else
-        fail $1
-    fi
-}
-
-function expectprint {
-    if [ "`./$1 $3`" != "$2" ]; then
-        fail $1
-    else
-        pass $1
-    fi
-}
-
-
-function expectcompare {
-    if [ x"" !=  x"$TMPDIR" ]; then 
-        t=$TMPDIR/myrtest-$1-$RANDOM
-    else
-        t=/tmp/myrtest-$1-$RANDOM
-    fi
-    ./$1 $3 > $t
-    if cmp $t data/$1-expected; then
-        pass $1
-    else
-        fail $1
-    fi
-    rm -f $t
-}
-
-function expectfcompare {
-    ./$1 $3
-    if cmp data/$1-expected $2; then
-        pass $1
-    else
-        fail $1
-    fi
-}
-
-function shouldskip {
-  if [ -z $ARGS ]; then
-      return 1
-  fi
-
-  for i in $ARGS; do
-      if [ $i = $1 ]; then
-          return 1
-      fi
-  done
-  return 0
-}
-
-
-# Should build and run
-function B {
-    if shouldskip $1; then
-        return
-    fi
-
-    test="$1"; shift
-    type="$1"; shift
-    res="$1"; shift
-    if [ $# > 0 ]; then
-        args="$1"; shift
-    fi
-    build $test
-    case $type in
-    "E")  expectstatus "$test" "$res" "$input";;
-    "P")  expectprint "$test" "$res" "$input";;
-    "C")  expectcompare "$test" "$res" "$input";;
-    "F")  expectfcompare "$test" "$res" "$args";;
-    esac
-}
-
-# Should fail
-function F {
-    if shouldskip $1; then
-        return
-    fi
-    (build $1) > /dev/null
-    if [ $? -eq '1' ]; then
-        pass $1
-    else
-        fail $1
-    fi
-}
-
-# Should generate a usefile
-function U {
-    return
-}
-
-source tests
-
-echo "PASSED ($NPASSED): $PASSED"
-if [ -z "$NFAILED" ]; then
-    echo "SUCCESS"
-else
-    echo "FAILURES ($NFAILED): $FAILED"
-fi
--- a/libcryptohash/test/sha1-test.myr
+++ /dev/null
@@ -1,14 +1,0 @@
-use std
-use cryptohash
-
-use "printhash.use"
-
-const main = {
-	print(cryptohash.sha1("")[:])
-	print(cryptohash.sha1("h")[:])
-	/* 64 byte block */
-	print(cryptohash.sha1("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:])
-	/* tail spanning */
-	print(cryptohash.sha1("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:])
-}
-
--- /dev/null
+++ b/libcryptohash/test/sha1.myr
@@ -1,0 +1,18 @@
+use std
+use cryptohash
+
+use "test/util.use"
+
+const main = {
+	hasheq(cryptohash.sha1("")[:], \
+		"da39a3ee5e6b4b0d3255bfef60951890d8af0709")
+	hasheq(cryptohash.sha1("h")[:], \
+		"27d5482eebd075de44389774e2fc8c695cf48a75")
+	/* 64 byte block */
+	hasheq(cryptohash.sha1("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
+		"0098ba824b5c16427bd7a1125a2a442aec25644d")
+	/* tail spanning */
+	hasheq(cryptohash.sha1("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
+		"4eb17e52bb55910b037869438f69d9c87643d75a")
+}
+
--- a/libcryptohash/test/sha224-test.myr
+++ /dev/null
@@ -1,14 +1,0 @@
-use std
-use cryptohash
-
-use "printhash.use"
-
-const main = {
-	print(cryptohash.sha224("")[:])
-	print(cryptohash.sha224("h")[:])
-	/* 64 byte block */
-	print(cryptohash.sha224("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:])
-	/* tail spanning */
-	print(cryptohash.sha224("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:])
-}
-
--- a/libcryptohash/test/sha256-test.myr
+++ /dev/null
@@ -1,14 +1,0 @@
-use std
-use cryptohash
-
-use "printhash.use"
-
-const main = {
-	print(cryptohash.sha256("")[:])
-	print(cryptohash.sha256("h")[:])
-	/* 64 byte block */
-	print(cryptohash.sha256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:])
-	/* tail spanning */
-	print(cryptohash.sha256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:])
-}
-
--- /dev/null
+++ b/libcryptohash/test/sha256.myr
@@ -1,0 +1,29 @@
+use std
+use cryptohash
+
+use "test/util.use"
+
+const main = {
+	hasheq(cryptohash.sha224("")[:], \
+		"d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f")
+	hasheq(cryptohash.sha224("h")[:], \
+		"e0ccaeadfef916630c35576679e4cd4b438e7fc95a60b7361705f708")
+	/* 64 byte block */
+	hasheq(cryptohash.sha224("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
+		"a88cd5cde6d6fe9136a4e58b49167461ea95d388ca2bdb7afdc3cbf4")
+	/* tail spanning */
+	hasheq(cryptohash.sha224("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
+		"4a5859b7efa22c3b25710520fc97b0a901f5cdba3e4f0becfeea725e")
+
+	hasheq(cryptohash.sha256("")[:], \
+		"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
+	hasheq(cryptohash.sha256("h")[:], \
+		"aaa9402664f1a41f40ebbc52c9993eb66aeb366602958fdfaa283b71e64db123")
+	/* 64 byte block */
+	hasheq(cryptohash.sha256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
+		"ffe054fe7ae0cb6dc65c3af9b61d5209f439851db43d0ba5997337df154668eb")
+	/* tail spanning */
+	hasheq(cryptohash.sha256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
+		"bac8bf0f9794a520a5bf0ec64d3206edd1b9f2ef5ea118c9cad5365d84578de4")
+}
+
--- a/libcryptohash/test/sha384-test.myr
+++ /dev/null
@@ -1,14 +1,0 @@
-use std
-use cryptohash
-
-use "printhash.use"
-
-const main = {
-	print(cryptohash.sha384("")[:])
-	print(cryptohash.sha384("h")[:])
-	/* 64 byte block */
-	print(cryptohash.sha384("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:])
-	/* tail spanning */
-	print(cryptohash.sha384("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:])
-}
-
--- a/libcryptohash/test/sha512-test.myr
+++ /dev/null
@@ -1,14 +1,0 @@
-use std
-use cryptohash
-
-use "printhash.use"
-
-const main = {
-	print(cryptohash.sha512("")[:])
-	print(cryptohash.sha512("h")[:])
-	/* 64 byte block */
-	print(cryptohash.sha512("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:])
-	/* tail spanning */
-	print(cryptohash.sha512("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:])
-}
-
--- /dev/null
+++ b/libcryptohash/test/sha512.myr
@@ -1,0 +1,29 @@
+use std
+use cryptohash
+
+use "test/util.use"
+
+const main = {
+	hasheq(cryptohash.sha384("")[:], \
+		"38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b")
+	hasheq(cryptohash.sha384("h")[:], \
+		"a4eb0778c79fce94c02126543cba398d645b2fd4c6ff6a02eecc026bbe0cc0dd666279722b7615bc15b4c9126b941c04")
+	/* 64 byte block */
+	hasheq(cryptohash.sha384("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
+		"2e404b9339da795776e510d96930b3be2904c500395b8cb7413334b82d4dec413b4b8113045a05bbbcff846f027423f6")
+	/* tail spanning */
+	hasheq(cryptohash.sha384("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
+		"f8f4b55a0fb1ac8506d2e5195c714a1ad16c3bf61ad8b2d544344b105a49a77ff3b8eb61e8f970a71864e9dad87042b1")
+
+	hasheq(cryptohash.sha512("")[:], \
+		"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e")
+	hasheq(cryptohash.sha512("h")[:], \
+		"2241bc8fc70705b42efead371fd4982c5ba69917e5b4b895810002644f0386da9c3131793458c2bf47608480d64a07278133c99912e0ba2daf23098f3520eb97")
+	/* 64 byte block */
+	hasheq(cryptohash.sha512("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:], \
+		"01d35c10c6c38c2dcf48f7eebb3235fb5ad74a65ec4cd016e2354c637a8fb49b695ef3c1d6f7ae4cd74d78cc9c9bcac9d4f23a73019998a7f73038a5c9b2dbde")
+	/* tail spanning */
+	hasheq(cryptohash.sha512("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:], \
+		"d5c989d2e41299b6bfd57562b4b09cd2efa56f13c8fa109e0ce5ddbd6bfb5b34f8563608d6162104bef750023732581f22704d5df43feecbb05742be1d7c34fa")
+}
+
--- a/libcryptohash/test/tests
+++ /dev/null
@@ -1,29 +1,0 @@
-FLAGS=-I../
-mkdir -p tmpout
-EXTRA_SRC=printhash.myr
-# Format:
-# [B|F] testname [E|P] result
-#    [B|F]: Compiler outcome.
-#	B: Expect that this test will build.
-#	F: Expect that this test will not build.
-#    testname: Test case
-#	The test that will run. We will try to
-#	compile 'testname.myr' to 'testname',
-#	and then execute it, verifying the result
-#    [E|P|C]: Result type
-#	E tells us that the result is an exit status
-#	P tells us that the result is on stdout,
-#         and should be compared to the value on the
-#         line
-#	C tells us that the result is on stdout,
-#         and should be compared to the contents of
-#         the file passed on the line.
-#    result: Result value
-#	What we compare with. This should be self-
-#	evident.
-B md5-test	C
-B sha1-test	C
-B sha256-test	C
-B sha224-test	C
-B sha512-test	C
-B sha384-test	C
--- /dev/null
+++ b/libcryptohash/test/util.myr
@@ -1,0 +1,19 @@
+use std
+
+pkg =
+	const hasheq	: (got : byte[:], expected : byte[:] -> void)
+;;
+
+const hasheq = {got, expected
+	var sb, str
+
+	sb = std.mksb()
+	for x in got
+		std.sbfmt(sb, "{p=0,w=2,x}", x)
+	;;
+	str = std.sbfin(sb)
+	if (!std.sleq(str, expected))
+		std.fatal("mismatched hashes:\n\tgot:\t{}\n\texpected:\t{}\n", str, expected)
+	;;
+	std.slfree(str)
+}