tests: stop overriding system printf symbols

To make the source code match the functions called at runtime.
And to avoid the preprocessor trick that may introduces build issues.

Before this patch, libtests, tunits and units were calling a mixture
of curl and system printf calls, then transformed them all to curl
printf calls by including `curl_printf.h`.

Changes made:
- tests: stop including `curl_printf.h`.
- libtest: switch a couple of outlier system printf calls to curl
  printf.
- unit: use more curl printf to avoid casts and show whole values.
- unit: switch remaining calls to curl printf explicitly.
- tunit: switch to call curl printf explicitly.
- libtest, tunit, unit: ban system printf.
- unit1307, unit1607, unit1609, unit1652, unit1655, unit3214: bump
  types/masks to avoid casts.

After this patch:
- libtests, tunits, units: use exclusively curl printf.
  (as before, but explicitly, without relying on redefinitions.)
- servers: is unchanged (it can only use system printf).

Closes #18814
This commit is contained in:
Viktor Szakats 2025-10-02 16:01:15 +02:00
parent 45438c8d6f
commit 4deea9396b
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
26 changed files with 200 additions and 174 deletions

8
tests/tunit/.checksrc Normal file
View file

@ -0,0 +1,8 @@
banfunc aprintf
banfunc fprintf
banfunc msnprintf
banfunc mvsnprintf
banfunc printf
banfunc vaprintf
banfunc vfprintf
banfunc vprintf

View file

@ -43,7 +43,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include \
# Get BUNDLE, FIRST_C, TESTS_C variables
include Makefile.inc
EXTRA_DIST = CMakeLists.txt README.md $(TESTS_C)
EXTRA_DIST = CMakeLists.txt .checksrc README.md $(TESTS_C)
CFLAGS += @CURL_CFLAG_EXTRAS@

View file

@ -73,42 +73,42 @@ static CURLcode test_tool1394(const char *arg)
if(p[1]) {
if(certname) {
if(strcmp(p[1], certname)) {
printf("expected certname '%s' but got '%s' "
"for -E param '%s'\n", p[1], certname, p[0]);
curl_mprintf("expected certname '%s' but got '%s' "
"for -E param '%s'\n", p[1], certname, p[0]);
fail("assertion failure");
}
}
else {
printf("expected certname '%s' but got NULL "
"for -E param '%s'\n", p[1], p[0]);
curl_mprintf("expected certname '%s' but got NULL "
"for -E param '%s'\n", p[1], p[0]);
fail("assertion failure");
}
}
else {
if(certname) {
printf("expected certname NULL but got '%s' "
"for -E param '%s'\n", certname, p[0]);
curl_mprintf("expected certname NULL but got '%s' "
"for -E param '%s'\n", certname, p[0]);
fail("assertion failure");
}
}
if(p[2]) {
if(passphrase) {
if(strcmp(p[2], passphrase)) {
printf("expected passphrase '%s' but got '%s'"
"for -E param '%s'\n", p[2], passphrase, p[0]);
curl_mprintf("expected passphrase '%s' but got '%s'"
"for -E param '%s'\n", p[2], passphrase, p[0]);
fail("assertion failure");
}
}
else {
printf("expected passphrase '%s' but got NULL "
"for -E param '%s'\n", p[2], p[0]);
curl_mprintf("expected passphrase '%s' but got NULL "
"for -E param '%s'\n", p[2], p[0]);
fail("assertion failure");
}
}
else {
if(passphrase) {
printf("expected passphrase NULL but got '%s' "
"for -E param '%s'\n", passphrase, p[0]);
curl_mprintf("expected passphrase NULL but got '%s' "
"for -E param '%s'\n", passphrase, p[0]);
fail("assertion failure");
}
}

View file

@ -33,11 +33,11 @@ static char *getflagstr(int flags)
{
char *buf = malloc(256);
if(buf) {
msnprintf(buf, 256, "%s,%s",
((flags & SANITIZE_ALLOW_PATH) ?
"SANITIZE_ALLOW_PATH" : ""),
((flags & SANITIZE_ALLOW_RESERVED) ?
"SANITIZE_ALLOW_RESERVED" : ""));
curl_msnprintf(buf, 256, "%s,%s",
((flags & SANITIZE_ALLOW_PATH) ?
"SANITIZE_ALLOW_PATH" : ""),
((flags & SANITIZE_ALLOW_RESERVED) ?
"SANITIZE_ALLOW_RESERVED" : ""));
}
return buf;
}
@ -46,13 +46,12 @@ static char *getcurlcodestr(int cc)
{
char *buf = malloc(256);
if(buf) {
msnprintf(buf, 256, "%s (%d)",
(cc == SANITIZE_ERR_OK ? "SANITIZE_ERR_OK" :
cc == SANITIZE_ERR_BAD_ARGUMENT ? "SANITIZE_ERR_BAD_ARGUMENT" :
cc == SANITIZE_ERR_INVALID_PATH ? "SANITIZE_ERR_INVALID_PATH" :
cc == SANITIZE_ERR_OUT_OF_MEMORY ? "SANITIZE_ERR_OUT_OF_MEMORY":
"unexpected error code - add name"),
cc);
curl_msnprintf(buf, 256, "%s (%d)",
(cc == SANITIZE_ERR_OK ? "SANITIZE_ERR_OK" :
cc == SANITIZE_ERR_BAD_ARGUMENT ? "SANITIZE_ERR_BAD_ARGUMENT" :
cc == SANITIZE_ERR_INVALID_PATH ? "SANITIZE_ERR_INVALID_PATH" :
cc == SANITIZE_ERR_OUT_OF_MEMORY ? "SANITIZE_ERR_OUT_OF_MEMORY" :
"unexpected error code - add name"), cc);
}
return buf;
}
@ -225,21 +224,21 @@ static CURLcode test_tool1604(const char *arg)
abort_unless(expected_ccstr, "out of memory");
unitfail++;
fprintf(stderr, "\n"
"%s:%d sanitize_file_name failed.\n"
"input: %s\n"
"flags: %s\n"
"output: %s\n"
"result: %s\n"
"expected output: %s\n"
"expected result: %s\n",
__FILE__, __LINE__,
data[i].input,
flagstr,
(output ? output : "(null)"),
received_ccstr,
(data[i].expected_output ? data[i].expected_output : "(null)"),
expected_ccstr);
curl_mfprintf(stderr, "\n"
"%s:%d sanitize_file_name failed.\n"
"input: %s\n"
"flags: %s\n"
"output: %s\n"
"result: %s\n"
"expected output: %s\n"
"expected result: %s\n",
__FILE__, __LINE__,
data[i].input,
flagstr,
output ? output : "(null)",
received_ccstr,
data[i].expected_output ? data[i].expected_output : "(null)",
expected_ccstr);
free(output);
free(flagstr);
@ -248,7 +247,7 @@ static CURLcode test_tool1604(const char *arg)
}
/* END sanitize_file_name */
#else
fprintf(stderr, "Skipped test not for this platform\n");
curl_mfprintf(stderr, "Skipped test not for this platform\n");
#endif /* _WIN32 || MSDOS */
UNITTEST_END_SIMPLE

View file

@ -74,8 +74,9 @@ static CURLcode test_tool1621(const char *arg)
const char *url = tests[i].input;
char *stripped = stripcredentials(url);
const char *strippedstr = stripped ? stripped : "(null)";
printf("Test %u got input \"%s\", output: \"%s\", expected: \"%s\"\n",
i, tests[i].input, strippedstr, tests[i].output);
curl_mprintf("Test %u got input \"%s\", output: \"%s\", "
"expected: \"%s\"\n",
i, tests[i].input, strippedstr, tests[i].output);
fail_if(strcmp(tests[i].output, strippedstr), tests[i].output);
curl_free(stripped);