-
Notifications
You must be signed in to change notification settings - Fork 12
/
crc32_stress.c
92 lines (76 loc) · 1.87 KB
/
crc32_stress.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Test POWER8 128 bit checksum algorithm
*
* Copyright (C) 2015 Anton Blanchard <[email protected]>, IBM
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of either:
*
* a) the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version, or
* b) the Apache License, Version 2.0
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include "crcmodel.h"
#include "crc32_constants.h"
#define MAX_CRC_LENGTH (128*1024)
unsigned int crc32_vpmsum(unsigned int crc, unsigned char *p,
unsigned long len);
static unsigned int verify_crc(unsigned int crc, unsigned char *p,
unsigned long len)
{
cm_t cm_t = { 0, };
int i;
cm_t.cm_width = 32;
cm_t.cm_poly = CRC;
cm_t.cm_init = crc;
#ifdef REFLECT
cm_t.cm_refin = TRUE;
cm_t.cm_refot = TRUE;
#else
cm_t.cm_refin = FALSE;
cm_t.cm_refot = FALSE;
#endif
#ifdef CRC_XOR
cm_t.cm_init ^= 0xffffffff;
cm_t.cm_xorot = 0xffffffff;
#else
cm_t.cm_xorot = 0x0;
#endif
cm_ini(&cm_t);
for (i = 0; i < len; i++)
cm_nxt(&cm_t, p[i]);
return cm_crc(&cm_t);
}
#define VMX_ALIGN 16
#define VMX_ALIGN_MASK (VMX_ALIGN-1)
int main(void)
{
unsigned char *data;
unsigned int crc = 0, verify = 0;
data = memalign(VMX_ALIGN, MAX_CRC_LENGTH+VMX_ALIGN_MASK);
if (!data) {
perror("memalign");
exit(1);
}
srandom(1);
while (1) {
unsigned int len, offset;
unsigned long i;
for (i = 0; i < MAX_CRC_LENGTH; i++)
data[i] = random() & 0xff;
len = random() % MAX_CRC_LENGTH;
offset = random() & VMX_ALIGN_MASK;
crc = crc32_vpmsum(crc, data+offset, len);
verify = verify_crc(verify, data+offset, len);
if (crc != verify) {
fprintf(stderr, "FAILURE: got 0x%08x expected 0x%08x (len %d)\n", crc, verify, len);
crc = verify;
}
}
return 0;
}