[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/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> |
---|
[a45dfa14] | 25 | #include <string.h> |
---|
[270434cc] | 26 | |
---|
[5c2e7104] | 27 | #include "tar02-tar.h" |
---|
[270434cc] | 28 | |
---|
[f8b2eb03] | 29 | const char rtems_test_name[] = "TAR 2"; |
---|
| 30 | |
---|
[4c86e3d] | 31 | /* forward declarations to avoid warnings */ |
---|
| 32 | rtems_task Init(rtems_task_argument argument); |
---|
| 33 | void test_tarfs_load(void); |
---|
| 34 | |
---|
[5c65b988] | 35 | #define TARFILE_START tar02_tar |
---|
| 36 | #define TARFILE_SIZE tar02_tar_size |
---|
[270434cc] | 37 | |
---|
[a45dfa14] | 38 | static const char file[] = "/home/test_file"; |
---|
| 39 | |
---|
| 40 | static const char content_0[] = |
---|
| 41 | "This is a test of loading an RTEMS filesystem from an\n" |
---|
| 42 | "initial tar image.\n"; |
---|
| 43 | |
---|
| 44 | static 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 | |
---|
| 49 | static char buf[sizeof(content_1) - 1]; |
---|
| 50 | |
---|
| 51 | static 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 | |
---|
| 74 | static 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 */ |
---|
[270434cc] | 95 | void test_cat( |
---|
[a45dfa14] | 96 | const char *file, |
---|
| 97 | int offset_arg, |
---|
| 98 | int length |
---|
[270434cc] | 99 | ); |
---|
| 100 | |
---|
| 101 | void 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" ); |
---|
[a45dfa14] | 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 | |
---|
[270434cc] | 120 | /******************/ |
---|
| 121 | printf( "========= /symlink =========\n" ); |
---|
| 122 | test_cat( "/symlink", 0, 0 ); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | rtems_task Init( |
---|
| 126 | rtems_task_argument ignored |
---|
| 127 | ) |
---|
| 128 | { |
---|
[f8b2eb03] | 129 | TEST_BEGIN(); |
---|
[270434cc] | 130 | |
---|
| 131 | test_tarfs_load(); |
---|
| 132 | |
---|
[f8b2eb03] | 133 | TEST_END(); |
---|
[270434cc] | 134 | exit( 0 ); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | /* NOTICE: the clock driver is explicitly disabled */ |
---|
| 139 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
[c4b8b147] | 140 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
[270434cc] | 141 | |
---|
| 142 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
[3cec2df] | 143 | #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 5 |
---|
[270434cc] | 144 | |
---|
[f8b2eb03] | 145 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
| 146 | |
---|
[270434cc] | 147 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 148 | |
---|
| 149 | #define CONFIGURE_INIT |
---|
| 150 | #include <rtems/confdefs.h> |
---|