1 /* Basic test for the TEST_COMPARE macro.
2 Copyright (C) 2017-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
20 #include <support/check.h>
21 #include <support/capture_subprocess.h>
24 subprocess (void *closure
)
27 /* These tests should fail. */
28 TEST_COMPARE (ch
, -1); /* Line 28. */
29 TEST_COMPARE (2LL, -2LL); /* Line 29. */
30 TEST_COMPARE (3LL, (short) -3); /* Line 30. */
40 unsigned int u31
: 31 ;
41 long long int i63
: 63;
42 unsigned long long int u63
: 63;
45 /* Functions which return signed sizes are common, so test that these
46 results can readily checked using TEST_COMPARE. */
64 /* This should succeed. */
66 TEST_COMPARE (2LL, 2U);
69 unsigned short u16
= 3;
70 TEST_COMPARE (i8
, u16
);
72 TEST_COMPARE (return_ssize_t (), sizeof (char[4]));
73 TEST_COMPARE (return_int (), sizeof (char[4]));
75 struct bitfield bitfield
= { 0 };
76 TEST_COMPARE (bitfield
.i2
, bitfield
.i3
);
77 TEST_COMPARE (bitfield
.u2
, bitfield
.u3
);
78 TEST_COMPARE (bitfield
.u2
, bitfield
.i3
);
79 TEST_COMPARE (bitfield
.u3
, bitfield
.i3
);
80 TEST_COMPARE (bitfield
.i2
, bitfield
.u3
);
81 TEST_COMPARE (bitfield
.i3
, bitfield
.u2
);
82 TEST_COMPARE (bitfield
.i63
, bitfield
.i63
);
83 TEST_COMPARE (bitfield
.u63
, bitfield
.u63
);
84 TEST_COMPARE (bitfield
.i31
, bitfield
.i63
);
85 TEST_COMPARE (bitfield
.i63
, bitfield
.i31
);
87 struct support_capture_subprocess proc
= support_capture_subprocess
90 /* Discard the reported error. */
91 support_record_failure_reset ();
93 puts ("info: *** subprocess output starts ***");
94 fputs (proc
.out
.buffer
, stdout
);
95 puts ("info: *** subprocess output ends ***");
98 (strcmp (proc
.out
.buffer
,
99 "tst-test_compare.c:28: numeric comparison failure\n"
100 " left: 1 (0x1); from: ch\n"
101 " right: -1 (0xffffffff); from: -1\n"
102 "tst-test_compare.c:29: numeric comparison failure\n"
103 " left: 2 (0x2); from: 2LL\n"
104 " right: -2 (0xfffffffffffffffe); from: -2LL\n"
105 "tst-test_compare.c:30: numeric comparison failure"
106 " (widths 64 and 32)\n"
107 " left: 3 (0x3); from: 3LL\n"
108 " right: -3 (0xfffffffd); from: (short) -3\n") == 0);
110 /* Check that there is no output on standard error. */
111 support_capture_subprocess_check (&proc
, "TEST_COMPARE", 0, sc_allow_stdout
);
116 #include <support/test-driver.c>