md5sum.tests 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. # Used by {ms5,shaN}sum
  3. # We pipe texts 0...999 bytes long, {md5,shaN}sum them,
  4. # then {md5,shaN}sum the resulting list.
  5. # Then we compare the result with expected result.
  6. #
  7. # Here are the expected results:
  8. # efe30c482e0b687e0cca0612f42ca29b
  9. # d41337e834377140ae7f98460d71d908598ef04f
  10. # 8e1d3ed57ebc130f0f72508446559eeae06451ae6d61b1e8ce46370cfb8963c3
  11. # fe413e0f177324d1353893ca0772ceba83fd41512ba63895a0eebb703ef9feac2fb4e92b2cb430b3bda41b46b0cb4ea8307190a5cc795157cfb680a9cd635d0f
  12. if ! test "$1"; then
  13. set -- md5sum efe30c482e0b687e0cca0612f42ca29b
  14. fi
  15. sum="$1"
  16. expected="$2"
  17. test -f "$bindir/.config" && . "$bindir/.config"
  18. test x"$CONFIG_FEATURE_FANCY_HEAD" != x"y" \
  19. && { echo "SKIPPED: $sum"; exit 0; }
  20. FAILCOUNT=0
  21. text="The quick brown fox jumps over the lazy dog"
  22. text=`yes "$text" | head -c 9999`
  23. result=`(
  24. n=0
  25. while test $n -le 999; do
  26. echo "$text" | head -c $n | "$sum"
  27. n=$(($n+1))
  28. done | "$sum"
  29. )`
  30. if test x"$result" != x"$expected -"; then
  31. echo "FAIL: $sum (r:$result exp:$expected)"
  32. : $((FAILCOUNT++))
  33. else
  34. echo "PASS: $sum"
  35. fi
  36. # GNU compat: -c EMPTY must fail (exitcode 1)!
  37. >EMPTY
  38. if "$sum" -c EMPTY 2>/dev/null; then
  39. echo "FAIL: $sum -c EMPTY"
  40. : $((FAILCOUNT++))
  41. else
  42. echo "PASS: $sum -c EMPTY"
  43. fi
  44. rm EMPTY
  45. exit $FAILCOUNT