1 /* Test case for strcmp inside a transactionally executing RTM
2 region.
3 Copyright (C) 2022 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20 #include <stdint.h>
21 #include <tst-string-rtm.h>
22
23 #ifdef WIDE
24 # define CHAR wchar_t
25 # define MEMSET wmemset
26 # define STRCMP wcscmp
27 # define TEST_NAME "wcscmp"
28 #else /* !WIDE */
29 # define CHAR char
30 # define MEMSET memset
31
32 # ifndef STRCMP
33 # define STRCMP strcmp
34 # define TEST_NAME "strcmp"
35 # endif
36 #endif
37
38 #define LOOP 3000
39 #define STRING_SIZE 1024
40 CHAR string1[STRING_SIZE];
41 CHAR string2[STRING_SIZE];
42
43 __attribute__ ((noinline, noclone))
44 static int
prepare(void)45 prepare (void)
46 {
47 MEMSET (string1, 'a', STRING_SIZE - 1);
48 MEMSET (string2, 'a', STRING_SIZE - 1);
49 if (STRCMP (string1, string2) == 0)
50 return EXIT_SUCCESS;
51 else
52 return EXIT_FAILURE;
53 }
54
55 __attribute__ ((noinline, noclone))
56 static int
function(void)57 function (void)
58 {
59 if (STRCMP (string1, string2) == 0)
60 return 0;
61 else
62 return 1;
63 }
64
65
66 static int
do_test(void)67 do_test (void)
68 {
69 return do_test_1 (TEST_NAME, LOOP, prepare, function);
70 }
71