support: Report errno constants in TEST_COMPARE failures

If the expression is errno, decode it as an errno constant
using strerrorname_np.

Reviewed-by: Arjun Shankar <arjun@redhat.com>
This commit is contained in:
Florian Weimer 2024-08-22 16:14:17 +02:00
parent 79f44e1a47
commit 34e52acd55

View File

@ -17,7 +17,9 @@
<https://www.gnu.org/licenses/>. */ <https://www.gnu.org/licenses/>. */
#include <errno.h> #include <errno.h>
#include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <support/check.h> #include <support/check.h>
static void static void
@ -31,7 +33,14 @@ report (const char *which, const char *expr, long long value, int positive,
printf ("%lld", value); printf ("%lld", value);
unsigned long long mask unsigned long long mask
= (~0ULL) >> (8 * (sizeof (unsigned long long) - size)); = (~0ULL) >> (8 * (sizeof (unsigned long long) - size));
printf (" (0x%llx); from: %s\n", (unsigned long long) value & mask, expr); const char *errno_constant = NULL;
if (strcmp (expr, "errno") == 0
&& positive && (unsigned long long int) value <= INT_MAX)
errno_constant = strerrorname_np (value);
printf (" (0x%llx", (unsigned long long) value & mask);
if (errno_constant != NULL)
printf (", %s", errno_constant);
printf ("); from: %s\n", expr);
} }
void void