]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/x86/tst-strncmp-rtm.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / x86 / tst-strncmp-rtm.c
CommitLineData
4bd660be 1/* Test case for strncmp inside a transactionally executing RTM region.
6d7e8eda 2 Copyright (C) 2021-2023 Free Software Foundation, Inc.
4bd660be
L
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
c6272098 19#include <stdint.h>
4bd660be
L
20#include <tst-string-rtm.h>
21
7835d611
NG
22#ifdef WIDE
23# define CHAR wchar_t
24# define MEMSET wmemset
25# define STRNCMP wcsncmp
b98d0bbf 26# define TEST_NAME "wcsncmp"
7835d611
NG
27#else /* !WIDE */
28# define CHAR char
29# define MEMSET memset
7c8ca178
NG
30# ifndef STRNCMP
31# define STRNCMP strncmp
32# define TEST_NAME "strncmp"
33# endif
7835d611
NG
34#endif /* !WIDE */
35
36
37
4bd660be
L
38#define LOOP 3000
39#define STRING_SIZE 1024
7835d611
NG
40CHAR string1[STRING_SIZE];
41CHAR string2[STRING_SIZE];
4bd660be
L
42
43__attribute__ ((noinline, noclone))
44static int
45prepare (void)
46{
7835d611
NG
47 MEMSET (string1, 'a', STRING_SIZE - 1);
48 MEMSET (string2, 'a', STRING_SIZE - 1);
49 if (STRNCMP (string1, string2, STRING_SIZE) == 0)
4bd660be
L
50 return EXIT_SUCCESS;
51 else
52 return EXIT_FAILURE;
53}
54
55__attribute__ ((noinline, noclone))
56static int
57function (void)
58{
7835d611 59 if (STRNCMP (string1, string2, STRING_SIZE) == 0)
4bd660be
L
60 return 0;
61 else
62 return 1;
63}
64
c6272098
NG
65__attribute__ ((noinline, noclone))
66static int
67function_overflow (void)
68{
7835d611 69 if (STRNCMP (string1, string2, SIZE_MAX) == 0)
c6272098
NG
70 return 0;
71 else
72 return 1;
73}
74
9fef7039
NG
75__attribute__ ((noinline, noclone))
76static int
77function_overflow2 (void)
78{
79 if (STRNCMP (string1, string2, SIZE_MAX >> 4) == 0)
80 return 0;
81 else
82 return 1;
83}
84
4bd660be
L
85static int
86do_test (void)
87{
7835d611 88 int status = do_test_1 (TEST_NAME, LOOP, prepare, function);
c6272098
NG
89 if (status != EXIT_SUCCESS)
90 return status;
7835d611 91 status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow);
9fef7039
NG
92 if (status != EXIT_SUCCESS)
93 return status;
94 status = do_test_1 (TEST_NAME, LOOP, prepare, function_overflow2);
95 if (status != EXIT_SUCCESS)
96 return status;
c6272098 97 return status;
4bd660be 98}