annotate packages/services/crc/current/tests/crc_test.c @ 395:9f81d6e38c3d

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