From: Junio C Hamano <junkio@cox.net>
From: Junio C Hamano <junkio@cox.net>
To: git@vger.kernel.org
Cc: linux@horizon.com
Subject: From b65bc21e7d8dc8cafc70dfa6354cb66b8874b2d9 Mon Sep 17 00:00:00 2001
Subject: [PATCH] Makefile: add framework to verify and bench sha1 implementations.
Date: Sat, 24 Jun 2006 00:59:49 -0700 [thread overview]
Message-ID: <7v3bdv0xyd.fsf_-_@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <7vfyhv11ej.fsf@assigned-by-dhcp.cox.net> (Junio C. Hamano's message of "Sat, 24 Jun 2006 00:03:00 -0700")
With this, you can say
MOZILLA_SHA1=YesPlease make check-sha1
to see how fast your favorite SHA-1 implementation is and if it
fails with small to huge inputs.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
* As the maintainer, I do need people to see breakage before it
happens, without having access to all the platforms, hence
this.
Makefile | 6 ++++
test-sha1.c | 24 +++++++++++++++++
test-sha1.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 113 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
index e29e3fa..ea0044d 100644
--- a/Makefile
+++ b/Makefile
@@ -636,6 +636,12 @@ test-delta$X: test-delta.c diff-delta.o
test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
+test-sha1$X: test-sha1.o $(GITLIBS)
+ $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
+
+check-sha1:: test-sha1$X
+ ./test-sha1.sh
+
check:
for i in *.c; do sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; done
diff --git a/test-sha1.c b/test-sha1.c
new file mode 100644
index 0000000..2efc315
--- /dev/null
+++ b/test-sha1.c
@@ -0,0 +1,24 @@
+#include "cache.h"
+
+int main(int ac, char **av)
+{
+ SHA_CTX ctx;
+ unsigned char sha1[20];
+
+ SHA1_Init(&ctx);
+
+ while (1) {
+ ssize_t sz;
+ char buffer[8192];
+ sz = xread(0, buffer, sizeof(buffer));
+ if (sz == 0)
+ break;
+ if (sz < 0)
+ die("test-sha1: %s", strerror(errno));
+ SHA1_Update(&ctx, buffer, sz);
+ }
+ SHA1_Final(sha1, &ctx);
+ puts(sha1_to_hex(sha1));
+ exit(0);
+}
+
diff --git a/test-sha1.sh b/test-sha1.sh
new file mode 100755
index 0000000..01bbb57
--- /dev/null
+++ b/test-sha1.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+dd if=/dev/zero bs=1048576 count=100 2>/dev/null |
+/usr/bin/time ./test-sha1 >/dev/null
+
+while read expect cnt pfx
+do
+ case "$expect" in '#'*) continue ;; esac
+ actual=`
+ {
+ test -z "$pfx" || echo "$pfx"
+ dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
+ tr '[\0]' '[g]'
+ } | ./test-sha1
+ `
+ if test "$expect" = "$actual"
+ then
+ echo "OK: $expect $cnt $pfx"
+ else
+ echo >&2 "OOPS: $cnt"
+ echo >&2 "expect: $expect"
+ echo >&2 "actual: $actual"
+ exit 1
+ fi
+done <<EOF
+da39a3ee5e6b4b0d3255bfef95601890afd80709 0
+3f786850e387550fdab836ed7e6dc881de23001b 0 a
+5277cbb45a15902137d332d97e89cf8136545485 0 ab
+03cfd743661f07975fa2f1220c5194cbaff48451 0 abc
+3330b4373640f9e4604991e73c7e86bfd8da2dc3 0 abcd
+ec11312386ad561674f724b8cca7cf1796e26d1d 0 abcde
+bdc37c074ec4ee6050d68bc133c6b912f36474df 0 abcdef
+69bca99b923859f2dc486b55b87f49689b7358c7 0 abcdefg
+e414af7161c9554089f4106d6f1797ef14a73666 0 abcdefgh
+0707f2970043f9f7c22029482db27733deaec029 0 abcdefghi
+a4dd8aa74a5636728fe52451636e2e17726033aa 1
+9986b45e2f4d7086372533bb6953a8652fa3644a 1 frotz
+23d8d4f788e8526b4877548a32577543cbaaf51f 10
+8cd23f822ab44c7f481b8c92d591f6d1fcad431c 10 frotz
+f3b5604a4e604899c1233edb3bf1cc0ede4d8c32 512
+b095bd837a371593048136e429e9ac4b476e1bb3 512 frotz
+08fa81d6190948de5ccca3966340cc48c10cceac 1200 xyzzy
+e33a291f42c30a159733dd98b8b3e4ff34158ca0 4090 4G
+#a3bf783bc20caa958f6cb24dd140a7b21984838d 9999 nitfol
+EOF
+
+exit
+
+# generating test vectors
+# inputs are number of megabytes followed by some random string to prefix.
+
+while read cnt pfx
+do
+ actual=`
+ {
+ test -z "$pfx" || echo "$pfx"
+ dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
+ tr '[\0]' '[g]'
+ } | sha1sum |
+ sed -e 's/ .*//'
+ `
+ echo "$actual $cnt $pfx"
+done <<EOF
+0
+0 a
+0 ab
+0 abc
+0 abcd
+0 abcde
+0 abcdef
+0 abcdefg
+0 abcdefgh
+0 abcdefghi
+1
+1 frotz
+10
+10 frotz
+512
+512 frotz
+1200 xyzzy
+4090 4G
+9999 nitfol
+EOF
--
1.4.1.rc1.g0fca
next prev parent reply other threads:[~2006-06-24 8:17 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-23 17:18 x86 asm SHA1 (draft) linux
2006-06-24 0:18 ` Junio C Hamano
2006-06-24 1:22 ` linux
2006-06-24 7:03 ` Junio C Hamano
2006-06-24 7:59 ` Junio C Hamano, Junio C Hamano [this message]
2006-06-24 9:29 ` From b65bc21e7d8dc8cafc70dfa6354cb66b8874b2d9 Mon Sep 17 00:00:00 2001 [PATCH] Makefile: add framework to verify and bench sha1 implementations linux
2006-06-24 19:47 ` Junio C Hamano
2006-06-24 9:20 ` x86 asm SHA1 (draft) linux
2006-06-24 10:03 ` PPC SHA-1 Updates in "pu" Junio C Hamano
2006-06-24 18:55 ` Linus Torvalds
2006-06-24 20:21 ` Junio C Hamano
2006-06-24 20:42 ` Linus Torvalds
2006-06-24 23:59 ` Junio C Hamano
2006-06-25 1:02 ` Petr Baudis
2006-06-25 1:40 ` [PATCH] Git.pm build: Fix quoting and missing GIT-CFLAGS dependency Petr Baudis
2006-06-25 3:03 ` Junio C Hamano
2006-06-25 15:21 ` Petr Baudis
2006-06-26 6:48 ` Junio C Hamano
2006-07-01 23:59 ` [POOL] Who likes running Git without make install? Petr Baudis
2006-07-02 0:05 ` Junio C Hamano
2006-07-02 0:08 ` Junio C Hamano
2006-07-02 11:30 ` Petr Baudis
2006-07-02 17:19 ` Junio C Hamano
2006-07-03 6:54 ` [POLL] " Junio C Hamano
2006-07-03 7:58 ` Petr Baudis
2006-07-03 8:08 ` Junio C Hamano
2006-07-03 8:17 ` Petr Baudis
2006-07-03 8:37 ` Johannes Schindelin
2006-06-25 1:24 ` PPC SHA-1 Updates in "pu" Petr Baudis
2006-06-25 3:57 ` Junio C Hamano
2006-06-25 9:34 ` Petr Baudis
2006-06-25 10:07 ` Johannes Schindelin
2006-06-25 10:20 ` Petr Baudis
2006-06-25 10:48 ` Junio C Hamano
2006-06-25 13:44 ` Johannes Schindelin
2006-06-25 18:46 ` Randal L. Schwartz
2006-06-25 23:23 ` Johannes Schindelin
2006-06-26 1:51 ` perl profiling (was: PPC SHA-1 Updates in "pu") Jeff King
2006-06-26 6:49 ` PPC SHA-1 Updates in "pu" Junio C Hamano
2006-06-30 1:28 ` GIt.xs merge status Junio C Hamano
2006-06-30 5:08 ` Pavel Roskin
2006-06-30 7:18 ` Git.xs " Junio C Hamano
2006-06-30 7:28 ` Pavel Roskin
2006-06-30 9:53 ` GIt.xs " Johannes Schindelin
2006-06-30 10:26 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v3bdv0xyd.fsf_-_@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=linux@horizon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).