libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 2e76bcf260b223d508ff40b77f2d6a3790eb4be6
parent 49b44ba5d3fdfee19d8b9504a8eaa0cbadf65b35
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Sun,  3 Aug 2025 00:17:18 +0200

test_upgrade: corrected exit error codes

Diffstat:
Msrc/tests/upgrade/test_upgrade.c | 70+++++++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 39 insertions(+), 31 deletions(-)

diff --git a/src/tests/upgrade/test_upgrade.c b/src/tests/upgrade/test_upgrade.c @@ -109,43 +109,46 @@ MHD_NORETURN_ static void -_externalErrorExit_func (const char *errDesc, const char *funcName, int lineNum) +_externalErrorExit_func (const char *errDesc, const char *funcName, + int lineNum, int test_failed) { + int last_errno = errno; fflush (stdout); if ((NULL != errDesc) && (0 != errDesc[0])) - fprintf (stderr, "%s", errDesc); + fprintf (stderr, "!!! %s", errDesc); else - fprintf (stderr, "System or external library call failed"); + fprintf (stderr, "!!! System or external library call failed"); if ((NULL != funcName) && (0 != funcName[0])) fprintf (stderr, " in %s", funcName); if (0 < lineNum) fprintf (stderr, " at line %d", lineNum); - fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno, - strerror (errno)); + fprintf (stderr, ".\nLast errno value: %d (%s)\n", last_errno, + strerror (last_errno)); #ifdef MHD_SOCKETS_KIND_WINSOCK fprintf (stderr, "WSAGetLastError() value: %d\n", (int) WSAGetLastError ()); #endif /* MHD_SOCKETS_KIND_WINSOCK */ fflush (stderr); - exit (99); + exit (test_failed ? 9 : 99); } MHD_NORETURN_ static void _mhdErrorExit_func (const char *errDesc, const char *funcName, int lineNum) { + int last_errno = errno; fflush (stdout); if ((NULL != errDesc) && (0 != errDesc[0])) - fprintf (stderr, "%s", errDesc); + fprintf (stderr, "!!! %s", errDesc); else - fprintf (stderr, "MHD unexpected error"); + fprintf (stderr, "!!! MHD unexpected error"); if ((NULL != funcName) && (0 != funcName[0])) fprintf (stderr, " in %s", funcName); if (0 < lineNum) fprintf (stderr, " at line %d", lineNum); - fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno, - strerror (errno)); + fprintf (stderr, ".\nLast errno value: %d (%s)\n", last_errno, + strerror (last_errno)); fflush (stderr); exit (8); @@ -155,18 +158,19 @@ _mhdErrorExit_func (const char *errDesc, const char *funcName, int lineNum) static void _testErrorLog_func (const char *errDesc, const char *funcName, int lineNum) { + int last_errno = errno; fflush (stdout); if ((NULL != errDesc) && (0 != errDesc[0])) - fprintf (stderr, "%s", errDesc); + fprintf (stderr, "!!! %s", errDesc); else - fprintf (stderr, "System or external library call resulted in error"); + fprintf (stderr, "!!! System or external library call resulted in error"); if ((NULL != funcName) && (0 != funcName[0])) fprintf (stderr, " in %s", funcName); if (0 < lineNum) fprintf (stderr, " at line %d", lineNum); - fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno, - strerror (errno)); + fprintf (stderr, ".\nLast errno value: %d (%s)\n", last_errno, + strerror (last_errno)); #ifdef MHD_SOCKETS_KIND_WINSOCK fprintf (stderr, "WSAGetLastError() value: %d\n", (int) WSAGetLastError ()); #endif /* MHD_SOCKETS_KIND_WINSOCK */ @@ -175,10 +179,12 @@ _testErrorLog_func (const char *errDesc, const char *funcName, int lineNum) #ifdef MHD_HAVE_MHD_FUNC_ -#define externalErrorExit(ignore) \ - _externalErrorExit_func (NULL, MHD_FUNC_, __LINE__) +#define externalErrorExit() \ + _externalErrorExit_func (NULL, MHD_FUNC_, __LINE__, 0) #define externalErrorExitDesc(errDesc) \ - _externalErrorExit_func (errDesc, MHD_FUNC_, __LINE__) + _externalErrorExit_func (errDesc, MHD_FUNC_, __LINE__, 0) +#define testFailedExitDesc(errDesc) \ + _externalErrorExit_func (errDesc, MHD_FUNC_, __LINE__, ! 0) #define mhdErrorExit(ignore) \ _mhdErrorExit_func (NULL, MHD_FUNC_, __LINE__) #define mhdErrorExitDesc(errDesc) \ @@ -188,9 +194,11 @@ _testErrorLog_func (const char *errDesc, const char *funcName, int lineNum) #define testErrorLogDesc(errDesc) \ _testErrorLog_func (errDesc, MHD_FUNC_, __LINE__) #else /* ! MHD_HAVE_MHD_FUNC_ */ -#define externalErrorExit(ignore) _externalErrorExit_func (NULL, NULL, __LINE__) +#define externalErrorExit() _externalErrorExit_func (NULL, NULL, __LINE__, 0) #define externalErrorExitDesc(errDesc) \ - _externalErrorExit_func (errDesc, NULL, __LINE__) + _externalErrorExit_func (errDesc, NULL, __LINE__, 0) +#define testFailedExitDesc(errDesc) \ + _externalErrorExit_func (errDesc, NULL, __LINE__, ! 0) #define mhdErrorExit(ignore) _mhdErrorExit_func (NULL, NULL, __LINE__) #define mhdErrorExitDesc(errDesc) _mhdErrorExit_func (errDesc, NULL, __LINE__) #define testErrorLog(ignore) _testErrorLog_func (NULL, NULL, __LINE__) @@ -1163,7 +1171,7 @@ send_all (struct wr_socket *sock, ret = 0; continue; } - externalErrorExitDesc ("send() failed"); + testFailedExitDesc ("send() failed"); } } } @@ -1198,10 +1206,10 @@ recv_hdr (struct wr_socket *sock) continue; if (mhd_SCKT_ERR_IS_EINTR (mhd_SCKT_GET_LERR ())) continue; - externalErrorExitDesc ("recv() failed"); + testFailedExitDesc ("recv() failed"); } if (0 == ret) - mhdErrorExitDesc ("The server unexpectedly closed connection"); + testFailedExitDesc ("The server unexpectedly closed connection"); if (c == next) { i++; @@ -1250,7 +1258,7 @@ recv_all (struct wr_socket *sock, ret = 0; continue; } - externalErrorExitDesc ("recv() failed"); + testFailedExitDesc ("recv() failed"); } else if (0 == ret) { @@ -1261,7 +1269,7 @@ recv_all (struct wr_socket *sock, mhdErrorExitDesc ("The server unexpectedly closed connection"); } if ((data_size - rcvd) < (size_t) ret) - externalErrorExitDesc ("recv() returned excessive amount of data"); + testFailedExitDesc ("recv() returned excessive amount of data"); if (0 != memcmp (data, buf, rcvd + (size_t) ret)) { fprintf (stderr, "Wrong received text. Expected: '%.*s'. " @@ -1331,7 +1339,7 @@ receive_eof (struct wr_socket *sock) ret = 0; continue; } - externalErrorExitDesc ("recv() failed"); + testFailedExitDesc ("recv() failed"); } else if (0 == ret) { @@ -1394,8 +1402,8 @@ recv_upg_all (struct MHD_UpgradedHandle *urh, mhdErrorExitDesc ("The server unexpectedly closed connection"); } if ((data_size - rcvd) < last_rcvd) - externalErrorExitDesc ("MHD_upgraded_recv() returned excessive " \ - "amount of data"); + mhdErrorExitDesc ("MHD_upgraded_recv() returned excessive " \ + "amount of data"); if (0 != memcmp (data, buf, rcvd + (size_t) last_rcvd)) { fprintf (stderr, "Wrong received text. Expected: '%.*s'. " @@ -1738,11 +1746,11 @@ test_upgrade (void) } #endif /* HTTPS_SUPPORT && HAVE_FORK && HAVE_WAITPID */ if (! client_done) - externalErrorExitDesc ("The client thread has not signalled " \ - "successful finish"); + testFailedExitDesc ("The client thread has not signalled " \ + "successful finish"); if (! app_done) - externalErrorExitDesc ("The application thread has not signalled " \ - "successful finish"); + testFailedExitDesc ("The application thread has not signalled " \ + "successful finish"); MHD_daemon_destroy (d); return 0; }