1 /* Testcase for http://sourceware.org/bugzilla/show_bug.cgi?id=14090.
2 Copyright (C) 2012-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; version 2 of the License, or
8 (at your option) any later version.
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>. */
26 /* This test will not work with 32-bit size_t, so let it succeed
28 #if SIZE_MAX <= UINT32_MAX
36 # define CONST_2G 0x080000000
37 # define CONST_10G 0x280000000
39 /* MD5 sum values of zero-filled blocks of specified sizes. */
40 static const struct test_data_s
46 { "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e",
48 { "\xa9\x81\x13\x0c\xf2\xb7\xe0\x9f\x46\x86\xdc\x27\x3c\xf7\x18\x7e",
50 { "\xc9\xa5\xa6\x87\x8d\x97\xb4\x8c\xc9\x65\xc1\xe4\x18\x59\xf0\x34",
52 { "\x58\xcf\x63\x8a\x73\x3f\x91\x90\x07\xb4\x28\x7c\xf5\x39\x6d\x0c",
54 { "\xb7\x70\x35\x1f\xad\xae\x5a\x96\xbb\xaf\x97\x02\xed\x97\xd2\x8d",
56 { "\x2d\xd2\x6c\x4d\x47\x99\xeb\xd2\x9f\xa3\x1e\x48\xd4\x9e\x8e\x53",
61 report (const char *id
, const char *md5
, size_t len
, const char *ref
)
63 if (memcmp (md5
, ref
, 16))
65 printf ("test %s with size %zd failed\n", id
, len
);
71 /* Test md5 in a single md5_process_bytes call. */
73 test_single (void *buf
, size_t len
, const char *ref
)
78 __md5_init_ctx (&ctx
);
79 __md5_process_bytes (buf
, len
, &ctx
);
80 __md5_finish_ctx (&ctx
, sum
);
82 return report ("single", sum
, len
, ref
);
85 /* Test md5 with two md5_process_bytes calls to trigger a
86 different path in md5_process_block for sizes > 2 GB. */
88 test_double (void *buf
, size_t len
, const char *ref
)
93 __md5_init_ctx (&ctx
);
96 __md5_process_bytes (buf
, CONST_2G
, &ctx
);
97 __md5_process_bytes (buf
+ CONST_2G
, len
- CONST_2G
, &ctx
);
100 __md5_process_bytes (buf
, len
, &ctx
);
102 __md5_finish_ctx (&ctx
, sum
);
104 return report ("double", sum
, len
, ref
);
115 buf
= mmap64 (0, CONST_10G
, PROT_READ
, MAP_ANONYMOUS
| MAP_PRIVATE
, -1, 0);
116 if (buf
== MAP_FAILED
)
118 puts ("Could not allocate 10 GB via mmap, skipping test.");
122 for (j
= 0; j
< sizeof (test_data
) / sizeof (struct test_data_s
); j
++)
124 if (test_single (buf
, test_data
[j
].len
, test_data
[j
].ref
))
126 if (test_double (buf
, test_data
[j
].len
, test_data
[j
].ref
))
134 /* This needs on a fast machine 90s. */
136 #define TEST_FUNCTION do_test ()
137 #include "../test-skeleton.c"