Skip to content

Commit 6b91f82

Browse files
committed
tests: Replace cpp parsing with C compilation for macro extraction
The previous cpp-based approach for extracting macro values proved brittle across different platforms due to: - Inconsistent cpp output formatting between implementations - Shell arithmetic evaluation limitations with parenthetical expressions - Complex error handling with multiple potential failure points Replace the brittle cpp output parsing with a simple C program that prints the macro value directly. This uses the actual build toolchain and lets the C compiler handle all macro expansion and arithmetic evaluation according to the C standard. It is more portable and reliable across different platforms and compiler implementations. The cpp approach remains in git history if needed for reference. Tested: - AlmaLinux 10.0 (x86-64-v2), 9.6, 8.10 - Arch Linux - CentOS Stream 9 - Debian sid, 13.1, 12.12, 11.11, 10.13, 9.13, 8.11, 7.11, 6.0.10, 5, 4 - Fedora 42, 41 - FreeBSD 14.3, 13.5 - NetBSD 10.1, 9.4 - OpenBSD 7.7, 7.6 - openSUSE Leap 15.6, 15.5 - Ubuntu 25.04, 24.04.3, 22.04.5, 20.04.6, 18.04.6, 16.04.7
1 parent baed50b commit 6b91f82

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

tests/0095-credential-payload.t

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,19 @@ test_description='Check maximum credential payload'
66
: "${SHARNESS_TEST_SRCDIR:=$(cd "$(dirname "$0")" && pwd)}"
77
. "${SHARNESS_TEST_SRCDIR}/sharness.sh"
88

9-
# Ensure cpp is available for processing "munge_defs.h".
10-
#
11-
if ! command -v cpp >/dev/null 2>&1; then
12-
skip_all='skipping maximum credential payload test; cpp not found'
13-
test_done
14-
fi
15-
169
# Get the maximum payload & request sizes, or bail out.
1710
#
1811
get_munge_define()
1912
{
2013
macro="$1"
21-
hdr="${MUNGE_SOURCE_DIR}/src/libcommon/munge_defs.h"
22-
defs=$(grep -E '^#define MUNGE_MAXIMUM_(REQ|PAYLOAD)_LEN' "${hdr}")
23-
out=$({ echo "${defs}"; echo ${macro}; } | cpp | grep -Ev '^#|^$' |tail -1)
24-
echo "${out}" | grep -q "^${macro}$" && return 1
25-
val=$(eval "echo \$((${out}))" 2>/dev/null) || return 1
26-
test "${val}" -gt 0 || return 1
27-
echo "${val}"
28-
return 0
14+
cc=$(sed -n "s/^CC *= *//p" "${MUNGE_BUILD_DIR}/Makefile" | head -1)
15+
cat >getval.$$.c <<-EOF
16+
#include <stdio.h>
17+
#include "${MUNGE_SOURCE_DIR}/src/libcommon/munge_defs.h"
18+
int main(void) {printf("%lu\n", (unsigned long)(${macro})); return 0;}
19+
EOF
20+
inc="${MUNGE_SOURCE_DIR}/src/libmunge"
21+
${cc:-cc} -I"${inc}" -o getval.$$ getval.$$.c 2>/dev/null && ./getval.$$
2922
}
3023
MAX_PAYLOAD=$(get_munge_define MUNGE_MAXIMUM_PAYLOAD_LEN) || \
3124
bail_out "Failed to get MUNGE_MAXIMUM_PAYLOAD_LEN"

0 commit comments

Comments
 (0)