source: rtems/testsuites/libtests/tar01/init.c @ 1a8fe67a

5
Last change on this file since 1a8fe67a was 1a8fe67a, checked in by Alexander Krutwig <alexander.krutwig@…>, on 07/13/16 at 07:22:35

Add Untar_FromChunk_Print() + Test

  • Property mode set to 100644
File size: 4.1 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 "initial_filesystem_tar.h"
27
28const char rtems_test_name[] = "TAR 1";
29
30/* forward declarations to avoid warnings */
31rtems_task Init(rtems_task_argument argument);
32void test_untar_from_memory(void);
33void test_untar_from_file(void);
34void test_untar_chunks_from_memory(void);
35
36#define TARFILE_START initial_filesystem_tar
37#define TARFILE_SIZE  initial_filesystem_tar_size
38
39void test_cat(
40  char *file,
41  int   offset_arg,
42  int   length
43);
44
45void test_untar_from_memory(void)
46{
47  rtems_status_code sc;
48  rtems_printer     printer;
49
50  rtems_print_printer_printf(&printer);
51
52  printf("Untaring from memory - ");
53  sc = Untar_FromMemory_Print((void *)TARFILE_START, TARFILE_SIZE, &printer);
54  if (sc != RTEMS_SUCCESSFUL) {
55    printf ("error: untar failed: %s\n", rtems_status_text (sc));
56    exit(1);
57  }
58  printf ("successful\n");
59
60  /******************/
61  printf( "========= /home/test_file =========\n" );
62  test_cat( "/home/test_file", 0, 0 );
63
64  /******************/
65  printf( "========= /symlink =========\n" );
66  test_cat( "/symlink", 0, 0 );
67
68}
69
70void test_untar_from_file(void)
71{
72  int                fd;
73  int                rv;
74  ssize_t            n;
75
76  puts( "Copy tar image to test.tar" );
77  /* Copy tar image from object to file in IMFS */
78  fd = open( "/test.tar", O_CREAT|O_TRUNC|O_WRONLY, 0777 );
79  rtems_test_assert( fd != -1 );
80
81  n = write( fd, TARFILE_START, TARFILE_SIZE );
82  rtems_test_assert( n == TARFILE_SIZE );
83  close( fd );
84
85  /* make a directory to untar it into */
86  rv = mkdir( "/dest", 0777 );
87  rtems_test_assert( rv == 0 );
88
89  rv = chdir( "/dest" );
90  rtems_test_assert( rv == 0 );
91
92  /* Untar it */
93  rv = Untar_FromFile( "/test.tar" );
94  printf("Untaring from file - ");
95  if (rv != UNTAR_SUCCESSFUL) {
96    printf ("error: untar failed: %i\n", rv);
97    exit(1);
98  }
99  printf ("successful\n");
100
101  /******************/
102  printf( "========= /dest/home/test_file =========\n" );
103  test_cat( "/dest/home/test_file", 0, 0 );
104
105  /******************/
106  printf( "========= /dest/symlink =========\n" );
107  test_cat( "/dest/symlink", 0, 0 );
108}
109
110void test_untar_chunks_from_memory(void)
111{
112  rtems_status_code sc;
113  rtems_printer     printer;
114  int rv;
115  Untar_ChunkContext ctx;
116  unsigned long counter = 0;
117  char *buffer = (char *)TARFILE_START;
118  size_t buflen = TARFILE_SIZE;
119
120  rtems_print_printer_printf(&printer);
121
122  /* make a directory to untar it into */
123  rv = mkdir( "/dest2", 0777 );
124  rtems_test_assert( rv == 0 );
125
126  rv = chdir( "/dest2" );
127  rtems_test_assert( rv == 0 );
128
129  printf( "Untaring chunks from memory - " );
130  Untar_ChunkContext_Init(&ctx);
131  do {
132    sc = Untar_FromChunk_Print(&ctx, &buffer[counter], (size_t)1 , &printer);
133    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
134    counter ++;
135  } while (counter < buflen);
136  printf("successful\n");
137
138  /******************/
139  printf( "========= /dest2/home/test_file =========\n" );
140  test_cat( "/dest2/home/test_file", 0, 0 );
141
142  /******************/
143  printf( "========= /dest2/symlink =========\n" );
144  test_cat( "/dest2/symlink", 0, 0 );
145
146}
147
148rtems_task Init(
149  rtems_task_argument ignored
150)
151{
152  TEST_BEGIN();
153
154  test_untar_from_memory();
155  puts( "" );
156  test_untar_from_file();
157  puts( "" );
158  test_untar_chunks_from_memory();
159
160  TEST_END();
161  exit( 0 );
162}
163
164
165/* NOTICE: the clock driver is explicitly disabled */
166#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
167#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
168
169#define CONFIGURE_MAXIMUM_TASKS            1
170#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
171
172#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
173
174#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
175
176#define CONFIGURE_INIT
177#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.