File indexing completed on 2025-05-11 08:24:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032
0033 #include <sys/stat.h>
0034 #include <fcntl.h>
0035 #include <errno.h>
0036 #include <stdio.h>
0037 #include <stdint.h>
0038 #include <stdlib.h>
0039 #include <string.h>
0040 #include <unistd.h>
0041
0042 #include "fstest.h"
0043 #include "fs_config.h"
0044 #include <tmacros.h>
0045
0046 #define BUF_SIZE 100
0047
0048 const char rtems_test_name[] = "FSPATHEVAL " FILESYSTEM;
0049 const RTEMS_TEST_STATE rtems_test_state = TEST_STATE;
0050
0051 static void make_multiple_files (char **files,int is_directory)
0052 {
0053 int i;
0054 int status;
0055 int fd;
0056
0057 i = 0;
0058 if (is_directory) {
0059 while (files[i]) {
0060 printf ("Making directory %s\n", files[i]);
0061 status = mkdir (files[i], S_IRWXU);
0062 rtems_test_assert (!status);
0063 i++;
0064 }
0065 } else {
0066 while (files[i]) {
0067 printf ("Create file %s\n", files[i]);
0068 fd=creat(files[i],S_IRWXU);
0069 status=close(fd);
0070 rtems_test_assert (!status);
0071 i++;
0072 }
0073 }
0074
0075 puts ("");
0076 }
0077
0078 static void remove_multiple_files (char **files,int is_directory)
0079 {
0080 int i;
0081 int status;
0082
0083 i = 0;
0084 while (files[i]) {
0085 i++;
0086 }
0087
0088 if (is_directory) {
0089 while (i) {
0090 i--;
0091 printf ("Removing directory %s\n", files[i]);
0092 status = rmdir (files[i]);
0093 rtems_test_assert (!status);
0094 }
0095 } else {
0096 while (i) {
0097 i--;
0098 printf ("Removing file %s\n", files[i]);
0099 status = unlink (files[i]);
0100 rtems_test_assert (!status);
0101 }
0102 }
0103
0104 puts ("");
0105 }
0106
0107 static void path_eval_test01 (void)
0108 {
0109 char *valid_path[] = {
0110 "/test1/",
0111 "tets2",
0112 "///test3",
0113 "test4////",
0114 "../../test5",
0115 "/test1/../test6",
0116 "./test7/",
0117 ".././test8",
0118 "test8/./../test9",
0119 "///test9/../test10",
0120 0
0121 };
0122 char *valid_file[]={
0123 "/test1",
0124 "tets2",
0125 "///test3",
0126 "test4",
0127 "../../test5",
0128 "/../test6",
0129 "./test7",
0130 ".././test8",
0131 "/./../test9",
0132 "//../test10",
0133 0
0134 };
0135
0136 char *valid_relative_path[]={
0137 "test1",
0138 "tets2",
0139 "test3",
0140 "test4",
0141 "test5",
0142 "test6",
0143 "test7",
0144 "test8",
0145 "test9",
0146 "test10",
0147 0
0148
0149 };
0150
0151 char *valid_name[] = {
0152 "!#$%&()-@^_`{}~'",
0153 "0_1_A",
0154 "aaa bbb",
0155 "ccc....ddd",
0156 " fff",
0157 0
0158 };
0159
0160
0161 make_multiple_files(valid_path,1);
0162 make_multiple_files (valid_name,1);
0163
0164 remove_multiple_files(valid_relative_path,1);
0165 remove_multiple_files(valid_name,1);
0166
0167 make_multiple_files(valid_file,0);
0168 make_multiple_files (valid_name,0);
0169
0170 remove_multiple_files(valid_relative_path,0);
0171 remove_multiple_files(valid_name,0);
0172
0173 }
0174 static void path_eval_test02(void )
0175 {
0176
0177 int status;
0178 char buf[BUF_SIZE];
0179 char* cwd;
0180
0181 mode_t mode = S_IRWXU|S_IRWXG|S_IRWXO;
0182 puts("mkdir /tmp/a/b");
0183 status=mkdir("/tmp",mode);
0184 rtems_test_assert(status==0);
0185 status=mkdir("/tmp/a",mode);
0186 rtems_test_assert(status==0);
0187 status=mkdir("/tmp/a/b",mode);
0188 rtems_test_assert(status==0);
0189
0190 cwd=getcwd(buf,BUF_SIZE);
0191 rtems_test_assert(cwd!=NULL);
0192
0193 puts("cd /tmp");
0194 status=chdir("/tmp");
0195 rtems_test_assert(status==0);
0196
0197 status=chdir("a/b");
0198 rtems_test_assert(status==0);
0199
0200 status=chdir("../b");
0201 rtems_test_assert(status==0);
0202
0203 status=chdir("../b/.");
0204 rtems_test_assert(status==0);
0205
0206 }
0207
0208 void test (void )
0209 {
0210 path_eval_test01();
0211 path_eval_test02();
0212 }