xref: /nrf52832-nimble/rt-thread/components/dfs/filesystems/jffs2/cyg/compress/tests/zlib1.c (revision 104654410c56c573564690304ae786df310c91fc)
1*10465441SEvalZero //=================================================================
2*10465441SEvalZero //
3*10465441SEvalZero //        zlib1.c
4*10465441SEvalZero //
5*10465441SEvalZero //        zlib compression/decompression test 1
6*10465441SEvalZero //
7*10465441SEvalZero //==========================================================================
8*10465441SEvalZero // ####ECOSGPLCOPYRIGHTBEGIN####
9*10465441SEvalZero // -------------------------------------------
10*10465441SEvalZero // This file is part of eCos, the Embedded Configurable Operating System.
11*10465441SEvalZero // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12*10465441SEvalZero //
13*10465441SEvalZero // eCos is free software; you can redistribute it and/or modify it under
14*10465441SEvalZero // the terms of the GNU General Public License as published by the Free
15*10465441SEvalZero // Software Foundation; either version 2 or (at your option) any later
16*10465441SEvalZero // version.
17*10465441SEvalZero //
18*10465441SEvalZero // eCos is distributed in the hope that it will be useful, but WITHOUT
19*10465441SEvalZero // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20*10465441SEvalZero // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21*10465441SEvalZero // for more details.
22*10465441SEvalZero //
23*10465441SEvalZero // You should have received a copy of the GNU General Public License
24*10465441SEvalZero // along with eCos; if not, write to the Free Software Foundation, Inc.,
25*10465441SEvalZero // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26*10465441SEvalZero //
27*10465441SEvalZero // As a special exception, if other files instantiate templates or use
28*10465441SEvalZero // macros or inline functions from this file, or you compile this file
29*10465441SEvalZero // and link it with other works to produce a work based on this file,
30*10465441SEvalZero // this file does not by itself cause the resulting work to be covered by
31*10465441SEvalZero // the GNU General Public License. However the source code for this file
32*10465441SEvalZero // must still be made available in accordance with section (3) of the GNU
33*10465441SEvalZero // General Public License v2.
34*10465441SEvalZero //
35*10465441SEvalZero // This exception does not invalidate any other reasons why a work based
36*10465441SEvalZero // on this file might be covered by the GNU General Public License.
37*10465441SEvalZero // -------------------------------------------
38*10465441SEvalZero // ####ECOSGPLCOPYRIGHTEND####
39*10465441SEvalZero //==========================================================================
40*10465441SEvalZero //#####DESCRIPTIONBEGIN####
41*10465441SEvalZero //
42*10465441SEvalZero // Author(s):     jskov
43*10465441SEvalZero // Contributors:  jskov
44*10465441SEvalZero // Date:          2001-03-09
45*10465441SEvalZero // Description:   Tests zlib compress/decompress functionality.
46*10465441SEvalZero //####DESCRIPTIONEND####
47*10465441SEvalZero 
48*10465441SEvalZero 
49*10465441SEvalZero #include <cyg/hal/hal_arch.h>           // CYGNUM_HAL_STACK_SIZE_TYPICAL
50*10465441SEvalZero 
51*10465441SEvalZero #include <cyg/kernel/kapi.h>
52*10465441SEvalZero 
53*10465441SEvalZero #include <cyg/infra/testcase.h>
54*10465441SEvalZero #include <cyg/infra/diag.h>
55*10465441SEvalZero 
56*10465441SEvalZero #ifdef CYGFUN_KERNEL_API_C
57*10465441SEvalZero 
58*10465441SEvalZero #include <cyg/compress/zlib.h>
59*10465441SEvalZero #include <stdlib.h>
60*10465441SEvalZero 
61*10465441SEvalZero #define NTHREADS 1
62*10465441SEvalZero #define STACKSIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL > 8192 ? CYGNUM_HAL_STACK_SIZE_TYPICAL : 8192)
63*10465441SEvalZero 
64*10465441SEvalZero static cyg_handle_t thread[NTHREADS];
65*10465441SEvalZero 
66*10465441SEvalZero static cyg_thread thread_obj[NTHREADS];
67*10465441SEvalZero static char stack[NTHREADS][STACKSIZE];
68*10465441SEvalZero 
69*10465441SEvalZero static char license_txt[] =
70*10465441SEvalZero "Red Hat eCos Public License v1.1\n"
71*10465441SEvalZero "\n"
72*10465441SEvalZero "\n"
73*10465441SEvalZero "1. DEFINITIONS\n"
74*10465441SEvalZero "\n"
75*10465441SEvalZero "1.1. \"Contributor\" means each entity that creates or\n"
76*10465441SEvalZero "contributes to the creation of Modifications.\n"
77*10465441SEvalZero "\n"
78*10465441SEvalZero "1.2. \"Contributor Version\" means the combination of the\n"
79*10465441SEvalZero "Original Code, prior Modifications used by a\n"
80*10465441SEvalZero "Contributor, and the Modifications made by that\n"
81*10465441SEvalZero "particular Contributor.\n"
82*10465441SEvalZero "\n"
83*10465441SEvalZero "1.3. \"Covered Code\" means the Original Code or\n"
84*10465441SEvalZero "Modifications or the combination of the Original Code\n"
85*10465441SEvalZero "and Modifications, in each case including portions\n"
86*10465441SEvalZero "thereof.\n"
87*10465441SEvalZero "\n"
88*10465441SEvalZero "1.4. \"Electronic Distribution Mechanism\" means a\n"
89*10465441SEvalZero "mechanism generally accepted in the software development\n"
90*10465441SEvalZero "community for the electronic transfer of data.\n"
91*10465441SEvalZero "\n"
92*10465441SEvalZero "1.5. \"Executable\" means Covered Code in any form other\n"
93*10465441SEvalZero "than Source Code.\n"
94*10465441SEvalZero "1.6. \"Initial Developer\" means the individual or entity\n"
95*10465441SEvalZero "identified as the Initial Developer in the Source Code\n"
96*10465441SEvalZero "notice required by Exhibit A.\n"
97*10465441SEvalZero "\n"
98*10465441SEvalZero "1.7. \"Larger Work\" means a work which combines Covered\n"
99*10465441SEvalZero "Code or portions thereof with code not governed by the\n"
100*10465441SEvalZero "terms of this License.\n"
101*10465441SEvalZero "\n"
102*10465441SEvalZero "1.8. \"License\" means this document.\n"
103*10465441SEvalZero "\n"
104*10465441SEvalZero "1.9. \"Modifications\" means any addition to or deletion\n"
105*10465441SEvalZero "from the substance or structure of either the Original\n"
106*10465441SEvalZero "Code or any previous Modifications. When Covered Code is\n"
107*10465441SEvalZero "released as a series of files, a Modification is:\n"
108*10465441SEvalZero "\n"
109*10465441SEvalZero "     A. Any addition to or deletion from the\n"
110*10465441SEvalZero "     contents of a file containing Original Code or\n"
111*10465441SEvalZero "     previous Modifications.\n"
112*10465441SEvalZero "\n"
113*10465441SEvalZero "     B. Any new file that contains any part of the\n"
114*10465441SEvalZero "     Original Code or previous Modifications.\n"
115*10465441SEvalZero "\n"
116*10465441SEvalZero "1.10. \"Original Code\" means Source Code of computer\n"
117*10465441SEvalZero "software code which is described in the Source Code\n"
118*10465441SEvalZero "notice required by Exhibit A as Original Code, and\n"
119*10465441SEvalZero "which, at the time of its release under this License is\n"
120*10465441SEvalZero "not already Covered Code governed by this License.\n"
121*10465441SEvalZero "\n"
122*10465441SEvalZero "1.11. \"Source Code\" means the preferred form of the\n"
123*10465441SEvalZero "Covered Code for making modifications to it, including\n"
124*10465441SEvalZero "all modules it contains, plus any associated interface\n"
125*10465441SEvalZero "definition files, scripts used to control compilation\n"
126*10465441SEvalZero "and installation of an Executable, or a list of source\n"
127*10465441SEvalZero "code differential comparisons against either the\n"
128*10465441SEvalZero "Original Code or another well known, available Covered\n"
129*10465441SEvalZero "Code of the Contributor's choice. The Source Code can be\n"
130*10465441SEvalZero "in a compressed or archival form, provided the\n"
131*10465441SEvalZero "appropriate decompression or de-archiving software is\n"
132*10465441SEvalZero "widely available for no charge.\n"
133*10465441SEvalZero "\n"
134*10465441SEvalZero "1.12. \"You\" means an individual or a legal entity\n"
135*10465441SEvalZero "exercising rights under, and complying with all of the\n"
136*10465441SEvalZero "terms of, this License or a future version of this\n"
137*10465441SEvalZero "License issued under Section 6.1. For legal entities,\n"
138*10465441SEvalZero "\"You\" includes any entity which controls, is controlled\n"
139*10465441SEvalZero "by, or is under common control with You. For purposes of\n"
140*10465441SEvalZero "this definition, \"control\" means (a) the power, direct\n"
141*10465441SEvalZero "or indirect, to cause the direction or management of\n"
142*10465441SEvalZero "such entity, whether by contract or otherwise, or (b)\n"
143*10465441SEvalZero "ownership of fifty percent (50%) or more of the\n"
144*10465441SEvalZero "outstanding shares or beneficial ownership of such\n"
145*10465441SEvalZero "entity.\n"
146*10465441SEvalZero "\n"
147*10465441SEvalZero "1.13. \"Red Hat Branded Code\" is code that Red Hat\n"
148*10465441SEvalZero "distributes and/or permits others to distribute under\n"
149*10465441SEvalZero "different terms than the Red Hat eCos Public License.\n"
150*10465441SEvalZero "Red Hat's Branded Code may contain part or all of the\n"
151*10465441SEvalZero "Covered Code.\n";
152*10465441SEvalZero 
entry0(cyg_addrword_t data)153*10465441SEvalZero static void entry0( cyg_addrword_t data )
154*10465441SEvalZero {
155*10465441SEvalZero     int i;
156*10465441SEvalZero     unsigned long len;
157*10465441SEvalZero     int err;
158*10465441SEvalZero     int buf_size = sizeof(license_txt)+512;
159*10465441SEvalZero     unsigned char* packed = malloc(buf_size);
160*10465441SEvalZero     unsigned char* unpacked = malloc(buf_size);
161*10465441SEvalZero 
162*10465441SEvalZero     if (NULL == packed || NULL == unpacked)
163*10465441SEvalZero         CYG_TEST_NA("Not enough memory for buffers");
164*10465441SEvalZero 
165*10465441SEvalZero     CYG_TEST_INFO("Compressing");
166*10465441SEvalZero 
167*10465441SEvalZero     len = buf_size;
168*10465441SEvalZero     err = compress(packed, &len, license_txt, sizeof(license_txt));
169*10465441SEvalZero     diag_printf("len = %d", len);
170*10465441SEvalZero     diag_dump_buf(packed, len);
171*10465441SEvalZero 
172*10465441SEvalZero     if (Z_OK != err)
173*10465441SEvalZero         CYG_TEST_NA("Not enough memory for compression");
174*10465441SEvalZero 
175*10465441SEvalZero 
176*10465441SEvalZero     CYG_TEST_INFO("Decompressing");
177*10465441SEvalZero     err = uncompress(unpacked, &buf_size, packed, len);
178*10465441SEvalZero 
179*10465441SEvalZero     switch (err) {
180*10465441SEvalZero     case Z_OK:
181*10465441SEvalZero         break;
182*10465441SEvalZero     case Z_MEM_ERROR:
183*10465441SEvalZero         CYG_TEST_NA("Not enough memory for decompression");
184*10465441SEvalZero         break;
185*10465441SEvalZero     case Z_BUF_ERROR:
186*10465441SEvalZero         CYG_TEST_FAIL_FINISH("Decompressed data larger than original");
187*10465441SEvalZero         break;
188*10465441SEvalZero     case Z_DATA_ERROR:
189*10465441SEvalZero         CYG_TEST_FAIL_FINISH("Decompression failed");
190*10465441SEvalZero         break;
191*10465441SEvalZero     default:
192*10465441SEvalZero         CYG_TEST_FAIL_FINISH("Unknown decompression error");
193*10465441SEvalZero         break;
194*10465441SEvalZero     }
195*10465441SEvalZero 
196*10465441SEvalZero     for (i = 0; i < sizeof(license_txt)-1; i++) {
197*10465441SEvalZero         if (license_txt[i] != unpacked[i])
198*10465441SEvalZero             CYG_TEST_FAIL_FINISH("Verify failed");
199*10465441SEvalZero     }
200*10465441SEvalZero 
201*10465441SEvalZero     CYG_TEST_PASS_FINISH("zlib1 OK");
202*10465441SEvalZero }
203*10465441SEvalZero 
zlib1_main(void)204*10465441SEvalZero void zlib1_main( void )
205*10465441SEvalZero {
206*10465441SEvalZero     CYG_TEST_INIT();
207*10465441SEvalZero 
208*10465441SEvalZero     cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "zlib1",
209*10465441SEvalZero         (void *)stack[0], STACKSIZE,&thread[0], &thread_obj[0]);
210*10465441SEvalZero     cyg_thread_resume(thread[0]);
211*10465441SEvalZero 
212*10465441SEvalZero     cyg_scheduler_start();
213*10465441SEvalZero 
214*10465441SEvalZero     CYG_TEST_FAIL_FINISH("Not reached");
215*10465441SEvalZero }
216*10465441SEvalZero 
217*10465441SEvalZero externC void
cyg_start(void)218*10465441SEvalZero cyg_start( void )
219*10465441SEvalZero {
220*10465441SEvalZero     zlib1_main();
221*10465441SEvalZero }
222*10465441SEvalZero 
223*10465441SEvalZero #else /* def CYGFUN_KERNEL_API_C */
224*10465441SEvalZero externC void
cyg_start(void)225*10465441SEvalZero cyg_start( void )
226*10465441SEvalZero {
227*10465441SEvalZero     CYG_TEST_INIT();
228*10465441SEvalZero     CYG_TEST_NA("Kernel C API layer disabled");
229*10465441SEvalZero }
230*10465441SEvalZero #endif /* def CYGFUN_KERNEL_API_C */
231*10465441SEvalZero 
232*10465441SEvalZero // EOF zlib1.c
233