Skip to content

Commit

Permalink
Merge pull request #373 from Tarsnap/libcperciva-import
Browse files Browse the repository at this point in the history
Libcperciva import and trivial sh style
  • Loading branch information
cperciva authored Aug 16, 2023
2 parents 9fd3e4c + 79497e0 commit 81abc2a
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 63 deletions.
2 changes: 1 addition & 1 deletion get-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if git rev-parse 2>/dev/null; then
# Get a version string from the latest git tag.
if version_git=$( git describe --tags --match '[[:digit:]].*' ) \
2>/dev/null ; then
version_decapitated=$( echo ${version} | sed "s/-head//" )
version_decapitated=$( echo "${version}" | sed "s/-head//" )
# Check that the beginning of this tag matches the version.
case ${version_git} in
"${version_decapitated}"*)
Expand Down
46 changes: 23 additions & 23 deletions libcperciva/POSIX/posix-cflags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ if [ -z "${CC}" ]; then
exit 1
fi
if ! [ "${PATH}" = "$1" ]; then
echo "WARNING: POSIX violation: $SHELL's command -p resets \$PATH" 1>&2
echo "WARNING: POSIX violation: ${SHELL}'s command -p resets \$PATH" 1>&2
PATH=$1
fi

# Find directory of this script and the source files
D=$(dirname "$0")

# Check if we can compile & run a binary.
if ! ${CC} ${CFLAGS} "$D/posix-trivial.c" 2>/dev/null; then
if ! ${CC} ${CFLAGS} "${D}/posix-trivial.c" 2>/dev/null; then
echo "WARNING: failed to compile posix-trivial.c" 1>&2
else
# If the user hasn't disabled runtime checks...
Expand All @@ -31,28 +31,28 @@ else
fi

FIRST=YES
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L "$D/posix-msg_nosignal.c" 2>/dev/null; then
[ ${FIRST} = "NO" ] && printf " "; FIRST=NO
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L "${D}/posix-msg_nosignal.c" 2>/dev/null; then
[ "${FIRST}" = "NO" ] && printf " "; FIRST=NO
printf %s "-DPOSIXFAIL_MSG_NOSIGNAL"
echo "WARNING: POSIX violation: <sys/socket.h> not defining MSG_NOSIGNAL" 1>&2
fi
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L "$D/posix-clock_realtime.c" 2>/dev/null; then
[ ${FIRST} = "NO" ] && printf " "; FIRST=NO
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L "${D}/posix-clock_realtime.c" 2>/dev/null; then
[ "${FIRST}" = "NO" ] && printf " "; FIRST=NO
printf %s "-DPOSIXFAIL_CLOCK_REALTIME"
echo "WARNING: POSIX violation: <time.h> not defining CLOCK_REALTIME" 1>&2
fi
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 "$D/posix-inet-addrstrlen.c" 2>/dev/null; then
[ ${FIRST} = "NO" ] && printf " "; FIRST=NO
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 "${D}/posix-inet-addrstrlen.c" 2>/dev/null; then
[ "${FIRST}" = "NO" ] && printf " "; FIRST=NO
printf %s "-DPOSIXFAIL_INET_ADDRSTRLEN"
echo "WARNING: POSIX violation: <netinet/in.h> not defining INET_ADDRSTRLEN" 1>&2
fi
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 "$D/posix-inet6-addrstrlen.c" 2>/dev/null; then
[ ${FIRST} = "NO" ] && printf " "; FIRST=NO
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 "${D}/posix-inet6-addrstrlen.c" 2>/dev/null; then
[ "${FIRST}" = "NO" ] && printf " "; FIRST=NO
printf %s "-DPOSIXFAIL_INET6_ADDRSTRLEN"
echo "WARNING: POSIX violation: <netinet/in.h> not defining INET6_ADDRSTRLEN" 1>&2
fi
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L "$D/posix-clock_gettime.c" 2>/dev/null; then
[ ${FIRST} = "NO" ] && printf " "; FIRST=NO
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L "${D}/posix-clock_gettime.c" 2>/dev/null; then
[ "${FIRST}" = "NO" ] && printf " "; FIRST=NO
printf %s "-DPOSIXFAIL_CLOCK_GETTIME"
echo "WARNING: POSIX violation: <time.h> not declaring clock_gettime()" 1>&2
elif [ "${DISABLE_POSIX_RUNTIME_CHECKS:-0}" -ne "0" ]; then
Expand All @@ -68,30 +68,30 @@ else
# calling process. The "( ./x 2>y ) 2>y" captures both types of error
# message.
if ! ( ./a.out 2>/dev/null ) 2>/dev/null ; then
[ ${FIRST} = "NO" ] && printf " "; FIRST=NO
[ "${FIRST}" = "NO" ] && printf " "; FIRST=NO
printf %s "-DPOSIXFAIL_CLOCK_GETTIME"
echo "WARNING: POSIX violation: clock_gettime() is not linkable" 1>&2
fi
fi
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 "$D/posix-stat-st_mtim.c" 2>/dev/null; then
[ ${FIRST} = "NO" ] && printf " "; FIRST=NO
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 "${D}/posix-stat-st_mtim.c" 2>/dev/null; then
[ "${FIRST}" = "NO" ] && printf " "; FIRST=NO
printf %s "-DPOSIXFAIL_STAT_ST_MTIM"
echo "WARNING: POSIX violation: struct stat does not contain st_mtim" 1>&2
fi
NEED_STD_C99=""
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L "$D/posix-restrict.c" 2>/dev/null; then
CFLAGS_C99=""
if ! ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L "${D}/posix-restrict.c" 2>/dev/null; then
echo "WARNING: POSIX violation: ${CC} does not accept the 'restrict' keyword" 1>&2
if ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L -std=c99 "$D/posix-restrict.c" 2>/dev/null; then
[ ${FIRST} = "NO" ] && printf " "; FIRST=NO
if ${CC} ${CFLAGS} -D_POSIX_C_SOURCE=200809L -std=c99 "${D}/posix-restrict.c" 2>/dev/null; then
[ "${FIRST}" = "NO" ] && printf " "; FIRST=NO
printf %s "-std=c99"
NEED_STD_C99="-std=c99"
CFLAGS_C99="-std=c99"
fi
fi
if ! ${CC} ${CFLAGS} ${NEED_STD_C99} -D_POSIX_C_SOURCE=200809L -DARGNAME="" "$D/posix-abstract-declarator.c" 2>/dev/null; then
if ! ${CC} ${CFLAGS} ${CFLAGS_C99} -D_POSIX_C_SOURCE=200809L -DARGNAME="" "${D}/posix-abstract-declarator.c" 2>/dev/null; then
echo "WARNING: POSIX violation: ${CC} does not accept qualifiers in an abstract declarator" 1>&2
# Test compile with -DPOSIXFAIL_ABSTRACT_DECLARATOR
if ${CC} ${CFLAGS} ${NEED_STD_C99} -D_POSIX_C_SOURCE=200809L -DPOSIXFAIL_ABSTRACT_DECLARATOR "$D/posix-abstract-declarator.c" 2>/dev/null; then
[ ${FIRST} = "NO" ] && printf " "; FIRST=NO
if ${CC} ${CFLAGS} ${CFLAGS_C99} -D_POSIX_C_SOURCE=200809L -DPOSIXFAIL_ABSTRACT_DECLARATOR "${D}/posix-abstract-declarator.c" 2>/dev/null; then
[ "${FIRST}" = "NO" ] && printf " "; FIRST=NO
printf %s "-DPOSIXFAIL_ABSTRACT_DECLARATOR"
fi
fi
Expand Down
6 changes: 3 additions & 3 deletions libcperciva/POSIX/posix-l.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if [ -z "${CC}" ]; then
exit 1
fi
if ! [ "${PATH}" = "$1" ]; then
echo "WARNING: POSIX violation: $SHELL's command -p resets \$PATH" 1>&2
echo "WARNING: POSIX violation: ${SHELL}'s command -p resets \$PATH" 1>&2
PATH=$1
fi

Expand All @@ -17,8 +17,8 @@ D=$(dirname "$0")

FIRST=YES
for LIB in rt xnet; do
if ${CC} ${CFLAGS} -l${LIB} "$D/posix-trivial.c" 2>/dev/null; then
if [ ${FIRST} = "NO" ]; then
if ${CC} ${CFLAGS} -l"${LIB}" "${D}/posix-trivial.c" 2>/dev/null; then
if [ "${FIRST}" = "NO" ]; then
printf " ";
fi
printf "%s" "-l${LIB}";
Expand Down
11 changes: 6 additions & 5 deletions libcperciva/cpusupport/Build/cpusupport.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Should be sourced by `command -p sh path/to/cpusupport.sh "$PATH"` from
# within a Makefile.
if ! [ "${PATH}" = "$1" ]; then
echo "WARNING: POSIX violation: $SHELL's command -p resets \$PATH" 1>&2
echo "WARNING: POSIX violation: ${SHELL}'s command -p resets \$PATH" 1>&2
PATH=$1
fi

# Standard output should be written to cpusupport-config.h, which is both a
# C header file defining CPUSUPPORT_ARCH_FEATURE macros and sourceable sh
# code which sets CFLAGS_ARCH_FEATURE environment variables.
Expand Down Expand Up @@ -32,16 +33,16 @@ feature() {

# Check if we can compile this feature (and any required arguments).
printf "Checking if compiler supports %s %s feature..." \
"$ARCH" "$FEATURE" 1>&2
"${ARCH}" "${FEATURE}" 1>&2
for CPU_CFLAGS in "$@"; do
if ${CC} ${CPPFLAGS} ${CFLAGS} ${CFLAGS_HARDCODED} \
${CPU_CFLAGS} "${feature_filename}" 2>>${outcc}; then
${CPU_CFLAGS} "${feature_filename}" 2>>"${outcc}"; then
rm -f a.out
break;
fi
CPU_CFLAGS=NOTSUPPORTED;
done
case $CPU_CFLAGS in
case ${CPU_CFLAGS} in
NOTSUPPORTED)
echo " no" 1>&2
;;
Expand All @@ -50,7 +51,7 @@ feature() {
echo "#define CPUSUPPORT_${ARCH}_${FEATURE} 1"
;;
*)
echo " yes, via $CPU_CFLAGS" 1>&2
echo " yes, via ${CPU_CFLAGS}" 1>&2
echo "#define CPUSUPPORT_${ARCH}_${FEATURE} 1"
echo "#ifdef cpusupport_dummy"
echo "export CFLAGS_${ARCH}_${FEATURE}=\"${CPU_CFLAGS}\""
Expand Down
2 changes: 1 addition & 1 deletion libcperciva/util/entropy.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ entropy_read_fill(struct entropy_read_cookie * er, uint8_t * buf,

/**
* entropy_read_done(er):
* Release any resources used by {er}.
* Release any resources used by ${er}.
*/
int
entropy_read_done(struct entropy_read_cookie * er)
Expand Down
2 changes: 1 addition & 1 deletion libcperciva/util/entropy.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int entropy_read_fill(struct entropy_read_cookie *, uint8_t *, size_t);

/**
* entropy_read_done(er):
* Release any resources used by {er}.
* Release any resources used by ${er}.
*/
int entropy_read_done(struct entropy_read_cookie * er);

Expand Down
4 changes: 2 additions & 2 deletions libcperciva/util/warnp.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static void
warnp_atexit(void)
{

/* Clean up writing to the syslog (if applicable). */
/* Clean up writing to the syslog (if applicable). */
if (use_syslog)
closelog();

Expand Down Expand Up @@ -144,7 +144,7 @@ void
warnp_syslog(int enable)
{

/* Clean up writing to the syslog (if applicable). */
/* Clean up writing to the syslog (if applicable). */
if (use_syslog && !enable)
closelog();

Expand Down
4 changes: 2 additions & 2 deletions release-tools/create-sign-tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SCRYPTVERSION=$1
GNUPG_SIGNING_HOME=$2

# Check for required arguments
if [ -z "$SCRYPTVERSION" ] || [ -z "$GNUPG_SIGNING_HOME" ]; then
if [ -z "${SCRYPTVERSION}" ] || [ -z "${GNUPG_SIGNING_HOME}" ]; then
echo "Usage: $0 SCRYPTVERSION GNUPG_SIGNING_HOME"
exit 1
fi
Expand All @@ -26,7 +26,7 @@ PKGSIGS=scrypt-sigs-${SCRYPTVERSION}
dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)

# Create tarball
sh "${dir}/mktarball.sh" "$SCRYPTVERSION"
sh "${dir}/mktarball.sh" "${SCRYPTVERSION}"

# Sign tarball
sha256 "${PKGNAME}.tgz" | \
Expand Down
4 changes: 2 additions & 2 deletions release-tools/mktarball.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

VERSION=$1
if [ -z "$VERSION" ]; then
if [ -z "${VERSION}" ]; then
echo "Please specify the version number"
exit 1
fi
Expand All @@ -15,7 +15,7 @@ cp Makefile.am .autom4te.cfg "${DESTDIR}"
cp Makefile.am "${DESTDIR}/autotools"
cp -R lib lib-platform libcperciva libscrypt-kdf m4 tests "${DESTDIR}"
# Copy with substitution
sed -e "s/@DATE@/$RELEASEDATE/" < scrypt.1 > "${DESTDIR}/scrypt.1"
sed -e "s/@DATE@/${RELEASEDATE}/" < scrypt.1 > "${DESTDIR}/scrypt.1"
sed -e "s/\[m4_esyscmd(\[sh get-version\.sh\])]/${VERSION}/" \
< configure.ac > "${DESTDIR}/configure.ac"
cp "${DESTDIR}/configure.ac" "${DESTDIR}/autotools"
Expand Down
61 changes: 45 additions & 16 deletions tests/shared_test_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
# scenario_cmd()
# function which was defined in that file.
#
# Functions which are available to other scripts as a "public API" are:
# - has_pid(cmd):
# Look for a ${cmd} in $(ps).
# - wait_while(func):
# Wait until ${func} returns non-zero.
# - setup_check_variables(description, check_prev):
# Set up the below variables.
# - expected_exitcode(expected, actual):
# Check if ${expected} matches ${actual}.
# - run_scenarios():
# Run scenarios in the test directory.
#
### Variables
#
# Wherever possible, this suite uses local variables and
Expand All @@ -27,6 +39,7 @@
# valgrind log files.
# - s_count: this is the count of the scenario's checks (so that
# each check can have distinct files).
# - s_count_str: ${s_count} expressed as a two-digit string.
# - s_retval: this is the overall exit code of the scenario.
# - c_exitfile: this contains the exit code of each check.
# - c_valgrind_min: this is the minimum value of USE_VALGRIND
Expand Down Expand Up @@ -108,16 +121,32 @@ has_pid() {
return 1
}

## wait_for_file (filename):
# Waits until ${filename} exists.
wait_for_file() {
filename=$1
while [ ! -e "${filename}" ]; do
## wait_while(func):
# Wait while ${func} returns 0. If ${msleep} is defined, use that to wait
# 100ms; otherwise, wait in 1 second increments.
wait_while() {
_wait_while_ms=0

# Check for the ending condition
while "$@"; do
# Notify user (if desired)
if [ "${VERBOSE}" -ne 0 ]; then
echo "Waiting for ${filename}" 1>&2
printf "waited\t%ims\t%s\n" \
"${_wait_while_ms}" "$*" 1>&2
fi

# Wait using the appropriate binary
if [ -n "${msleep:-}" ]; then
"${msleep}" 100
_wait_while_ms=$((_wait_while_ms + 100))
else
sleep 1
_wait_while_ms=$((_wait_while_ms + 1000))
fi
sleep 1
done

# Success
return 0
}

## setup_check_variables (description, check_prev=1):
Expand Down Expand Up @@ -145,12 +174,12 @@ setup_check_variables() {
fi

# Set up the "exit" file.
count_str=$(printf "%02d" "${s_count}")
c_exitfile="${s_basename}-${count_str}.exit"
s_count_str=$(printf "%02d" "${s_count}")
c_exitfile="${s_basename}-${s_count_str}.exit"

# Write the "description" file.
printf "%s\n" "${description}" > \
"${s_basename}-${count_str}.desc"
"${s_basename}-${s_count_str}.desc"

# Set up the valgrind command (or an empty string).
c_valgrind_cmd="$(valgrind_setup_cmd)"
Expand Down Expand Up @@ -189,7 +218,7 @@ notify_success_or_fail() {

# Bail if there's no exitfiles.
exitfiles=$(ls "${log_basename}"-*.exit) || true
if [ -z "$exitfiles" ]; then
if [ -z "${exitfiles}" ]; then
echo "FAILED" 1>&2
s_retval=1
return
Expand All @@ -200,7 +229,7 @@ notify_success_or_fail() {
skip_exitfiles=0

# Check each exitfile.
for exitfile in $(echo "$exitfiles" | sort); do
for exitfile in $(echo "${exitfiles}" | sort); do
ret=$(cat "${exitfile}")
total_exitfiles=$(( total_exitfiles + 1 ))
if [ "${ret}" -lt 0 ]; then
Expand Down Expand Up @@ -236,8 +265,8 @@ notify_success_or_fail() {
done

# Notify about skip or success.
if [ ${skip_exitfiles} -gt 0 ]; then
if [ ${skip_exitfiles} -eq ${total_exitfiles} ]; then
if [ "${skip_exitfiles}" -gt 0 ]; then
if [ "${skip_exitfiles}" -eq "${total_exitfiles}" ]; then
echo "SKIP!" 1>&2
else
echo "PARTIAL SUCCESS / SKIP!" 1>&2
Expand Down Expand Up @@ -305,8 +334,8 @@ run_scenarios() {
# want to allow it to echo values to stdout.
scenario_runner "${scenario}"
retval=$?
if [ ${retval} -gt 0 ]; then
exit ${retval}
if [ "${retval}" -gt 0 ]; then
exit "${retval}"
fi
done
}
Loading

0 comments on commit 81abc2a

Please sign in to comment.