From mboxrd@z Thu Jan 1 00:00:00 1970 From: Junio C Hamano Subject: From b65bc21e7d8dc8cafc70dfa6354cb66b8874b2d9 Mon Sep 17 00:00:00 2001 Date: Sat, 24 Jun 2006 00:59:49 -0700 Message-ID: <7v3bdv0xyd.fsf_-_@assigned-by-dhcp.cox.net> References: <7vzmg376ee.fsf@assigned-by-dhcp.cox.net> <20060624012202.4822.qmail@science.horizon.com> <7vfyhv11ej.fsf@assigned-by-dhcp.cox.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux@horizon.com X-From: git-owner@vger.kernel.org Sat Jun 24 10:17:44 2006 Return-path: Envelope-to: gcvg-git@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Fu3Kl-0003h2-SK for gcvg-git@gmane.org; Sat, 24 Jun 2006 10:17:40 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751249AbWFXIRf (ORCPT ); Sat, 24 Jun 2006 04:17:35 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S933305AbWFXIRe (ORCPT ); Sat, 24 Jun 2006 04:17:34 -0400 Received: from fed1rmmtao11.cox.net ([68.230.241.28]:35745 "EHLO fed1rmmtao11.cox.net") by vger.kernel.org with ESMTP id S933267AbWFXIRb (ORCPT ); Sat, 24 Jun 2006 04:17:31 -0400 Received: from assigned-by-dhcp.cox.net ([68.4.9.127]) by fed1rmmtao11.cox.net (InterMail vM.6.01.06.01 201-2131-130-101-20060113) with ESMTP id <20060624081731.POV554.fed1rmmtao11.cox.net@assigned-by-dhcp.cox.net>; Sat, 24 Jun 2006 04:17:31 -0400 From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH] Makefile: add framework to verify and bench sha1 implementations. In-Reply-To: <7vfyhv11ej.fsf@assigned-by-dhcp.cox.net> (Junio C. Hamano's message of "Sat, 24 Jun 2006 00:03:00 -0700") User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Sender: git-owner@vger.kernel.org Precedence: bulk X-Mailing-List: git@vger.kernel.org Archived-At: 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 --- * 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 </dev/null | + tr '[\0]' '[g]' + } | sha1sum | + sed -e 's/ .*//' + ` + echo "$actual $cnt $pfx" +done <