blob: 01eb5ac651d69d649c263f39f8ead4ffc850cf2c [file] [log] [blame]
Louis Yung-Chieh Lob31ddce2010-05-21 16:35:44 +08001/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6#include "crc32_test.h"
7#include "cgptlib_test.h"
8#include "crc32.h"
vbendeb3ecaf772010-06-24 16:19:53 -07009#include "test_common.h"
Louis Yung-Chieh Lob31ddce2010-05-21 16:35:44 +080010#include "utility.h"
11
12#define MAX_VECTOR_LEN 256
13
14int TestCrc32TestVectors() {
15 struct {
16 uint8_t vector[MAX_VECTOR_LEN];
17 int len;
18 uint32_t crc32;
19 } cases[] = {
20 {{0x00}, 1, 0xD202EF8D},
21 {{0x00, 0x00, 0x00, 0x00}, 4, 0x2144DF1C},
22 {{0x01, 0x01, 0x01, 0x01}, 4, 0xF626D399},
23 {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
24 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
25 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
26 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
27 0x00,0x00,0x00,0x28,0x86,0x4d,0x7f,0x99}, 48, 0x923D6EFD},
28 {{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
29 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
30 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
31 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
32 0x00,0x00,0x00,0x28,0xc5,0x5e,0x45,0x7a}, 48, 0x49A04D82},
33 {{0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,
34 0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,
35 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,
36 0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,
37 0x00,0x00,0x00,0x28,0xbf,0x67,0x1e,0xd0}, 48, 0x688B3BFA},
38 };
39 int i;
40
41 for (i = 0; i < ARRAY_SIZE(cases); ++i) {
42 uint32_t crc32;
43
44 crc32 = Crc32(cases[i].vector, cases[i].len);
45 EXPECT(crc32 == cases[i].crc32);
46 }
47 return TEST_OK;
48}