1 /* Reporting a numeric comparison failure.
2 Copyright (C) 2017-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <errno.h>
20 #include <stdio.h>
21 #include <support/check.h>
22
23 static void
report(const char * which,const char * expr,long long value,int positive,int size)24 report (const char *which, const char *expr, long long value, int positive,
25 int size)
26 {
27 printf (" %s: ", which);
28 if (positive)
29 printf ("%llu", (unsigned long long) value);
30 else
31 printf ("%lld", value);
32 unsigned long long mask
33 = (~0ULL) >> (8 * (sizeof (unsigned long long) - size));
34 printf (" (0x%llx); from: %s\n", (unsigned long long) value & mask, expr);
35 }
36
37 void
support_test_compare_failure(const char * file,int line,const char * left_expr,long long left_value,int left_positive,int left_size,const char * right_expr,long long right_value,int right_positive,int right_size)38 support_test_compare_failure (const char *file, int line,
39 const char *left_expr,
40 long long left_value,
41 int left_positive,
42 int left_size,
43 const char *right_expr,
44 long long right_value,
45 int right_positive,
46 int right_size)
47 {
48 int saved_errno = errno;
49 support_record_failure ();
50 if (left_size != right_size)
51 printf ("%s:%d: numeric comparison failure (widths %d and %d)\n",
52 file, line, left_size * 8, right_size * 8);
53 else
54 printf ("%s:%d: numeric comparison failure\n", file, line);
55 report (" left", left_expr, left_value, left_positive, left_size);
56 report ("right", right_expr, right_value, right_positive, right_size);
57 errno = saved_errno;
58 }
59