[270434cc] | 1 | /* |
---|
[4c86e3d] | 2 | * COPYRIGHT (c) 1989-2012. |
---|
[270434cc] | 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 |
---|
[c499856] | 7 | * http://www.rtems.org/license/LICENSE. |
---|
[270434cc] | 8 | */ |
---|
| 9 | |
---|
[7d3f9c6] | 10 | #ifdef HAVE_CONFIG_H |
---|
| 11 | #include "config.h" |
---|
| 12 | #endif |
---|
| 13 | |
---|
[270434cc] | 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 | |
---|
[f8b2eb03] | 28 | const char rtems_test_name[] = "TAR 1"; |
---|
| 29 | |
---|
[4c86e3d] | 30 | /* forward declarations to avoid warnings */ |
---|
| 31 | rtems_task Init(rtems_task_argument argument); |
---|
| 32 | void test_untar_from_memory(void); |
---|
| 33 | void test_untar_from_file(void); |
---|
[1a8fe67a] | 34 | void test_untar_chunks_from_memory(void); |
---|
[4c86e3d] | 35 | |
---|
[270434cc] | 36 | #define TARFILE_START initial_filesystem_tar |
---|
| 37 | #define TARFILE_SIZE initial_filesystem_tar_size |
---|
| 38 | |
---|
| 39 | void test_cat( |
---|
| 40 | char *file, |
---|
| 41 | int offset_arg, |
---|
| 42 | int length |
---|
| 43 | ); |
---|
| 44 | |
---|
| 45 | void test_untar_from_memory(void) |
---|
| 46 | { |
---|
| 47 | rtems_status_code sc; |
---|
[d84e346b] | 48 | rtems_printer printer; |
---|
| 49 | |
---|
| 50 | rtems_print_printer_printf(&printer); |
---|
[270434cc] | 51 | |
---|
| 52 | printf("Untaring from memory - "); |
---|
[d84e346b] | 53 | sc = Untar_FromMemory_Print((void *)TARFILE_START, TARFILE_SIZE, &printer); |
---|
[270434cc] | 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 ); |
---|
[d84e346b] | 63 | |
---|
[270434cc] | 64 | /******************/ |
---|
| 65 | printf( "========= /symlink =========\n" ); |
---|
| 66 | test_cat( "/symlink", 0, 0 ); |
---|
| 67 | |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | void test_untar_from_file(void) |
---|
| 71 | { |
---|
| 72 | int fd; |
---|
[5bd6123] | 73 | int rv; |
---|
| 74 | ssize_t n; |
---|
[270434cc] | 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 | |
---|
[5bd6123] | 81 | n = write( fd, TARFILE_START, TARFILE_SIZE ); |
---|
| 82 | rtems_test_assert( n == TARFILE_SIZE ); |
---|
[270434cc] | 83 | close( fd ); |
---|
| 84 | |
---|
| 85 | /* make a directory to untar it into */ |
---|
[5bd6123] | 86 | rv = mkdir( "/dest", 0777 ); |
---|
| 87 | rtems_test_assert( rv == 0 ); |
---|
[270434cc] | 88 | |
---|
[5bd6123] | 89 | rv = chdir( "/dest" ); |
---|
| 90 | rtems_test_assert( rv == 0 ); |
---|
[270434cc] | 91 | |
---|
| 92 | /* Untar it */ |
---|
[5bd6123] | 93 | rv = Untar_FromFile( "/test.tar" ); |
---|
[270434cc] | 94 | printf("Untaring from file - "); |
---|
[5bd6123] | 95 | if (rv != UNTAR_SUCCESSFUL) { |
---|
| 96 | printf ("error: untar failed: %i\n", rv); |
---|
[270434cc] | 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 ); |
---|
[d84e346b] | 104 | |
---|
[270434cc] | 105 | /******************/ |
---|
| 106 | printf( "========= /dest/symlink =========\n" ); |
---|
| 107 | test_cat( "/dest/symlink", 0, 0 ); |
---|
| 108 | } |
---|
| 109 | |
---|
[1a8fe67a] | 110 | void 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 | |
---|
[270434cc] | 148 | rtems_task Init( |
---|
| 149 | rtems_task_argument ignored |
---|
| 150 | ) |
---|
| 151 | { |
---|
[f8b2eb03] | 152 | TEST_BEGIN(); |
---|
[270434cc] | 153 | |
---|
| 154 | test_untar_from_memory(); |
---|
| 155 | puts( "" ); |
---|
| 156 | test_untar_from_file(); |
---|
[1a8fe67a] | 157 | puts( "" ); |
---|
| 158 | test_untar_chunks_from_memory(); |
---|
[270434cc] | 159 | |
---|
[f8b2eb03] | 160 | TEST_END(); |
---|
[270434cc] | 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 | |
---|
[f8b2eb03] | 172 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
| 173 | |
---|
[270434cc] | 174 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 175 | |
---|
| 176 | #define CONFIGURE_INIT |
---|
| 177 | #include <rtems/confdefs.h> |
---|