Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:34

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include <bsp.h> /* for device driver prototypes */
0034 #include "tmacros.h"
0035 #include <rtems/imfs.h>
0036 #include <rtems/error.h>
0037 
0038 #include <stdio.h>
0039 #include <stdlib.h>
0040 #include <sys/types.h>
0041 #include <sys/stat.h>
0042 #include <fcntl.h>
0043 #include <unistd.h>
0044 #include <string.h>
0045 
0046 #include "tar02-tar.h"
0047 
0048 const char rtems_test_name[] = "TAR 2";
0049 
0050 /* forward declarations to avoid warnings */
0051 rtems_task Init(rtems_task_argument argument);
0052 void test_tarfs_load(void);
0053 
0054 #define TARFILE_START tar01_tar
0055 #define TARFILE_SIZE  tar01_tar_size
0056 
0057 static const char file[] = "/home/test_file";
0058 
0059 static const char content_0[] =
0060   "This is a test of loading an RTEMS filesystem from an\n"
0061   "initial tar image.\n";
0062 
0063 static const char content_1[] =
0064   "This is a test of loading an RTEMS filesystem from an\n"
0065   "initial tar image.\n"
0066   "And some other stuff.\n";
0067 
0068 static char buf[sizeof(content_1) - 1];
0069 
0070 static void check_file(
0071   const char *file,
0072   const char *expected_content,
0073   char *buf,
0074   size_t size
0075 )
0076 {
0077   int fd;
0078   ssize_t n;
0079   int rv;
0080 
0081   fd = open(file, O_RDONLY);
0082   rtems_test_assert(fd >= 0);
0083 
0084   n = read(fd, buf, size);
0085   rtems_test_assert(n == (ssize_t) size);
0086 
0087   rtems_test_assert(memcmp(expected_content, buf, size) == 0);
0088 
0089   rv = close(fd);
0090   rtems_test_assert(rv == 0);
0091 }
0092 
0093 static void write_file(
0094   const char *file,
0095   const char *content,
0096   size_t size
0097 )
0098 {
0099   int fd;
0100   ssize_t n;
0101   int rv;
0102 
0103   fd = open(file, O_WRONLY);
0104   rtems_test_assert(fd >= 0);
0105 
0106   n = write(fd, content, size);
0107   rtems_test_assert(n == (ssize_t) size);
0108 
0109   rv = close(fd);
0110   rtems_test_assert(rv == 0);
0111 }
0112 
0113 /* FIXME */
0114 void test_cat(
0115   const char *file,
0116   int         offset_arg,
0117   int         length
0118 );
0119 
0120 void test_tarfs_load(void)
0121 {
0122   rtems_status_code sc;
0123 
0124   printf("Loading tarfs image ... ");
0125   sc = rtems_tarfs_load("/",(void *)TARFILE_START, TARFILE_SIZE);
0126   if (sc != RTEMS_SUCCESSFUL) {
0127     printf ("error: untar failed: %s\n", rtems_status_text (sc));
0128     exit(1);
0129   }
0130   printf ("successful\n");
0131 
0132   /******************/
0133   printf( "========= /home/test_file =========\n" );
0134   test_cat(&file[0], 0, 0);
0135   check_file(&file[0], &content_0[0], &buf[0], sizeof(content_0) - 1);
0136   write_file(&file[0], &content_1[0], sizeof(content_1) - 1);
0137   check_file(&file[0], &content_1[0], &buf[0], sizeof(content_1) - 1);
0138 
0139   /******************/
0140   printf( "========= /symlink =========\n" );
0141   test_cat( "/symlink", 0, 0 );
0142 }
0143 
0144 rtems_task Init(
0145   rtems_task_argument ignored
0146 )
0147 {
0148   TEST_BEGIN();
0149 
0150   test_tarfs_load();
0151 
0152   TEST_END();
0153   exit( 0 );
0154 }
0155 
0156 
0157 /* NOTICE: the clock driver is explicitly disabled */
0158 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0159 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0160 
0161 #define CONFIGURE_MAXIMUM_TASKS            1
0162 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 5
0163 
0164 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0165 
0166 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0167 
0168 #define CONFIGURE_INIT
0169 #include <rtems/confdefs.h>