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