2
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
* You can also choose to distribute this program under the terms of
20
* the Unmodified Binary Distribution Licence (as given in the file
21
* COPYING.UBDL), provided that you have satisfied its requirements.
24
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
31
* Test vectors generated using Perl's Digest::CRC:
33
* use Digest::CRC qw ( crc );
35
* printf "%#08x", crc ( $data, 32, $seed, 0, 1, 0x04c11db7, 1 );
39
/* Forcibly enable assertions */
43
#include <ipxe/crc32.h>
44
#include <ipxe/test.h>
46
/** Define inline data */
47
#define DATA(...) { __VA_ARGS__ }
53
/** Length of test data */
67
* @v CRC32 Expected CRC32
68
* @ret test CRC32 test
70
#define CRC32_TEST( name, DATA, SEED, CRC32 ) \
71
static const uint8_t name ## _data[] = DATA; \
72
static struct crc32_test name = { \
73
.data = name ## _data, \
74
.len = sizeof ( name ## _data ), \
80
* Report a CRC32 test result
84
#define crc32_ok( test ) do { \
86
crc32 = crc32_le ( (test)->seed, (test)->data, (test)->len ); \
87
ok ( crc32 == (test)->crc32 ); \
91
CRC32_TEST ( empty_test,
93
0x12345678UL, 0x12345678UL );
95
DATA ( 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd' ),
96
0xffffffffUL, 0xf2b5ee7aUL );
97
CRC32_TEST ( hw_split_part1_test,
98
DATA ( 'h', 'e', 'l', 'l', 'o' ),
99
0xffffffffUL, 0xc9ef5979UL );
100
CRC32_TEST ( hw_split_part2_test,
101
DATA ( ' ', 'w', 'o', 'r', 'l', 'd' ),
102
0xc9ef5979UL, 0xf2b5ee7aUL );
105
* Perform CRC32 self-tests
108
static void crc32_test_exec ( void ) {
110
crc32_ok ( &empty_test );
111
crc32_ok ( &hw_test );
112
crc32_ok ( &hw_split_part1_test );
113
crc32_ok ( &hw_split_part2_test );
116
/** CRC32 self-test */
117
struct self_test crc32_test __self_test = {
119
.exec = crc32_test_exec,