Skip to content

Commit

Permalink
Merge pull request #476 from Tarsnap/optional-mutex-tests
Browse files Browse the repository at this point in the history
Use liball_optional_mutex_{normal,pthread}.a
  • Loading branch information
cperciva authored Aug 26, 2023
2 parents dd65357 + 4ba9f31 commit 11ce1ee
Show file tree
Hide file tree
Showing 43 changed files with 157 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/posix-flags.sh
# Compiled libraries and test binaries.
/liball/liball.a
/liball/optional_mutex_normal/liball_optional_mutex_normal.a
/liball/optional_mutex_pthread/liball_optional_mutex_pthread.a
/perftests/http/test_http
/perftests/https/test_https
/perftests/network-ssl/test_network_ssl
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.POSIX:

PROGS=
LIBS= liball
LIBS= liball \
liball/optional_mutex_normal \
liball/optional_mutex_pthread
TESTS= perftests/http \
perftests/https \
perftests/network-ssl \
Expand Down
4 changes: 3 additions & 1 deletion Makefile.BSD
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
PKG= libcperciva
PROGS=
LIBS= liball
LIBS= liball \
liball/optional_mutex_normal \
liball/optional_mutex_pthread
TESTS= perftests/http \
perftests/https \
perftests/network-ssl \
Expand Down
4 changes: 3 additions & 1 deletion Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ MAN =

.if !defined(NOLIBALL)
# Link everything to liball.a, unless they specifically ask not to use it.
LIBALL = ${SUBDIR_DEPTH}/liball/liball.a
# If appropriate, metabuild.sh will do:
# s/optional_mutex_normal/optional_mutex_pthread/g
LIBALL = ${SUBDIR_DEPTH}/liball/liball.a ${SUBDIR_DEPTH}/liball/optional_mutex_normal/liball_optional_mutex_normal.a
LDADD += ${LIBALL}
DPADD += ${LIBALL}
.endif
Expand Down
3 changes: 3 additions & 0 deletions liball/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.include "../Makefile.inc"

SUBDIR_DEPTH := ${SUBDIR_DEPTH}/..
25 changes: 25 additions & 0 deletions liball/optional_mutex_normal/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.POSIX:
# AUTOGENERATED FILE, DO NOT EDIT
LIB=liball_optional_mutex_normal.a
SRCS=optional_mutex.c
IDIRS=-I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=liball/optional_mutex_normal

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
cd ${SUBDIR_DEPTH}; \
${MAKE} BUILD_SUBDIR=${RELATIVE_DIR} \
BUILD_TARGET=${PROG} buildsubdir; \
else \
${MAKE} ${LIB}; \
fi

clean:
rm -f ${LIB} ${SRCS:.c=.o}

${LIB}:${SRCS:.c=.o}
${AR} ${ARFLAGS} ${LIB} ${SRCS:.c=.o}

optional_mutex.o: ../../util/optional_mutex.c ../../util/optional_mutex.h
${CC} ${CFLAGS_POSIX} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" -I../.. ${IDIRS} ${CPPFLAGS} ${CFLAGS} -DOPTIONAL_MUTEX_PTHREAD_NO -c ../../util/optional_mutex.c -o optional_mutex.o
21 changes: 21 additions & 0 deletions liball/optional_mutex_normal/Makefile.BSD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Library name.
LIB = all_optional_mutex_normal

# Don't install it.
NOINST = 1

# Don't link to liball.a.
NOLIBALL = 1

# Useful relative directories.
LIBCPERCIVA_DIR = ../..

# Handle optional_mutex (this cannot be part of liball).
.PATH.c : ${LIBCPERCIVA_DIR}/util
SRCS += optional_mutex.c
IDIRS += -I${LIBCPERCIVA_DIR}/util

# Required define.
CFLAGS.optional_mutex.c= -DOPTIONAL_MUTEX_PTHREAD_NO

.include <bsd.prog.mk>
25 changes: 25 additions & 0 deletions liball/optional_mutex_pthread/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.POSIX:
# AUTOGENERATED FILE, DO NOT EDIT
LIB=liball_optional_mutex_pthread.a
SRCS=optional_mutex.c
IDIRS=-I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=liball/optional_mutex_pthread

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
cd ${SUBDIR_DEPTH}; \
${MAKE} BUILD_SUBDIR=${RELATIVE_DIR} \
BUILD_TARGET=${PROG} buildsubdir; \
else \
${MAKE} ${LIB}; \
fi

clean:
rm -f ${LIB} ${SRCS:.c=.o}

${LIB}:${SRCS:.c=.o}
${AR} ${ARFLAGS} ${LIB} ${SRCS:.c=.o}

optional_mutex.o: ../../util/optional_mutex.c ../../util/optional_mutex.h
${CC} ${CFLAGS_POSIX} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" -I../.. ${IDIRS} ${CPPFLAGS} ${CFLAGS} -DOPTIONAL_MUTEX_PTHREAD_YES -c ../../util/optional_mutex.c -o optional_mutex.o
21 changes: 21 additions & 0 deletions liball/optional_mutex_pthread/Makefile.BSD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Library name.
LIB = all_optional_mutex_pthread

# Don't install it.
NOINST = 1

# Don't link to liball.a.
NOLIBALL = 1

# Useful relative directories.
LIBCPERCIVA_DIR = ../..

# Handle optional_mutex (this cannot be part of liball).
.PATH.c : ${LIBCPERCIVA_DIR}/util
SRCS += optional_mutex.c
IDIRS += -I${LIBCPERCIVA_DIR}/util

# Required define.
CFLAGS.optional_mutex.c= -DOPTIONAL_MUTEX_PTHREAD_YES

.include <bsd.prog.mk>
2 changes: 1 addition & 1 deletion perftests/http/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I ../../events -I ../../http -I ../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=perftests/http
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion perftests/https/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ IDIRS=-I ../../events -I ../../http -I ../../util
LDADD_REQ=-lssl -lcrypto
SUBDIR_DEPTH=../..
RELATIVE_DIR=perftests/https
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion perftests/network-ssl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ IDIRS=-I ../../events -I ../../network_ssl -I ../../util
LDADD_REQ=-lssl -lcrypto
SUBDIR_DEPTH=../..
RELATIVE_DIR=perftests/network-ssl
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
17 changes: 16 additions & 1 deletion release-tools/metabuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ addvar_lib() {
fi
}

copyvar_LIBALL_optional_mutex() {
var=LIBALL
val=$(${MAKEBSD} -v LIBALL)
if [ -n "${val}" ]; then
# Replace optional_mutex_normal with pthread variant,
# if appropriate.
ldadd_req=$(${MAKEBSD} -v LDADD_REQ)
if [ "${ldadd_req#*-lpthread}" != "${ldadd_req}" ] ; then
val=$(echo "${val}" | \
sed 's/optional_mutex_normal/optional_mutex_pthread/g')
fi
printf "%s=%s\n" "${var}" "${val}" >> "${OUT}"
fi
}

add_makefile_prog() {
# Get a copy of the default Makefile.prog
cp "${SUBDIR_DEPTH}/release-tools/Makefile.prog" prog.tmp
Expand Down Expand Up @@ -161,7 +176,7 @@ printf "RELATIVE_DIR=%s\n" "${D}" >> "${OUT}"
if [ -n "$(${MAKEBSD} -v LIB)" ]; then
cat "${SUBDIR_DEPTH}/release-tools/Makefile.lib" >> "${OUT}"
elif [ -n "$(${MAKEBSD} -v SRCS)" ]; then
copyvar LIBALL
copyvar_LIBALL_optional_mutex
add_makefile_prog
else
printf "\nall:\n\ttrue\n\nclean:\n\ttrue\n" >> "${OUT}"
Expand Down
2 changes: 1 addition & 1 deletion tests/aws/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../aws -I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/aws
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/buildall/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
LDADD_REQ=-lcrypto
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/buildall
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/buildsingles/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../alg -I../../aws -I../../cpusupport -I../../crypto -I../../datastruct -I../../events -I../../external/queue -I../../http -I../../netbuf -I../../network -I../../network_ssl -I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/buildsingles
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/crc32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../alg -I../../cpusupport -I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/crc32
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/crypto_aes/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ IDIRS=-I../../cpusupport -I../../crypto -I../../util
LDADD_REQ=-lcrypto
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/crypto_aes
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/crypto_aesctr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ IDIRS=-I../../cpusupport -I../../crypto -I../../util
LDADD_REQ=-lcrypto
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/crypto_aesctr
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/crypto_entropy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../crypto -I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/crypto_entropy
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/daemonize/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/daemonize
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/elasticarray/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../datastruct
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/elasticarray
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/events/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c events_counter.c events_interrupter.c
IDIRS=-I../../events -I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/events
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/getopt-longjmp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/getopt-longjmp
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/getopt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/getopt
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/heap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../datastruct -I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/heap
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/humansize/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/humansize
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/json/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I ../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/json
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/md5/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../alg -I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/md5
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/monoclock/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/monoclock
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
2 changes: 1 addition & 1 deletion tests/mpool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SRCS=main.c
IDIRS=-I../../datastruct -I../../util
SUBDIR_DEPTH=../..
RELATIVE_DIR=tests/mpool
LIBALL=../../liball/liball.a
LIBALL=../../liball/liball.a ../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand Down
6 changes: 2 additions & 4 deletions tests/optional_mutex/normal/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.POSIX:
# AUTOGENERATED FILE, DO NOT EDIT
PROG=test_optional_mutex_normal
SRCS=main.c optional_mutex.c
SRCS=main.c
IDIRS=-I../../../util
SUBDIR_DEPTH=../../..
RELATIVE_DIR=tests/optional_mutex/normal
LIBALL=../../../liball/liball.a
LIBALL=../../../liball/liball.a ../../../liball/optional_mutex_normal/liball_optional_mutex_normal.a

all:
if [ -z "$${HAVE_BUILD_FLAGS}" ]; then \
Expand All @@ -24,8 +24,6 @@ ${PROG}:${SRCS:.c=.o} ${LIBALL}

main.o: ../main.c ../../../util/optional_mutex.h ../../../util/warnp.h
${CC} ${CFLAGS_POSIX} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" -I../../.. ${IDIRS} ${CPPFLAGS} ${CFLAGS} -c ../main.c -o main.o
optional_mutex.o: ../../../util/optional_mutex.c ../../../util/optional_mutex.h
${CC} ${CFLAGS_POSIX} -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" -I../../.. ${IDIRS} ${CPPFLAGS} ${CFLAGS} -DOPTIONAL_MUTEX_PTHREAD_NO -c ../../../util/optional_mutex.c -o optional_mutex.o

test: all
./${PROG}
7 changes: 1 addition & 6 deletions tests/optional_mutex/normal/Makefile.BSD
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ LIBCPERCIVA_DIR = ../../..
.PATH.c : ..
SRCS = main.c

# Handle optional_mutex (this cannot be part of liball).
.PATH.c : ${LIBCPERCIVA_DIR}/util
SRCS += optional_mutex.c
# libcperciva includes
IDIRS += -I${LIBCPERCIVA_DIR}/util

# Required define.
CFLAGS.optional_mutex.c= -DOPTIONAL_MUTEX_PTHREAD_NO

test: all
./${PROG}

Expand Down
Loading

0 comments on commit 11ce1ee

Please sign in to comment.