1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#!/bin/sh
# Licensed under the zlib/libpng license (same as NSIS)
#
# Script to perform SHA256 tests
#
# Usage: run.sh [<helper dir [<Windows architecture> [<test dir>]]]
set -e
OUTPUT="output.log"
SCRIPT="sha256_test.nsi"
SOURCEDIR=$(cd "$(dirname "$0")"; pwd -P)
TOPDIR=$(cd "${SOURCEDIR}/../.."; pwd -P)
HELPERDIR="${1:-"${TOPDIR}/build"}/helpers/${SOURCEDIR##*/}"
INSTALLER="${SCRIPT%.*}.exe"
UNINSTALLER="uninstall.exe"
TESTID=
. "${SOURCEDIR}/../common/funcs.sh"
before() {
make_installer "-XOutFile ${PWD}/${INSTALLER}" \
$(test "${WINEARCH}" != "win32" && echo "-DNO_SHA256_HELPER") \
"-DSHA256_HELPER_DIR=${HELPERDIR}" \
"${SOURCEDIR}/${SCRIPT}"
}
after() {
[ -n "${TESTID}" -a -f "${TESTID}" ] && rm "${TESTID}"
[ -f "${OUTPUT}" ] && rm "${OUTPUT}"
[ -f "${INSTALLER}" ] && rm "${INSTALLER}"
[ -f "${UNINSTALLER}" ] && rm "${UNINSTALLER}"
}
run_reference() {
set -- safety $(sha256sum < "${1}") && shift && echo "${1}"
}
# Convert hexadecimal number into a byte
hex2byte() {
# Transform hexadecimal number into its octal representation
n=$((0x${1}))
divisor=64
byte=""
while [ ${divisor} -gt 0 ]
do
m=$((${n}/${divisor}))
n=$((${n}-${m}*${divisor}))
divisor=$((${divisor}/8))
byte="${byte}${m}"
done
if [ -n "${byte}" ]; then
byte="\\${byte}"
fi
# Create corresponding byte from the octal code
printf "${byte}"
}
test_sha256() {
# Skip comment lines starting with #
if [ -n "${1}" -a "${1}" = "${1#\#}" ]; then
testcase="Test:"
# Generate test data according to the provided pattern
:> "${1}"
if [ -n "${2}" ]; then
testcase="${testcase} $2"
while true
do
code=$(dd ibs=1 count=2 2>/dev/null)
[ -n "${code}" ] || break
hex2byte ${code} >> "${1}"
done << EOF
$2
EOF
if [ -n "${4}" ]; then
testcase="${testcase} ${3} ${4}"
transform=""
if [ "${2}" != "00" ]; then
transform="| tr \"\0\" \"$(cat ${1})\""
fi
eval head -c${4} /dev/zero $transform > "${1}"
fi
else
testcase="${testcase} <empty>"
fi
echo "${testcase}"
# Compute SHA256 digest via Installer and Uninstaller
# for the generated test data and compare the result
# with the expected one.
run_installer ${INSTALLER} \
"/FILE=${1}" "/RESULT=${OUTPUT}" || exit 1
result=$(assert_equal "${1}" "$(tail -n 1 ${OUTPUT})")
check_result $? "${result} (Installer)"
rm -f ${OUTPUT}
run_uninstaller ${UNINSTALLER} \
"/FILE=${1}" "/RESULT=${OUTPUT}" || exit 1
result=$(assert_equal "${1}" "$(tail -n 1 ${OUTPUT})")
check_result $? "${result} (Uninstaller)"
rm -f ${OUTPUT} "${1}"
fi
}
main() {
while read -r line
do
set -f -- safety $line
shift
TESTID="${1}"
test_sha256 $@
done < ${SOURCEDIR}/sha256tests.txt
}
[ $# -gt 1 ] && shift
wine_set_up "${@}"
before
main
after
wine_clean_up "${@}"
|