1 /* Tests for <support/blob_repeat.h>
2 Copyright (C) 2018-2020 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/blob_repeat.h>
21 #include <support/check.h>
26 struct support_blob_repeat repeat
27 = support_blob_repeat_allocate ("5", 1, 5);
28 TEST_COMPARE_BLOB (repeat
.start
, repeat
.size
, "55555", 5);
29 support_blob_repeat_free (&repeat
);
31 repeat
= support_blob_repeat_allocate ("ABC", 3, 3);
32 TEST_COMPARE_BLOB (repeat
.start
, repeat
.size
, "ABCABCABC", 9);
33 support_blob_repeat_free (&repeat
);
35 repeat
= support_blob_repeat_allocate ("abc", 4, 3);
36 TEST_COMPARE_BLOB (repeat
.start
, repeat
.size
, "abc\0abc\0abc", 12);
37 support_blob_repeat_free (&repeat
);
39 size_t gigabyte
= 1U << 30;
40 repeat
= support_blob_repeat_allocate ("X", 1, gigabyte
+ 1);
41 if (repeat
.start
== NULL
)
42 puts ("warning: not enough memory for 1 GiB mapping");
45 TEST_COMPARE (repeat
.size
, gigabyte
+ 1);
47 unsigned char *p
= repeat
.start
;
48 for (size_t i
= 0; i
< gigabyte
+ 1; ++i
)
50 FAIL_EXIT1 ("invalid byte 0x%02x at %zu", p
[i
], i
);
52 /* Check that there is no sharing across the mapping. */
55 for (size_t i
= 0; i
< gigabyte
+ 1; ++i
)
57 TEST_COMPARE (p
[i
], 'Y');
58 else if (i
== 1U << 24)
59 TEST_COMPARE (p
[i
], 'Z');
61 FAIL_EXIT1 ("invalid byte 0x%02x at %zu", p
[i
], i
);
64 support_blob_repeat_free (&repeat
);
66 repeat
= support_blob_repeat_allocate ("012345678", 9, 10 * 1000 * 1000);
67 if (repeat
.start
== NULL
)
68 puts ("warning: not enough memory for large mapping");
71 unsigned char *p
= repeat
.start
;
72 for (int i
= 0; i
< 10 * 1000 * 1000; ++i
)
73 for (int j
= 0; j
<= 8; ++j
)
74 if (p
[i
* 9 + j
] != '0' + j
)
76 printf ("error: element %d index %d\n", i
, j
);
77 TEST_COMPARE (p
[i
* 9 + j
], '0' + j
);
80 support_blob_repeat_free (&repeat
);
85 #include <support/test-driver.c>