Skip to content

Commit 0e18179

Browse files
author
Martin Belanger
committed
test: add unit tests for static helpers in fabrics.c
Adds libnvme/test/test-fabrics.c, which tests the static helper functions in src/nvme/fabrics.c without modifying any production source. The technique is to define 'static' to nothing and then #include the source file directly. This exposes all translation-unit-local symbols in the test binary. No #ifdef UNIT_TEST guards or visibility changes are needed — the production files are left completely untouched. Functions covered: strchomp, hostid_from_hostnqn, __add_bool_argument, __add_hex_argument, __add_int_argument, __add_int_or_minus_one_argument, __add_argument, inet4_pton, inet_pton_with_scope, traddr_is_hostname, unescape_uri The test is gated on want_fabrics in meson.build, matching the conditional that guards the uriparser test above it. Signed-off-by: Martin Belanger <[email protected]>
1 parent 17a4f8c commit 0e18179

2 files changed

Lines changed: 577 additions & 1 deletion

File tree

libnvme/test/meson.build

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,26 @@ if want_fabrics
126126
],
127127
)
128128

129-
test('libnvme - uriparser', uriparser)
129+
test('libnvme - uriparser', uriparser)
130+
131+
test_fabrics = executable(
132+
'test-fabrics',
133+
['test-fabrics.c'],
134+
# -fgnu89-inline: '#define static' (used to expose static helpers
135+
# for unit testing) turns 'static inline' into plain 'inline'.
136+
# Under C99, plain 'inline' has external linkage and may require an
137+
# external symbol definition that doesn't exist for header-only
138+
# inline functions. GNU89 semantics treat it as an inlining hint
139+
# only, avoiding the linker failure in -static builds.
140+
c_args: ['-fgnu89-inline'],
141+
dependencies: [
142+
config_dep,
143+
ccan_dep,
144+
libnvme_test_dep,
145+
],
146+
)
147+
148+
test('libnvme - fabrics', test_fabrics)
130149
endif
131150

132151
if conf.get('HAVE_NETDB')

0 commit comments

Comments
 (0)