diff options
author | Noah Goldstein <goldstein.w.n@gmail.com> | 2022-03-23 16:57:34 -0500 |
---|---|---|
committer | Noah Goldstein <goldstein.w.n@gmail.com> | 2022-03-25 11:46:13 -0500 |
commit | 46d19d1b83c52cc92d8215c7a1a032bcab3d271c (patch) | |
tree | 41a4c01df95f55fcb3b7de9ba3b9128918a9bcbf /string | |
parent | 1edbcc82b581c17fb9ebd233f8374c0825e4b12c (diff) | |
download | glibc-46d19d1b83c52cc92d8215c7a1a032bcab3d271c.zip glibc-46d19d1b83c52cc92d8215c7a1a032bcab3d271c.tar.gz glibc-46d19d1b83c52cc92d8215c7a1a032bcab3d271c.tar.bz2 |
string: Expand page cross tests in test-strncasecmp.c
Add more robust tests that cover all the page cross edge cases.
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Diffstat (limited to 'string')
-rw-r--r-- | string/test-strncasecmp.c | 166 |
1 files changed, 154 insertions, 12 deletions
diff --git a/string/test-strncasecmp.c b/string/test-strncasecmp.c index a3c8481..b86c630 100644 --- a/string/test-strncasecmp.c +++ b/string/test-strncasecmp.c @@ -18,6 +18,10 @@ #include <locale.h> #include <ctype.h> + +#define TEST_LEN (getpagesize () * 3) +#define MIN_PAGE_SIZE (TEST_LEN + 2 * getpagesize ()) + #define TEST_MAIN #define TEST_NAME "strncasecmp" #include "test-string.h" @@ -106,14 +110,15 @@ do_test (size_t align1, size_t align2, size_t n, size_t len, int max_char, if (len == 0) return; - align1 &= 7; - if (align1 + len + 1 >= page_size) + align1 &= getpagesize () - 1; + if (align1 + (len + 2) >= page_size) return; - align2 &= 7; - if (align2 + len + 1 >= page_size) + align2 &= getpagesize () - 1; + if (align2 + (len + 2) >= page_size) return; + s1 = (char *) (buf1 + align1); s2 = (char *) (buf2 + align2); @@ -126,12 +131,33 @@ do_test (size_t align1, size_t align2, size_t n, size_t len, int max_char, s1[len] = s2[len] = 0; s1[len + 1] = 23; s2[len + 1] = 24 + exp_result; + if ((s2[len - 1] == 'z' && exp_result == -1) || (s2[len - 1] == 'a' && exp_result == 1)) s1[len - 1] += exp_result; + else if ((s1[len - 1] == 'Z' + 1 && exp_result == 1) + || (s1[len - 1] == 'A' - 1 && exp_result == -1)) + s1[len - 1] = tolower (s2[len - 1]) + exp_result; else s2[len - 1] -= exp_result; + /* For some locals this is not guranteed yet. */ + if (tolower (s1[len - 1]) - tolower (s2[len - 1]) != exp_result) + { + if (exp_result == -1) + { + s1[len - 1] = tolower ('a'); + s2[len - 1] = toupper (tolower ('a') - 1); + } + else if (exp_result == 0) + s1[len - 1] = toupper (s2[len - 1]); + else + { + s1[len - 1] = tolower ('a'); + s2[len - 1] = toupper (tolower ('a') + 1); + } + } + FOR_EACH_IMPL (impl, 0) do_one_test (impl, s1, s2, n, exp_result); } @@ -299,10 +325,10 @@ bz14195 (void) } static void -test_locale (const char *locale) +test_locale (const char *locale, int extra_tests) { - size_t i; - + size_t i, j, k; + const size_t test_len = MIN(TEST_LEN, 3 * 4096); if (setlocale (LC_CTYPE, locale) == NULL) { error (0, 0, "cannot set locale \"%s\"", locale); @@ -374,6 +400,122 @@ test_locale (const char *locale) do_test (2 * i, i, (8 << i) + 100, 8 << i, 254, -1); } + for (j = 0; extra_tests && j < 160; ++j) + { + for (i = 0; i < test_len;) + { + do_test (getpagesize () - j - 1, 0, i + 1, i, 127, 0); + do_test (getpagesize () - j - 1, 0, i + 1, i, 127, 1); + do_test (getpagesize () - j - 1, 0, i + 1, i, 127, -1); + + do_test (getpagesize () - j - 1, 0, i, i, 127, 0); + do_test (getpagesize () - j - 1, 0, i - 1, i, 127, 0); + + do_test (getpagesize () - j - 1, 0, ULONG_MAX, i, 127, 0); + do_test (getpagesize () - j - 1, 0, ULONG_MAX, i, 127, 1); + do_test (getpagesize () - j - 1, 0, ULONG_MAX, i, 127, -1); + + do_test (getpagesize () - j - 1, 0, ULONG_MAX - i, i, 127, 0); + do_test (getpagesize () - j - 1, 0, ULONG_MAX - i, i, 127, 1); + do_test (getpagesize () - j - 1, 0, ULONG_MAX - i, i, 127, -1); + + do_test (getpagesize () - j - 1, j, i + 1, i, 127, 0); + do_test (getpagesize () - j - 1, j, i + 1, i, 127, 1); + do_test (getpagesize () - j - 1, j, i + 1, i, 127, -1); + + do_test (getpagesize () - j - 1, j, i, i, 127, 0); + do_test (getpagesize () - j - 1, j, i - 1, i, 127, 0); + + do_test (getpagesize () - j - 1, j, ULONG_MAX, i, 127, 0); + do_test (getpagesize () - j - 1, j, ULONG_MAX, i, 127, 1); + do_test (getpagesize () - j - 1, j, ULONG_MAX, i, 127, -1); + + do_test (getpagesize () - j - 1, j, ULONG_MAX - i, i, 127, 0); + do_test (getpagesize () - j - 1, j, ULONG_MAX - i, i, 127, 1); + do_test (getpagesize () - j - 1, j, ULONG_MAX - i, i, 127, -1); + + do_test (0, getpagesize () - j - 1, i + 1, i, 127, 0); + do_test (0, getpagesize () - j - 1, i + 1, i, 127, 1); + do_test (0, getpagesize () - j - 1, i + 1, i, 127, -1); + + do_test (0, getpagesize () - j - 1, i, i, 127, 0); + do_test (0, getpagesize () - j - 1, i - 1, i, 127, 0); + + do_test (0, getpagesize () - j - 1, ULONG_MAX, i, 127, 0); + do_test (0, getpagesize () - j - 1, ULONG_MAX, i, 127, 1); + do_test (0, getpagesize () - j - 1, ULONG_MAX, i, 127, -1); + + do_test (0, getpagesize () - j - 1, ULONG_MAX - i, i, 127, 0); + do_test (0, getpagesize () - j - 1, ULONG_MAX - i, i, 127, 1); + do_test (0, getpagesize () - j - 1, ULONG_MAX - i, i, 127, -1); + + do_test (j, getpagesize () - j - 1, i + 1, i, 127, 0); + do_test (j, getpagesize () - j - 1, i + 1, i, 127, 1); + do_test (j, getpagesize () - j - 1, i + 1, i, 127, -1); + + do_test (j, getpagesize () - j - 1, i, i, 127, 0); + do_test (j, getpagesize () - j - 1, i - 1, i, 127, 0); + + do_test (j, getpagesize () - j - 1, ULONG_MAX, i, 127, 0); + do_test (j, getpagesize () - j - 1, ULONG_MAX, i, 127, 1); + do_test (j, getpagesize () - j - 1, ULONG_MAX, i, 127, -1); + + do_test (j, getpagesize () - j - 1, ULONG_MAX - i, i, 127, 0); + do_test (j, getpagesize () - j - 1, ULONG_MAX - i, i, 127, 1); + do_test (j, getpagesize () - j - 1, ULONG_MAX - i, i, 127, -1); + + for (k = 2; k <= 128; k += k) + { + do_test (getpagesize () - k, getpagesize () - j - 1, i - 1, i, + 127, 0); + do_test (getpagesize () - k - 1, getpagesize () - j - 1, i - 1, + i, 127, 0); + do_test (getpagesize () - k, getpagesize () - j - 1, i + 1, i, + 127, 0); + do_test (getpagesize () - k - 1, getpagesize () - j - 1, i + 1, + i, 127, 0); + do_test (getpagesize () - k, getpagesize () - j - 1, i, i, 127, + 0); + do_test (getpagesize () - k - 1, getpagesize () - j - 1, i, i, + 127, 0); + do_test (getpagesize () - k, getpagesize () - j - 1, i + 1, i, + 127, -1); + do_test (getpagesize () - k - 1, getpagesize () - j - 1, i + 1, + i, 127, -1); + do_test (getpagesize () - k, getpagesize () - j - 1, i + 1, i, + 127, 1); + do_test (getpagesize () - k - 1, getpagesize () - j - 1, i + 1, + i, 127, 1); + } + if (i < 32) + { + i += 1; + } + else if (i < 161) + { + i += 7; + } + else if (i + 161 < test_len) + { + i += 31; + i *= 17; + i /= 16; + if (i + 161 > test_len) + { + i = test_len - 160; + } + } + else if (i + 32 < test_len) + { + i += 7; + } + else + { + i += 1; + } + } + } + do_random_tests (); do_page_tests (); } @@ -383,11 +525,11 @@ test_main (void) { test_init (); - test_locale ("C"); - test_locale ("en_US.ISO-8859-1"); - test_locale ("en_US.UTF-8"); - test_locale ("tr_TR.ISO-8859-9"); - test_locale ("tr_TR.UTF-8"); + test_locale ("C", 1); + test_locale ("en_US.ISO-8859-1", 0); + test_locale ("en_US.UTF-8", 0); + test_locale ("tr_TR.ISO-8859-9", 0); + test_locale ("tr_TR.UTF-8", 0); return ret; } |