Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcperciva import and fix lbs test #293

Merged
merged 4 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion libcperciva/datastruct/elasticarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ resize(struct elasticarray * EA, size_t nsize)
if (EA->alloc < nsize) {
/* We need to enlarge the buffer. */
nalloc = EA->alloc * 2;

/*
* Handle if nalloc is not large enough to hold nsize, which can
* happen when: 1) EA->alloc is small enough that EA->alloc * 2
* is still smaller than nsize, or 2) EA->alloc is large enough
* that EA->alloc * 2 wraps around, becoming smaller than nsize.
*/
if (nalloc < nsize)
nalloc = nsize;
} else if (EA->alloc > nsize * 4) {
} else if (EA->alloc / 4 > nsize) {
/* We need to shrink the buffer. */
nalloc = nsize * 2;
} else {
Expand Down
8 changes: 4 additions & 4 deletions libcperciva/events/events_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* for it to be larger than size_t unless there's an undocumented limit on
* the number of descriptors which can be polled (since poll takes an array,
* the size of which must fit into a size_t); and nfds_t should be able to
* the value INT_MAX + 1 (in case every possible file descriptor is in use
* and being polled for).
* store the value INT_MAX + 1 (in case every possible file descriptor is in
* use and being polled for).
*/
CTASSERT((nfds_t)(-1) <= (size_t)(-1));
CTASSERT((nfds_t)((size_t)(INT_MAX) + 1) == (size_t)(INT_MAX) + 1);
Expand Down Expand Up @@ -65,7 +65,7 @@ static size_t fdscanpos;
* S[i].reader != NULL <==> (fds[S[i].pollpos].events & POLLIN) != 0
* S[i].writer != NULL <==> (fds[S[i].pollpos].events & POLLOUT) != 0
* 5. We don't have events ready which we don't want:
* (fds[j].revents & (POLLIN | POLLOUT) & (~fds[j].events])) == 0
* (fds[j].revents & (POLLIN | POLLOUT) & (~fds[j].events)) == 0
* 6. Returned events are in position to be scanned later:
* fds[j].revents != 0 ==> f < fdscanpos.
*/
Expand Down Expand Up @@ -451,7 +451,7 @@ events_network_get(void)
break;
}

/* Are we ready for reading? */
/* Are we ready for writing? */
if (fds[fdscanpos].revents & POLLOUT) {
r = socketlist_get(S,
(size_t)fds[fdscanpos].fd)->writer;
Expand Down
2 changes: 1 addition & 1 deletion libcperciva/network_ssl/network_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ docallback(int (* callback)(void *, ssize_t), void * cookie, ssize_t len,

/*
* Zero the callback pointer; the callback might want to request
* another read/write operation so we need to get out of the way.
* another read/write operation, so we need to get out of the way.
*/
*callback_ptr = NULL;

Expand Down
4 changes: 2 additions & 2 deletions libcperciva/network_ssl/network_ssl_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifdef NETWORK_SSL_COMPAT_TLS_CLIENT_METHOD
/**
* network_ssl_compat_TLS_client_method(void):
* Create a SSL_METHOD.
* Create an SSL_METHOD.
*
* COMPATIBILITY: Behave like TLS_client_method().
*/
Expand All @@ -35,7 +35,7 @@ network_ssl_compat_CTL_set_min_proto_version(SSL_CTX * ctx, int version)
{
long options;

/* This the only version currently supported in this file. */
/* This is the only version currently supported in this file. */
assert(version == TLS1_2_VERSION);

/* Disable all protocols lower than TLS1_2_VERSION. */
Expand Down
2 changes: 1 addition & 1 deletion libcperciva/network_ssl/network_ssl_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#ifdef NETWORK_SSL_COMPAT_TLS_CLIENT_METHOD
/**
* network_ssl_compat_TLS_client_method(void):
* Create a SSL_METHOD.
* Create an SSL_METHOD.
*
* COMPATIBILITY: Behave like TLS_client_method().
*/
Expand Down
2 changes: 2 additions & 0 deletions libcperciva/util/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ sock_resolve_unix(const char * addr)
if ((sa_un = calloc(1, sizeof(struct sockaddr_un))) == NULL)
goto err0;
sa_un->sun_family = AF_UNIX;

/* Safely copy addr into the structure. */
if (strlen(addr) >= sizeof(sa_un->sun_path)) {
warn0("socket path too long: %s", addr);
goto err1;
Expand Down
35 changes: 18 additions & 17 deletions tests/01-lbs-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,40 @@ clean_storage() {
# that we should use valgrind. If ${is_read_delay} is non-zero, add a read
# delay to the server operations. Use ${description} for the test framework.
lbs_check_basic() {
is_single=$1
is_read_delay=$2
description=$3
_lbs_check_basic_single=$1
_lbs_check_basic_read_delay=$2
_lbs_check_basic_description=$3

# Ensure that we're starting with a clean storage directory.
servers_check_leftover
clean_storage

# Set up the read delay (if applicable).
if [ "${is_read_delay}" -gt 0 ]; then
this_read_delay="${lbs_basic_read_delay}"
if [ "${_lbs_check_basic_read_delay}" -gt 0 ]; then
_lbs_check_basic_read_delay="${lbs_basic_read_delay}"
else
this_read_delay="0"
_lbs_check_basic_read_delay="0"
fi

# Start a server.
lbs_start "${sock}" "${stor}" "${is_single}" \
"${lbs_pidfile}" "${this_read_delay}" \
"lbs ${description}"
lbs_start "${sock}" "${stor}" "${_lbs_check_basic_single}" \
"${lbs_pidfile}" "${_lbs_check_basic_read_delay}" \
"lbs ${_lbs_check_basic_description}"

# Run test.
setup_check "test_lbs ${description}"
setup_check "test_lbs ${_lbs_check_basic_description}"
${c_valgrind_cmd} "${testlbs}" "${sock}"
echo "$?" > "${c_exitfile}"

# Run test again (if applicable).
if [ "${is_single}" -eq "0" ]; then
setup_check "test_lbs ${description} again"
if [ "${_lbs_check_basic_single}" -eq "0" ]; then
setup_check "test_lbs ${_lbs_check_basic_description} again"
${c_valgrind_cmd} "${testlbs}" "${sock}"
echo "$?" > "${c_exitfile}"
fi

# Clean up.
lbs_stop "${lbs_pidfile}" "${is_single}"
lbs_stop "${lbs_pidfile}" "${_lbs_check_basic_single}"
clean_storage
}

Expand Down Expand Up @@ -128,10 +128,11 @@ lbs_check_addresses() {
clean_storage

for S in "localhost:1234" "[127.0.0.1]:1235" "[::1]:1236"; do
this_lbs_pidfile="${s_basename}-$S.pid"
_lbs_check_addresses_pidfile="${s_basename}-$S.pid"
# Start a server.
lbs_start "${S}" "${stor}" "0" \
"${this_lbs_pidfile}" "${lbs_basic_read_delay}" \
"${_lbs_check_addresses_pidfile}" \
"${lbs_basic_read_delay}" \
"lbs server ${S}"

# Run the test.
Expand All @@ -140,7 +141,7 @@ lbs_check_addresses() {
echo "$?" > "${c_exitfile}"

# Clean up.
lbs_stop "${this_lbs_pidfile}" "0"
lbs_stop "${_lbs_check_addresses_pidfile}" "0"
clean_storage
done
}
Expand All @@ -155,7 +156,7 @@ scenario_cmd() {
lbs_check_basic 1 0 "single"

# Check lbs, with the server in normal mode, but still with a read
# delay. Do not use valgrind on the server. but still use it for the
# delay. Do not use valgrind on the server, but still use it for the
# test_lbs binary.
lbs_check_basic 0 1 "normal"

Expand Down