1 2[[case]] # simple path test 3code = ''' 4 lfs_format(&lfs, &cfg) => 0; 5 lfs_mount(&lfs, &cfg) => 0; 6 lfs_mkdir(&lfs, "tea") => 0; 7 lfs_mkdir(&lfs, "tea/hottea") => 0; 8 lfs_mkdir(&lfs, "tea/warmtea") => 0; 9 lfs_mkdir(&lfs, "tea/coldtea") => 0; 10 11 lfs_stat(&lfs, "tea/hottea", &info) => 0; 12 assert(strcmp(info.name, "hottea") == 0); 13 lfs_stat(&lfs, "/tea/hottea", &info) => 0; 14 assert(strcmp(info.name, "hottea") == 0); 15 16 lfs_mkdir(&lfs, "/milk") => 0; 17 lfs_stat(&lfs, "/milk", &info) => 0; 18 assert(strcmp(info.name, "milk") == 0); 19 lfs_stat(&lfs, "milk", &info) => 0; 20 assert(strcmp(info.name, "milk") == 0); 21 lfs_unmount(&lfs) => 0; 22''' 23 24[[case]] # redundant slashes 25code = ''' 26 lfs_format(&lfs, &cfg) => 0; 27 lfs_mount(&lfs, &cfg) => 0; 28 lfs_mkdir(&lfs, "tea") => 0; 29 lfs_mkdir(&lfs, "tea/hottea") => 0; 30 lfs_mkdir(&lfs, "tea/warmtea") => 0; 31 lfs_mkdir(&lfs, "tea/coldtea") => 0; 32 33 lfs_stat(&lfs, "/tea/hottea", &info) => 0; 34 assert(strcmp(info.name, "hottea") == 0); 35 lfs_stat(&lfs, "//tea//hottea", &info) => 0; 36 assert(strcmp(info.name, "hottea") == 0); 37 lfs_stat(&lfs, "///tea///hottea", &info) => 0; 38 assert(strcmp(info.name, "hottea") == 0); 39 40 lfs_mkdir(&lfs, "////milk") => 0; 41 lfs_stat(&lfs, "////milk", &info) => 0; 42 assert(strcmp(info.name, "milk") == 0); 43 lfs_stat(&lfs, "milk", &info) => 0; 44 assert(strcmp(info.name, "milk") == 0); 45 lfs_unmount(&lfs) => 0; 46''' 47 48[[case]] # dot path test 49code = ''' 50 lfs_format(&lfs, &cfg) => 0; 51 lfs_mount(&lfs, &cfg) => 0; 52 lfs_mkdir(&lfs, "tea") => 0; 53 lfs_mkdir(&lfs, "tea/hottea") => 0; 54 lfs_mkdir(&lfs, "tea/warmtea") => 0; 55 lfs_mkdir(&lfs, "tea/coldtea") => 0; 56 57 lfs_stat(&lfs, "./tea/hottea", &info) => 0; 58 assert(strcmp(info.name, "hottea") == 0); 59 lfs_stat(&lfs, "/./tea/hottea", &info) => 0; 60 assert(strcmp(info.name, "hottea") == 0); 61 lfs_stat(&lfs, "/././tea/hottea", &info) => 0; 62 assert(strcmp(info.name, "hottea") == 0); 63 lfs_stat(&lfs, "/./tea/./hottea", &info) => 0; 64 assert(strcmp(info.name, "hottea") == 0); 65 66 lfs_mkdir(&lfs, "/./milk") => 0; 67 lfs_stat(&lfs, "/./milk", &info) => 0; 68 assert(strcmp(info.name, "milk") == 0); 69 lfs_stat(&lfs, "milk", &info) => 0; 70 assert(strcmp(info.name, "milk") == 0); 71 lfs_unmount(&lfs) => 0; 72''' 73 74[[case]] # dot dot path test 75code = ''' 76 lfs_format(&lfs, &cfg) => 0; 77 lfs_mount(&lfs, &cfg) => 0; 78 lfs_mkdir(&lfs, "tea") => 0; 79 lfs_mkdir(&lfs, "tea/hottea") => 0; 80 lfs_mkdir(&lfs, "tea/warmtea") => 0; 81 lfs_mkdir(&lfs, "tea/coldtea") => 0; 82 lfs_mkdir(&lfs, "coffee") => 0; 83 lfs_mkdir(&lfs, "coffee/hotcoffee") => 0; 84 lfs_mkdir(&lfs, "coffee/warmcoffee") => 0; 85 lfs_mkdir(&lfs, "coffee/coldcoffee") => 0; 86 87 lfs_stat(&lfs, "coffee/../tea/hottea", &info) => 0; 88 assert(strcmp(info.name, "hottea") == 0); 89 lfs_stat(&lfs, "tea/coldtea/../hottea", &info) => 0; 90 assert(strcmp(info.name, "hottea") == 0); 91 lfs_stat(&lfs, "coffee/coldcoffee/../../tea/hottea", &info) => 0; 92 assert(strcmp(info.name, "hottea") == 0); 93 lfs_stat(&lfs, "coffee/../coffee/../tea/hottea", &info) => 0; 94 assert(strcmp(info.name, "hottea") == 0); 95 96 lfs_mkdir(&lfs, "coffee/../milk") => 0; 97 lfs_stat(&lfs, "coffee/../milk", &info) => 0; 98 strcmp(info.name, "milk") => 0; 99 lfs_stat(&lfs, "milk", &info) => 0; 100 strcmp(info.name, "milk") => 0; 101 lfs_unmount(&lfs) => 0; 102''' 103 104[[case]] # trailing dot path test 105code = ''' 106 lfs_format(&lfs, &cfg) => 0; 107 lfs_mount(&lfs, &cfg) => 0; 108 lfs_mkdir(&lfs, "tea") => 0; 109 lfs_mkdir(&lfs, "tea/hottea") => 0; 110 lfs_mkdir(&lfs, "tea/warmtea") => 0; 111 lfs_mkdir(&lfs, "tea/coldtea") => 0; 112 113 lfs_stat(&lfs, "tea/hottea/", &info) => 0; 114 assert(strcmp(info.name, "hottea") == 0); 115 lfs_stat(&lfs, "tea/hottea/.", &info) => 0; 116 assert(strcmp(info.name, "hottea") == 0); 117 lfs_stat(&lfs, "tea/hottea/./.", &info) => 0; 118 assert(strcmp(info.name, "hottea") == 0); 119 lfs_stat(&lfs, "tea/hottea/..", &info) => 0; 120 assert(strcmp(info.name, "tea") == 0); 121 lfs_stat(&lfs, "tea/hottea/../.", &info) => 0; 122 assert(strcmp(info.name, "tea") == 0); 123 lfs_unmount(&lfs) => 0; 124''' 125 126[[case]] # leading dot path test 127code = ''' 128 lfs_format(&lfs, &cfg) => 0; 129 lfs_mount(&lfs, &cfg) => 0; 130 lfs_mkdir(&lfs, ".milk") => 0; 131 lfs_stat(&lfs, ".milk", &info) => 0; 132 strcmp(info.name, ".milk") => 0; 133 lfs_stat(&lfs, "tea/.././.milk", &info) => 0; 134 strcmp(info.name, ".milk") => 0; 135 lfs_unmount(&lfs) => 0; 136''' 137 138[[case]] # root dot dot path test 139code = ''' 140 lfs_format(&lfs, &cfg) => 0; 141 lfs_mount(&lfs, &cfg) => 0; 142 lfs_mkdir(&lfs, "tea") => 0; 143 lfs_mkdir(&lfs, "tea/hottea") => 0; 144 lfs_mkdir(&lfs, "tea/warmtea") => 0; 145 lfs_mkdir(&lfs, "tea/coldtea") => 0; 146 lfs_mkdir(&lfs, "coffee") => 0; 147 lfs_mkdir(&lfs, "coffee/hotcoffee") => 0; 148 lfs_mkdir(&lfs, "coffee/warmcoffee") => 0; 149 lfs_mkdir(&lfs, "coffee/coldcoffee") => 0; 150 151 lfs_stat(&lfs, "coffee/../../../../../../tea/hottea", &info) => 0; 152 strcmp(info.name, "hottea") => 0; 153 154 lfs_mkdir(&lfs, "coffee/../../../../../../milk") => 0; 155 lfs_stat(&lfs, "coffee/../../../../../../milk", &info) => 0; 156 strcmp(info.name, "milk") => 0; 157 lfs_stat(&lfs, "milk", &info) => 0; 158 strcmp(info.name, "milk") => 0; 159 lfs_unmount(&lfs) => 0; 160''' 161 162[[case]] # invalid path tests 163code = ''' 164 lfs_format(&lfs, &cfg); 165 lfs_mount(&lfs, &cfg) => 0; 166 lfs_stat(&lfs, "dirt", &info) => LFS_ERR_NOENT; 167 lfs_stat(&lfs, "dirt/ground", &info) => LFS_ERR_NOENT; 168 lfs_stat(&lfs, "dirt/ground/earth", &info) => LFS_ERR_NOENT; 169 170 lfs_remove(&lfs, "dirt") => LFS_ERR_NOENT; 171 lfs_remove(&lfs, "dirt/ground") => LFS_ERR_NOENT; 172 lfs_remove(&lfs, "dirt/ground/earth") => LFS_ERR_NOENT; 173 174 lfs_mkdir(&lfs, "dirt/ground") => LFS_ERR_NOENT; 175 lfs_file_open(&lfs, &file, "dirt/ground", LFS_O_WRONLY | LFS_O_CREAT) 176 => LFS_ERR_NOENT; 177 lfs_mkdir(&lfs, "dirt/ground/earth") => LFS_ERR_NOENT; 178 lfs_file_open(&lfs, &file, "dirt/ground/earth", LFS_O_WRONLY | LFS_O_CREAT) 179 => LFS_ERR_NOENT; 180 lfs_unmount(&lfs) => 0; 181''' 182 183[[case]] # root operations 184code = ''' 185 lfs_format(&lfs, &cfg) => 0; 186 lfs_mount(&lfs, &cfg) => 0; 187 lfs_stat(&lfs, "/", &info) => 0; 188 assert(strcmp(info.name, "/") == 0); 189 assert(info.type == LFS_TYPE_DIR); 190 191 lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST; 192 lfs_file_open(&lfs, &file, "/", LFS_O_WRONLY | LFS_O_CREAT) 193 => LFS_ERR_ISDIR; 194 195 lfs_remove(&lfs, "/") => LFS_ERR_INVAL; 196 lfs_unmount(&lfs) => 0; 197''' 198 199[[case]] # root representations 200code = ''' 201 lfs_format(&lfs, &cfg) => 0; 202 lfs_mount(&lfs, &cfg) => 0; 203 lfs_stat(&lfs, "/", &info) => 0; 204 assert(strcmp(info.name, "/") == 0); 205 assert(info.type == LFS_TYPE_DIR); 206 lfs_stat(&lfs, "", &info) => 0; 207 assert(strcmp(info.name, "/") == 0); 208 assert(info.type == LFS_TYPE_DIR); 209 lfs_stat(&lfs, ".", &info) => 0; 210 assert(strcmp(info.name, "/") == 0); 211 assert(info.type == LFS_TYPE_DIR); 212 lfs_stat(&lfs, "..", &info) => 0; 213 assert(strcmp(info.name, "/") == 0); 214 assert(info.type == LFS_TYPE_DIR); 215 lfs_stat(&lfs, "//", &info) => 0; 216 assert(strcmp(info.name, "/") == 0); 217 assert(info.type == LFS_TYPE_DIR); 218 lfs_stat(&lfs, "./", &info) => 0; 219 assert(strcmp(info.name, "/") == 0); 220 assert(info.type == LFS_TYPE_DIR); 221 lfs_unmount(&lfs) => 0; 222''' 223 224[[case]] # superblock conflict test 225code = ''' 226 lfs_format(&lfs, &cfg) => 0; 227 lfs_mount(&lfs, &cfg) => 0; 228 lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT; 229 lfs_remove(&lfs, "littlefs") => LFS_ERR_NOENT; 230 231 lfs_mkdir(&lfs, "littlefs") => 0; 232 lfs_stat(&lfs, "littlefs", &info) => 0; 233 assert(strcmp(info.name, "littlefs") == 0); 234 assert(info.type == LFS_TYPE_DIR); 235 lfs_remove(&lfs, "littlefs") => 0; 236 lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT; 237 lfs_unmount(&lfs) => 0; 238''' 239 240[[case]] # max path test 241code = ''' 242 lfs_format(&lfs, &cfg) => 0; 243 lfs_mount(&lfs, &cfg) => 0; 244 lfs_mkdir(&lfs, "coffee") => 0; 245 lfs_mkdir(&lfs, "coffee/hotcoffee") => 0; 246 lfs_mkdir(&lfs, "coffee/warmcoffee") => 0; 247 lfs_mkdir(&lfs, "coffee/coldcoffee") => 0; 248 249 memset(path, 'w', LFS_NAME_MAX+1); 250 path[LFS_NAME_MAX+1] = '\0'; 251 lfs_mkdir(&lfs, path) => LFS_ERR_NAMETOOLONG; 252 lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT) 253 => LFS_ERR_NAMETOOLONG; 254 255 memcpy(path, "coffee/", strlen("coffee/")); 256 memset(path+strlen("coffee/"), 'w', LFS_NAME_MAX+1); 257 path[strlen("coffee/")+LFS_NAME_MAX+1] = '\0'; 258 lfs_mkdir(&lfs, path) => LFS_ERR_NAMETOOLONG; 259 lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT) 260 => LFS_ERR_NAMETOOLONG; 261 lfs_unmount(&lfs) => 0; 262''' 263 264[[case]] # really big path test 265code = ''' 266 lfs_format(&lfs, &cfg) => 0; 267 lfs_mount(&lfs, &cfg) => 0; 268 lfs_mkdir(&lfs, "coffee") => 0; 269 lfs_mkdir(&lfs, "coffee/hotcoffee") => 0; 270 lfs_mkdir(&lfs, "coffee/warmcoffee") => 0; 271 lfs_mkdir(&lfs, "coffee/coldcoffee") => 0; 272 273 memset(path, 'w', LFS_NAME_MAX); 274 path[LFS_NAME_MAX] = '\0'; 275 lfs_mkdir(&lfs, path) => 0; 276 lfs_remove(&lfs, path) => 0; 277 lfs_file_open(&lfs, &file, path, 278 LFS_O_WRONLY | LFS_O_CREAT) => 0; 279 lfs_file_close(&lfs, &file) => 0; 280 lfs_remove(&lfs, path) => 0; 281 282 memcpy(path, "coffee/", strlen("coffee/")); 283 memset(path+strlen("coffee/"), 'w', LFS_NAME_MAX); 284 path[strlen("coffee/")+LFS_NAME_MAX] = '\0'; 285 lfs_mkdir(&lfs, path) => 0; 286 lfs_remove(&lfs, path) => 0; 287 lfs_file_open(&lfs, &file, path, 288 LFS_O_WRONLY | LFS_O_CREAT) => 0; 289 lfs_file_close(&lfs, &file) => 0; 290 lfs_remove(&lfs, path) => 0; 291 lfs_unmount(&lfs) => 0; 292''' 293 294