source: rtems/testsuites/libtests/tar01/init.c @ 5c65b988

5
Last change on this file since 5c65b988 was 5c65b988, checked in by Chris Johns <chrisj@…>, on 04/09/18 at 03:39:19

testsuite/libtests: Merged nested Makefile.am files into one Makefile.am

This change is part of the testsuite Makefile.am reorganization.

Update #3382

  • Property mode set to 100644
File size: 7.8 KB
Line 
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 "tar01_tar.h"
27#include "tar01_tar_gz.h"
28#if HAVE_XZ
29#include "tar01_tar_xz.h"
30#endif
31
32const char rtems_test_name[] = "TAR 1";
33
34/* forward declarations to avoid warnings */
35rtems_task Init(rtems_task_argument argument);
36void test_untar_from_memory(void);
37void test_untar_from_file(void);
38void test_untar_chunks_from_memory(void);
39void test_untar_unzip_tgz(void);
40void test_untar_unzip_txz(void);
41
42#define TARFILE_START    tar01_tar
43#define TARFILE_SIZE     tar01_tar_size
44#define TARFILE_GZ_START tar01_tar_gz
45#define TARFILE_GZ_SIZE  tar01_tar_gz_size
46#if HAVE_XZ
47#define TARFILE_XZ_START tar01_tar_xz
48#define TARFILE_XZ_SIZE  tar01_tar_xz_size
49#endif
50
51void test_cat(
52  char *file,
53  int   offset_arg,
54  int   length
55);
56
57static void test_untar_check_mode(const char* file, int mode)
58{
59  struct stat sb;
60  int         fmode;
61  rtems_test_assert(stat(file, &sb) == 0);
62  fmode = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
63  printf(" %s: mode: %04o want: %04o\n", file, fmode, mode);
64  rtems_test_assert(fmode == mode);
65}
66
67void test_untar_from_memory(void)
68{
69  rtems_status_code sc;
70
71  printf("Untaring from memory - ");
72  sc = Untar_FromMemory_Print(
73    (void *)TARFILE_START,
74    TARFILE_SIZE,
75    &rtems_test_printer
76  );
77  if (sc != RTEMS_SUCCESSFUL) {
78    printf ("error: untar failed: %s\n", rtems_status_text (sc));
79    exit(1);
80  }
81  printf ("successful\n");
82
83  /******************/
84  printf( "========= /home/test_file =========\n" );
85  test_cat( "/home/test_file", 0, 0 );
86
87  /******************/
88  printf( "========= /home/test_script =========\n" );
89  test_cat( "/home/test_script", 0, 0 );
90  test_untar_check_mode("/home/test_script", 0755);
91
92  /******************/
93  printf( "========= /symlink =========\n" );
94  test_cat( "/symlink", 0, 0 );
95
96}
97
98void test_untar_from_file(void)
99{
100  int                fd;
101  int                rv;
102  ssize_t            n;
103
104  puts( "" );
105
106  puts( "Copy tar image to test.tar" );
107  /* Copy tar image from object to file in IMFS */
108  fd = open( "/test.tar", O_CREAT|O_TRUNC|O_WRONLY, 0777 );
109  rtems_test_assert( fd != -1 );
110
111  n = write( fd, TARFILE_START, TARFILE_SIZE );
112  rtems_test_assert( n == TARFILE_SIZE );
113  close( fd );
114
115  /* make a directory to untar it into */
116  rv = mkdir( "/dest", 0777 );
117  rtems_test_assert( rv == 0 );
118
119  rv = chdir( "/dest" );
120  rtems_test_assert( rv == 0 );
121
122  /* Untar it */
123  rv = Untar_FromFile( "/test.tar" );
124  printf("Untaring from file - ");
125  if (rv != UNTAR_SUCCESSFUL) {
126    printf ("error: untar failed: %i\n", rv);
127    exit(1);
128  }
129  printf ("successful\n");
130
131  /******************/
132  printf( "========= /dest/home/test_file =========\n" );
133  test_cat( "/dest/home/test_file", 0, 0 );
134
135  /******************/
136  printf( "========= /dest/home/test_script =========\n" );
137  test_cat( "/dest/home/test_script", 0, 0 );
138  test_untar_check_mode("/dest/home/test_script", 0755);
139
140  /******************/
141  printf( "========= /dest/symlink =========\n" );
142  test_cat( "/dest/symlink", 0, 0 );
143}
144
145void test_untar_chunks_from_memory(void)
146{
147  rtems_status_code sc;
148  int rv;
149  Untar_ChunkContext ctx;
150  unsigned long counter = 0;
151  char *buffer = (char *)TARFILE_START;
152  size_t buflen = TARFILE_SIZE;
153
154  puts( "" );
155
156  /* make a directory to untar it into */
157  rv = mkdir( "/dest2", 0777 );
158  rtems_test_assert( rv == 0 );
159
160  rv = chdir( "/dest2" );
161  rtems_test_assert( rv == 0 );
162
163  printf( "Untaring chunks from memory - " );
164  Untar_ChunkContext_Init(&ctx);
165  do {
166    sc = Untar_FromChunk_Print(
167      &ctx,
168      &buffer[counter],
169      (size_t)1 ,
170      &rtems_test_printer
171    );
172    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
173    counter ++;
174  } while (counter < buflen);
175  printf("successful\n");
176
177  /******************/
178  printf( "========= /dest2/home/test_file =========\n" );
179  test_cat( "/dest2/home/test_file", 0, 0 );
180
181  /******************/
182  printf( "========= /dest2/home/test_script =========\n" );
183  test_cat( "/dest2/home/test_script", 0, 0 );
184  test_untar_check_mode("/dest2/home/test_script", 0755);
185
186  /******************/
187  printf( "========= /dest2/symlink =========\n" );
188  test_cat( "/dest2/symlink", 0, 0 );
189
190}
191
192void test_untar_unzip_tgz(void)
193{
194  int status;
195  int rv;
196  Untar_GzChunkContext ctx;
197  size_t i = 0;
198  char *buffer = (char *)TARFILE_GZ_START;
199  size_t buflen = TARFILE_GZ_SIZE;
200  char inflate_buffer;
201
202  puts( "" );
203
204  rtems_test_assert( buflen != 0 );
205
206  /* make a directory to untar it into */
207  rv = mkdir( "/dest3", 0777 );
208  rtems_test_assert( rv == 0 );
209
210  rv = chdir( "/dest3" );
211  rtems_test_assert( rv == 0 );
212
213  printf( "Untaring chunks from tgz - " );
214
215  status = Untar_GzChunkContext_Init(&ctx, &inflate_buffer, 1);
216  rtems_test_assert(status == UNTAR_SUCCESSFUL);
217  for(i = 0; i < buflen; i++) {
218    status = Untar_FromGzChunk_Print(&ctx, &buffer[i], 1, &rtems_test_printer);
219    rtems_test_assert(status == UNTAR_SUCCESSFUL);
220  }
221  printf( "successful\n" );
222
223  /******************/
224  printf( "========= /dest3/home/test_file =========\n" );
225  test_cat( "/dest3/home/test_file", 0, 0 );
226
227  /******************/
228  printf( "========= /dest3/home/test_script =========\n" );
229  test_cat( "/dest3/home/test_script", 0, 0 );
230  test_untar_check_mode("/dest3/home/test_script", 0755);
231
232  /******************/
233  printf( "========= /dest3/symlink =========\n" );
234  test_cat( "/dest3/symlink", 0, 0 );
235}
236
237void test_untar_unzip_txz(void)
238{
239#if HAVE_XZ
240  int status;
241  int rv;
242  Untar_XzChunkContext ctx;
243  size_t i = 0;
244  char *buffer = (char *)TARFILE_XZ_START;
245  size_t buflen = TARFILE_XZ_SIZE;
246  char inflate_buffer;
247
248  puts( "" );
249
250  rtems_test_assert( buflen != 0 );
251
252  /* make a directory to untar it into */
253  rv = mkdir( "/dest4", 0777 );
254  rtems_test_assert( rv == 0 );
255
256  rv = chdir( "/dest4" );
257  rtems_test_assert( rv == 0 );
258
259  printf( "Untaring chunks from txz - " );
260
261  /*
262   * Use 8K dict, this is set on the command line of xz when compressing.
263   */
264  status = Untar_XzChunkContext_Init(&ctx, XZ_DYNALLOC,
265                                     8 * 1024, &inflate_buffer, 1);
266  rtems_test_assert(status == UNTAR_SUCCESSFUL);
267  for(i = 0; i < buflen; i++) {
268    status = Untar_FromXzChunk_Print(&ctx, &buffer[i], 1, &rtems_test_printer);
269    rtems_test_assert(status == UNTAR_SUCCESSFUL);
270  }
271  printf( "successful\n" );
272
273  /******************/
274  printf( "========= /dest4/home/test_file =========\n" );
275  test_cat( "/dest4/home/test_file", 0, 0 );
276
277  /******************/
278  printf( "========= /dest4/home/test_script =========\n" );
279  test_cat( "/dest4/home/test_script", 0, 0 );
280  test_untar_check_mode("/dest4/home/test_script", 0755);
281
282  /******************/
283  printf( "========= /dest4/symlink =========\n" );
284  test_cat( "/dest4/symlink", 0, 0 );
285#endif
286}
287
288rtems_task Init(
289  rtems_task_argument ignored
290)
291{
292  TEST_BEGIN();
293
294  test_untar_from_memory();
295  test_untar_from_file();
296  test_untar_chunks_from_memory();
297  test_untar_unzip_tgz();
298  test_untar_unzip_txz();
299
300  TEST_END();
301  exit( 0 );
302}
303
304
305/* NOTICE: the clock driver is explicitly disabled */
306#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
307#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
308
309#define CONFIGURE_MAXIMUM_TASKS            1
310#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
311
312#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
313
314#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
315
316#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
317
318#define CONFIGURE_INIT
319#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.