]> git.ipfire.org Git - thirdparty/glibc.git/blame - support/support_test_compare_failure.c
support: Increase usability of TEST_COMPARE
[thirdparty/glibc.git] / support / support_test_compare_failure.c
CommitLineData
93485524 1/* Reporting a numeric comparison failure.
688903eb 2 Copyright (C) 2017-2018 Free Software Foundation, Inc.
93485524
FW
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 <http://www.gnu.org/licenses/>. */
18
19#include <stdio.h>
20#include <support/check.h>
21
22static void
2b3aa446 23report (const char *which, const char *expr, long long value, int positive,
93485524
FW
24 int size)
25{
26 printf (" %s: ", which);
2b3aa446 27 if (positive)
93485524 28 printf ("%llu", (unsigned long long) value);
2b3aa446
FW
29 else
30 printf ("%lld", value);
93485524
FW
31 unsigned long long mask
32 = (~0ULL) >> (8 * (sizeof (unsigned long long) - size));
33 printf (" (0x%llx); from: %s\n", (unsigned long long) value & mask, expr);
34}
35
36void
37support_test_compare_failure (const char *file, int line,
38 const char *left_expr,
39 long long left_value,
2b3aa446 40 int left_positive,
93485524
FW
41 int left_size,
42 const char *right_expr,
43 long long right_value,
2b3aa446 44 int right_positive,
93485524
FW
45 int right_size)
46{
47 support_record_failure ();
48 if (left_size != right_size)
49 printf ("%s:%d: numeric comparison failure (widths %d and %d)\n",
50 file, line, left_size * 8, right_size * 8);
51 else
52 printf ("%s:%d: numeric comparison failure\n", file, line);
2b3aa446
FW
53 report (" left", left_expr, left_value, left_positive, left_size);
54 report ("right", right_expr, right_value, right_positive, right_size);
93485524 55}