source: rtems/testsuites/libtests/tar02/init.c @ 5c2e7104

5
Last change on this file since 5c2e7104 was 5c2e7104, checked in by Sebastian Huber <sebastian.huber@…>, on 11/25/19 at 12:01:05

libtests: Use '-' for TAR file names

Use uniform pattern for all TAR file names. Use the dl* tests as a
template.

Update #3818.

  • Property mode set to 100644
File size: 3.2 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/imfs.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#include <string.h>
26
27#include "tar02-tar.h"
28
29const char rtems_test_name[] = "TAR 2";
30
31/* forward declarations to avoid warnings */
32rtems_task Init(rtems_task_argument argument);
33void test_tarfs_load(void);
34
35#define TARFILE_START tar02_tar
36#define TARFILE_SIZE  tar02_tar_size
37
38static const char file[] = "/home/test_file";
39
40static const char content_0[] =
41  "This is a test of loading an RTEMS filesystem from an\n"
42  "initial tar image.\n";
43
44static const char content_1[] =
45  "This is a test of loading an RTEMS filesystem from an\n"
46  "initial tar image.\n"
47  "And some other stuff.\n";
48
49static char buf[sizeof(content_1) - 1];
50
51static void check_file(
52  const char *file,
53  const char *expected_content,
54  char *buf,
55  size_t size
56)
57{
58  int fd;
59  ssize_t n;
60  int rv;
61
62  fd = open(file, O_RDONLY);
63  rtems_test_assert(fd >= 0);
64
65  n = read(fd, buf, size);
66  rtems_test_assert(n == (ssize_t) size);
67
68  rtems_test_assert(memcmp(expected_content, buf, size) == 0);
69
70  rv = close(fd);
71  rtems_test_assert(rv == 0);
72}
73
74static void write_file(
75  const char *file,
76  const char *content,
77  size_t size
78)
79{
80  int fd;
81  ssize_t n;
82  int rv;
83
84  fd = open(file, O_WRONLY);
85  rtems_test_assert(fd >= 0);
86
87  n = write(fd, content, size);
88  rtems_test_assert(n == (ssize_t) size);
89
90  rv = close(fd);
91  rtems_test_assert(rv == 0);
92}
93
94/* FIXME */
95void test_cat(
96  const char *file,
97  int         offset_arg,
98  int         length
99);
100
101void test_tarfs_load(void)
102{
103  rtems_status_code sc;
104
105  printf("Loading tarfs image ... ");
106  sc = rtems_tarfs_load("/",(void *)TARFILE_START, TARFILE_SIZE);
107  if (sc != RTEMS_SUCCESSFUL) {
108    printf ("error: untar failed: %s\n", rtems_status_text (sc));
109    exit(1);
110  }
111  printf ("successful\n");
112
113  /******************/
114  printf( "========= /home/test_file =========\n" );
115  test_cat(&file[0], 0, 0);
116  check_file(&file[0], &content_0[0], &buf[0], sizeof(content_0) - 1);
117  write_file(&file[0], &content_1[0], sizeof(content_1) - 1);
118  check_file(&file[0], &content_1[0], &buf[0], sizeof(content_1) - 1);
119
120  /******************/
121  printf( "========= /symlink =========\n" );
122  test_cat( "/symlink", 0, 0 );
123}
124
125rtems_task Init(
126  rtems_task_argument ignored
127)
128{
129  TEST_BEGIN();
130
131  test_tarfs_load();
132
133  TEST_END();
134  exit( 0 );
135}
136
137
138/* NOTICE: the clock driver is explicitly disabled */
139#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
140#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
141
142#define CONFIGURE_MAXIMUM_TASKS            1
143#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
144
145#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
146
147#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
148
149#define CONFIGURE_INIT
150#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.