1 |
786 |
skrzyp |
//=================================================================
|
2 |
|
|
//
|
3 |
|
|
// crc_test.c
|
4 |
|
|
//
|
5 |
|
|
// crc test cases
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 2002, 2009 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): asl
|
43 |
|
|
// Contributors: asl
|
44 |
|
|
// Date: 2002-08-06
|
45 |
|
|
// Description: Tests the calculation code
|
46 |
|
|
//####DESCRIPTIONEND####
|
47 |
|
|
|
48 |
|
|
#include <cyg/infra/testcase.h>
|
49 |
|
|
#include <cyg/crc/crc.h>
|
50 |
|
|
|
51 |
|
|
static char license_txt[] =
|
52 |
|
|
" GNU GENERAL PUBLIC LICENSE\n"
|
53 |
|
|
" Version 2, June 1991\n"
|
54 |
|
|
"\n"
|
55 |
|
|
" Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n"
|
56 |
|
|
" 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
|
57 |
|
|
" Everyone is permitted to copy and distribute verbatim copies\n"
|
58 |
|
|
" of this license document, but changing it is not allowed.\n"
|
59 |
|
|
"\n"
|
60 |
|
|
" Preamble\n"
|
61 |
|
|
"\n"
|
62 |
|
|
" The licenses for most software are designed to take away your\n"
|
63 |
|
|
"freedom to share and change it. By contrast, the GNU General Public\n"
|
64 |
|
|
"License is intended to guarantee your freedom to share and change free\n"
|
65 |
|
|
"software--to make sure the software is free for all its users. This\n"
|
66 |
|
|
"General Public License applies to most of the Free Software\n"
|
67 |
|
|
"Foundation's software and to any other program whose authors commit to\n"
|
68 |
|
|
"using it. (Some other Free Software Foundation software is covered by\n"
|
69 |
|
|
"the GNU Library General Public License instead.) You can apply it to\n"
|
70 |
|
|
"your programs, too.";
|
71 |
|
|
|
72 |
|
|
externC void
|
73 |
|
|
cyg_start( void )
|
74 |
|
|
{
|
75 |
|
|
unsigned long crc1,crc2;
|
76 |
|
|
|
77 |
|
|
CYG_TEST_INIT();
|
78 |
|
|
|
79 |
|
|
CYG_TEST_INFO("Calculating CRCs");
|
80 |
|
|
|
81 |
|
|
if (1500790746UL != cyg_posix_crc32((unsigned char *)license_txt,
|
82 |
|
|
sizeof(license_txt)-1)) {
|
83 |
|
|
CYG_TEST_FAIL("Wrong POSIX CRC32 calculation");
|
84 |
|
|
} else {
|
85 |
|
|
CYG_TEST_PASS("POSIX CRC32 calculation");
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
if (1667500021UL != cyg_ether_crc32((unsigned char *)license_txt,
|
89 |
|
|
sizeof(license_txt)-1)) {
|
90 |
|
|
CYG_TEST_FAIL("Wrong Ethernet crc32 calculation");
|
91 |
|
|
} else {
|
92 |
|
|
CYG_TEST_PASS("Ethernet crc32 calculation");
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
if (0 != cyg_ether_crc32_accumulate(0,0,0)) {
|
96 |
|
|
CYG_TEST_FAIL("Ethernet crc32 accumulate setup");
|
97 |
|
|
} else {
|
98 |
|
|
crc1= cyg_ether_crc32_accumulate(0, (unsigned char *)license_txt,
|
99 |
|
|
sizeof(license_txt)-1);
|
100 |
|
|
crc2 = cyg_ether_crc32_accumulate(crc1, (unsigned char *)license_txt,
|
101 |
|
|
sizeof(license_txt)-1);
|
102 |
|
|
|
103 |
|
|
if ((1667500021UL != crc1) || (3478736840UL != crc2)) {
|
104 |
|
|
CYG_TEST_FAIL("Wrong Etheret crc32 accumulate");
|
105 |
|
|
} else {
|
106 |
|
|
CYG_TEST_PASS("Ethernet crc32_accumulate");
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
if (1247800780UL != cyg_crc32((unsigned char *)license_txt,
|
111 |
|
|
sizeof(license_txt)-1)) {
|
112 |
|
|
CYG_TEST_FAIL("Wrong Gary S. Browns' crc32 calculation");
|
113 |
|
|
} else {
|
114 |
|
|
CYG_TEST_PASS("Gary S. Browns' crc32 calculation");
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
crc1 = cyg_crc32_accumulate(0,(unsigned char *)license_txt,
|
118 |
|
|
sizeof(license_txt)-1);
|
119 |
|
|
crc2 = cyg_crc32_accumulate(crc1,(unsigned char *)license_txt,
|
120 |
|
|
sizeof(license_txt)-1);
|
121 |
|
|
|
122 |
|
|
if ((1247800780UL != crc1) || (926002294UL != crc2)) {
|
123 |
|
|
CYG_TEST_FAIL("Wrong Gary S. Browns' crc32 accumulate calculation");
|
124 |
|
|
} else {
|
125 |
|
|
CYG_TEST_PASS("Gary S. Browns' crc32 accumulate calculation");
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
if (32256 != cyg_crc16((unsigned char *)license_txt,
|
129 |
|
|
sizeof(license_txt)-1)) {
|
130 |
|
|
CYG_TEST_FAIL("Wrong 16bit CRC calculation");
|
131 |
|
|
} else {
|
132 |
|
|
CYG_TEST_PASS("16bit CRC calculation");
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
if (0 != cyg_crc16_accumulate(0,0,0)) {
|
136 |
|
|
CYG_TEST_FAIL("16bit CRC accumulate setup");
|
137 |
|
|
} else {
|
138 |
|
|
crc1= cyg_crc16_accumulate(0, (unsigned char *)license_txt,
|
139 |
|
|
sizeof(license_txt)-1);
|
140 |
|
|
crc2 = cyg_crc16_accumulate(crc1, (unsigned char *)license_txt,
|
141 |
|
|
sizeof(license_txt)-1);
|
142 |
|
|
|
143 |
|
|
if ((32256 != crc1) || (48052 != crc2)) {
|
144 |
|
|
CYG_TEST_FAIL_FINISH("Wrong 16bit CRC accumulate");
|
145 |
|
|
} else {
|
146 |
|
|
CYG_TEST_PASS_FINISH("16bit CRC accumulate");
|
147 |
|
|
}
|
148 |
|
|
}
|
149 |
|
|
}
|