test-sha1.shon commit Merge branch 'jc/push' (5bcbc7f)
   1#!/bin/sh
   2
   3dd if=/dev/zero bs=1048576 count=100 2>/dev/null |
   4/usr/bin/time ./test-sha1 >/dev/null
   5
   6while read expect cnt pfx
   7do
   8        case "$expect" in '#'*) continue ;; esac
   9        actual=`
  10                {
  11                        test -z "$pfx" || echo "$pfx"
  12                        dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
  13                        tr '[\0]' '[g]'
  14                } | ./test-sha1 $cnt
  15        `
  16        if test "$expect" = "$actual"
  17        then
  18                echo "OK: $expect $cnt $pfx"
  19        else
  20                echo >&2 "OOPS: $cnt"
  21                echo >&2 "expect: $expect"
  22                echo >&2 "actual: $actual"
  23                exit 1
  24        fi
  25done <<EOF
  26da39a3ee5e6b4b0d3255bfef95601890afd80709 0
  273f786850e387550fdab836ed7e6dc881de23001b 0 a
  285277cbb45a15902137d332d97e89cf8136545485 0 ab
  2903cfd743661f07975fa2f1220c5194cbaff48451 0 abc
  303330b4373640f9e4604991e73c7e86bfd8da2dc3 0 abcd
  31ec11312386ad561674f724b8cca7cf1796e26d1d 0 abcde
  32bdc37c074ec4ee6050d68bc133c6b912f36474df 0 abcdef
  3369bca99b923859f2dc486b55b87f49689b7358c7 0 abcdefg
  34e414af7161c9554089f4106d6f1797ef14a73666 0 abcdefgh
  350707f2970043f9f7c22029482db27733deaec029 0 abcdefghi
  36a4dd8aa74a5636728fe52451636e2e17726033aa 1
  379986b45e2f4d7086372533bb6953a8652fa3644a 1 frotz
  3823d8d4f788e8526b4877548a32577543cbaaf51f 10
  398cd23f822ab44c7f481b8c92d591f6d1fcad431c 10 frotz
  40f3b5604a4e604899c1233edb3bf1cc0ede4d8c32 512
  41b095bd837a371593048136e429e9ac4b476e1bb3 512 frotz
  4208fa81d6190948de5ccca3966340cc48c10cceac 1200 xyzzy
  43e33a291f42c30a159733dd98b8b3e4ff34158ca0 4090 4G
  44#a3bf783bc20caa958f6cb24dd140a7b21984838d 9999 nitfol
  45EOF
  46
  47exit
  48
  49# generating test vectors
  50# inputs are number of megabytes followed by some random string to prefix.
  51
  52while read cnt pfx
  53do
  54        actual=`
  55                {
  56                        test -z "$pfx" || echo "$pfx"
  57                        dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
  58                        tr '[\0]' '[g]'
  59                } | sha1sum |
  60                sed -e 's/ .*//'
  61        `
  62        echo "$actual $cnt $pfx"
  63done <<EOF
  640
  650 a
  660 ab
  670 abc
  680 abcd
  690 abcde
  700 abcdef
  710 abcdefg
  720 abcdefgh
  730 abcdefghi
  741
  751 frotz
  7610
  7710 frotz
  78512
  79512 frotz
  801200 xyzzy
  814090 4G
  829999 nitfol
  83EOF