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