1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <bsp.h> /* for device driver prototypes */ |
---|
15 | #include "tmacros.h" |
---|
16 | #include <rtems/untar.h> |
---|
17 | #include <rtems/error.h> |
---|
18 | |
---|
19 | #include <stdio.h> |
---|
20 | #include <stdlib.h> |
---|
21 | #include <sys/types.h> |
---|
22 | #include <sys/stat.h> |
---|
23 | #include <fcntl.h> |
---|
24 | #include <unistd.h> |
---|
25 | |
---|
26 | #include "initial_filesystem_tar.h" |
---|
27 | #include "initial_filesystem_tar_gz.h" |
---|
28 | |
---|
29 | const char rtems_test_name[] = "TAR 1"; |
---|
30 | |
---|
31 | /* forward declarations to avoid warnings */ |
---|
32 | rtems_task Init(rtems_task_argument argument); |
---|
33 | void test_untar_from_memory(void); |
---|
34 | void test_untar_from_file(void); |
---|
35 | void test_untar_chunks_from_memory(void); |
---|
36 | void test_untar_unzip_tgz(void); |
---|
37 | |
---|
38 | #define TARFILE_START initial_filesystem_tar |
---|
39 | #define TARFILE_SIZE initial_filesystem_tar_size |
---|
40 | #define TARFILE_GZ_START initial_filesystem_tar_gz |
---|
41 | #define TARFILE_GZ_SIZE initial_filesystem_tar_gz_size |
---|
42 | |
---|
43 | void test_cat( |
---|
44 | char *file, |
---|
45 | int offset_arg, |
---|
46 | int length |
---|
47 | ); |
---|
48 | |
---|
49 | void test_untar_from_memory(void) |
---|
50 | { |
---|
51 | rtems_status_code sc; |
---|
52 | rtems_printer printer; |
---|
53 | |
---|
54 | rtems_print_printer_printf(&printer); |
---|
55 | |
---|
56 | printf("Untaring from memory - "); |
---|
57 | sc = Untar_FromMemory_Print((void *)TARFILE_START, TARFILE_SIZE, &printer); |
---|
58 | if (sc != RTEMS_SUCCESSFUL) { |
---|
59 | printf ("error: untar failed: %s\n", rtems_status_text (sc)); |
---|
60 | exit(1); |
---|
61 | } |
---|
62 | printf ("successful\n"); |
---|
63 | |
---|
64 | /******************/ |
---|
65 | printf( "========= /home/test_file =========\n" ); |
---|
66 | test_cat( "/home/test_file", 0, 0 ); |
---|
67 | |
---|
68 | /******************/ |
---|
69 | printf( "========= /symlink =========\n" ); |
---|
70 | test_cat( "/symlink", 0, 0 ); |
---|
71 | |
---|
72 | } |
---|
73 | |
---|
74 | void test_untar_from_file(void) |
---|
75 | { |
---|
76 | int fd; |
---|
77 | int rv; |
---|
78 | ssize_t n; |
---|
79 | |
---|
80 | puts( "Copy tar image to test.tar" ); |
---|
81 | /* Copy tar image from object to file in IMFS */ |
---|
82 | fd = open( "/test.tar", O_CREAT|O_TRUNC|O_WRONLY, 0777 ); |
---|
83 | rtems_test_assert( fd != -1 ); |
---|
84 | |
---|
85 | n = write( fd, TARFILE_START, TARFILE_SIZE ); |
---|
86 | rtems_test_assert( n == TARFILE_SIZE ); |
---|
87 | close( fd ); |
---|
88 | |
---|
89 | /* make a directory to untar it into */ |
---|
90 | rv = mkdir( "/dest", 0777 ); |
---|
91 | rtems_test_assert( rv == 0 ); |
---|
92 | |
---|
93 | rv = chdir( "/dest" ); |
---|
94 | rtems_test_assert( rv == 0 ); |
---|
95 | |
---|
96 | /* Untar it */ |
---|
97 | rv = Untar_FromFile( "/test.tar" ); |
---|
98 | printf("Untaring from file - "); |
---|
99 | if (rv != UNTAR_SUCCESSFUL) { |
---|
100 | printf ("error: untar failed: %i\n", rv); |
---|
101 | exit(1); |
---|
102 | } |
---|
103 | printf ("successful\n"); |
---|
104 | |
---|
105 | /******************/ |
---|
106 | printf( "========= /dest/home/test_file =========\n" ); |
---|
107 | test_cat( "/dest/home/test_file", 0, 0 ); |
---|
108 | |
---|
109 | /******************/ |
---|
110 | printf( "========= /dest/symlink =========\n" ); |
---|
111 | test_cat( "/dest/symlink", 0, 0 ); |
---|
112 | } |
---|
113 | |
---|
114 | void test_untar_chunks_from_memory(void) |
---|
115 | { |
---|
116 | rtems_status_code sc; |
---|
117 | rtems_printer printer; |
---|
118 | int rv; |
---|
119 | Untar_ChunkContext ctx; |
---|
120 | unsigned long counter = 0; |
---|
121 | char *buffer = (char *)TARFILE_START; |
---|
122 | size_t buflen = TARFILE_SIZE; |
---|
123 | |
---|
124 | rtems_print_printer_printf(&printer); |
---|
125 | |
---|
126 | /* make a directory to untar it into */ |
---|
127 | rv = mkdir( "/dest2", 0777 ); |
---|
128 | rtems_test_assert( rv == 0 ); |
---|
129 | |
---|
130 | rv = chdir( "/dest2" ); |
---|
131 | rtems_test_assert( rv == 0 ); |
---|
132 | |
---|
133 | printf( "Untaring chunks from memory - " ); |
---|
134 | Untar_ChunkContext_Init(&ctx); |
---|
135 | do { |
---|
136 | sc = Untar_FromChunk_Print(&ctx, &buffer[counter], (size_t)1 , &printer); |
---|
137 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
138 | counter ++; |
---|
139 | } while (counter < buflen); |
---|
140 | printf("successful\n"); |
---|
141 | |
---|
142 | /******************/ |
---|
143 | printf( "========= /dest2/home/test_file =========\n" ); |
---|
144 | test_cat( "/dest2/home/test_file", 0, 0 ); |
---|
145 | |
---|
146 | /******************/ |
---|
147 | printf( "========= /dest2/symlink =========\n" ); |
---|
148 | test_cat( "/dest2/symlink", 0, 0 ); |
---|
149 | |
---|
150 | } |
---|
151 | |
---|
152 | void test_untar_unzip_tgz(void) |
---|
153 | { |
---|
154 | int status; |
---|
155 | rtems_printer printer; |
---|
156 | int rv; |
---|
157 | Untar_GzChunkContext ctx; |
---|
158 | size_t i = 0; |
---|
159 | char *buffer = (char *)TARFILE_GZ_START; |
---|
160 | size_t buflen = TARFILE_GZ_SIZE; |
---|
161 | char inflate_buffer; |
---|
162 | |
---|
163 | rtems_print_printer_printf(&printer); |
---|
164 | |
---|
165 | /* make a directory to untar it into */ |
---|
166 | rv = mkdir( "/dest3", 0777 ); |
---|
167 | rtems_test_assert( rv == 0 ); |
---|
168 | |
---|
169 | rv = chdir( "/dest3" ); |
---|
170 | rtems_test_assert( rv == 0 ); |
---|
171 | |
---|
172 | printf( "Untaring chunks from tgz - " ); |
---|
173 | |
---|
174 | status = Untar_GzChunkContext_Init(&ctx, &inflate_buffer, 1); |
---|
175 | rtems_test_assert(status == UNTAR_SUCCESSFUL); |
---|
176 | for(i = 0; i < buflen; i++) { |
---|
177 | status = Untar_FromGzChunk_Print(&ctx, &buffer[i], 1, &printer); |
---|
178 | rtems_test_assert(status == UNTAR_SUCCESSFUL); |
---|
179 | } |
---|
180 | printf( "successful\n" ); |
---|
181 | |
---|
182 | /******************/ |
---|
183 | printf( "========= /dest3/home/test_file =========\n" ); |
---|
184 | test_cat( "/dest3/home/test_file", 0, 0 ); |
---|
185 | |
---|
186 | /******************/ |
---|
187 | printf( "========= /dest3/symlink =========\n" ); |
---|
188 | test_cat( "/dest3/symlink", 0, 0 ); |
---|
189 | } |
---|
190 | |
---|
191 | rtems_task Init( |
---|
192 | rtems_task_argument ignored |
---|
193 | ) |
---|
194 | { |
---|
195 | TEST_BEGIN(); |
---|
196 | |
---|
197 | test_untar_from_memory(); |
---|
198 | puts( "" ); |
---|
199 | test_untar_from_file(); |
---|
200 | puts( "" ); |
---|
201 | test_untar_chunks_from_memory(); |
---|
202 | puts( "" ); |
---|
203 | test_untar_unzip_tgz(); |
---|
204 | |
---|
205 | TEST_END(); |
---|
206 | exit( 0 ); |
---|
207 | } |
---|
208 | |
---|
209 | |
---|
210 | /* NOTICE: the clock driver is explicitly disabled */ |
---|
211 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
212 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
213 | |
---|
214 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
215 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5 |
---|
216 | |
---|
217 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
218 | |
---|
219 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
220 | |
---|
221 | #define CONFIGURE_INIT |
---|
222 | #include <rtems/confdefs.h> |
---|