mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	Migrated the first of the tests with internal knowledge
Both test_move and test_orphan needed internal knowledge which comes with the addition of the "in" attribute. This was in the plan for the test-revamp from the beginning as it really opens up the ability to write more unit-style-tests using internal knowledge of how littlefs works. More unit-style-tests should help _fix_ bugs by limiting the scope of the test and where the bug could be hiding. The "in" attribute effectively runs tests _inside_ the .c file specified, giving the test access to all static members without needed to change their visibility.
This commit is contained in:
		
							
								
								
									
										957
									
								
								tests_/test_move.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										957
									
								
								tests_/test_move.toml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,957 @@ | ||||
| [[case]] # move file | ||||
| code = ''' | ||||
|     lfs_format(&lfs, &cfg) => 0; | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_mkdir(&lfs, "a") => 0; | ||||
|     lfs_mkdir(&lfs, "b") => 0; | ||||
|     lfs_mkdir(&lfs, "c") => 0; | ||||
|     lfs_mkdir(&lfs, "d") => 0; | ||||
|     lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0; | ||||
|     lfs_file_write(&lfs, &file, "hola\n", 5) => 5; | ||||
|     lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8; | ||||
|     lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6; | ||||
|     lfs_file_close(&lfs, &file) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "a/hello", "c/hello") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "c") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hello") == 0); | ||||
|     assert(info.type == LFS_TYPE_REG); | ||||
|     assert(info.size == 5+8+6); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|  | ||||
|     lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 5) => 5; | ||||
|     memcmp(buffer, "hola\n", 5) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 8) => 8; | ||||
|     memcmp(buffer, "bonjour\n", 8) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 6) => 6; | ||||
|     memcmp(buffer, "ohayo\n", 6) => 0; | ||||
|     lfs_file_close(&lfs, &file) => 0; | ||||
|     lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| ''' | ||||
|  | ||||
| [[case]] # move file corrupt source | ||||
| in = "lfs.c" | ||||
| code = ''' | ||||
|     lfs_format(&lfs, &cfg) => 0; | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_mkdir(&lfs, "a") => 0; | ||||
|     lfs_mkdir(&lfs, "b") => 0; | ||||
|     lfs_mkdir(&lfs, "c") => 0; | ||||
|     lfs_mkdir(&lfs, "d") => 0; | ||||
|     lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0; | ||||
|     lfs_file_write(&lfs, &file, "hola\n", 5) => 5; | ||||
|     lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8; | ||||
|     lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6; | ||||
|     lfs_file_close(&lfs, &file) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "a/hello", "c/hello") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     // corrupt the source | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_block_t block = dir.m.pair[0]; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|     uint8_t bbuffer[LFS_BLOCK_SIZE]; | ||||
|     cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     int off = LFS_BLOCK_SIZE-1; | ||||
|     while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) { | ||||
|         off -= 1; | ||||
|     } | ||||
|     memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3); | ||||
|     cfg.erase(&cfg, block) => 0; | ||||
|     cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     cfg.sync(&cfg) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "c") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hello") == 0); | ||||
|     assert(info.type == LFS_TYPE_REG); | ||||
|     assert(info.size == 5+8+6); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|  | ||||
|     lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 5) => 5; | ||||
|     memcmp(buffer, "hola\n", 5) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 8) => 8; | ||||
|     memcmp(buffer, "bonjour\n", 8) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 6) => 6; | ||||
|     memcmp(buffer, "ohayo\n", 6) => 0; | ||||
|     lfs_file_close(&lfs, &file) => 0; | ||||
|     lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| ''' | ||||
|  | ||||
| [[case]] # move file corrupt source and dest | ||||
| in = "lfs.c" | ||||
| code = ''' | ||||
|     lfs_format(&lfs, &cfg) => 0; | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_mkdir(&lfs, "a") => 0; | ||||
|     lfs_mkdir(&lfs, "b") => 0; | ||||
|     lfs_mkdir(&lfs, "c") => 0; | ||||
|     lfs_mkdir(&lfs, "d") => 0; | ||||
|     lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0; | ||||
|     lfs_file_write(&lfs, &file, "hola\n", 5) => 5; | ||||
|     lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8; | ||||
|     lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6; | ||||
|     lfs_file_close(&lfs, &file) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "a/hello", "c/hello") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     // corrupt the source | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_block_t block = dir.m.pair[0]; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|     uint8_t bbuffer[LFS_BLOCK_SIZE]; | ||||
|     cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     int off = LFS_BLOCK_SIZE-1; | ||||
|     while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) { | ||||
|         off -= 1; | ||||
|     } | ||||
|     memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3); | ||||
|     cfg.erase(&cfg, block) => 0; | ||||
|     cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     cfg.sync(&cfg) => 0; | ||||
|  | ||||
|     // corrupt the destination | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "c") => 0; | ||||
|     block = dir.m.pair[0]; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|     cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     off = LFS_BLOCK_SIZE-1; | ||||
|     while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) { | ||||
|         off -= 1; | ||||
|     } | ||||
|     memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3); | ||||
|     cfg.erase(&cfg, block) => 0; | ||||
|     cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     cfg.sync(&cfg) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hello") == 0); | ||||
|     assert(info.type == LFS_TYPE_REG); | ||||
|     assert(info.size == 5+8+6); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "c") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|  | ||||
|     lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 5) => 5; | ||||
|     memcmp(buffer, "hola\n", 5) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 8) => 8; | ||||
|     memcmp(buffer, "bonjour\n", 8) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 6) => 6; | ||||
|     memcmp(buffer, "ohayo\n", 6) => 0; | ||||
|     lfs_file_close(&lfs, &file) => 0; | ||||
|     lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| ''' | ||||
|  | ||||
| [[case]] # move file after corrupt | ||||
| in = "lfs.c" | ||||
| code = ''' | ||||
|     lfs_format(&lfs, &cfg) => 0; | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_mkdir(&lfs, "a") => 0; | ||||
|     lfs_mkdir(&lfs, "b") => 0; | ||||
|     lfs_mkdir(&lfs, "c") => 0; | ||||
|     lfs_mkdir(&lfs, "d") => 0; | ||||
|     lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0; | ||||
|     lfs_file_write(&lfs, &file, "hola\n", 5) => 5; | ||||
|     lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8; | ||||
|     lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6; | ||||
|     lfs_file_close(&lfs, &file) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "a/hello", "c/hello") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     // corrupt the source | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_block_t block = dir.m.pair[0]; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|     uint8_t bbuffer[LFS_BLOCK_SIZE]; | ||||
|     cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     int off = LFS_BLOCK_SIZE-1; | ||||
|     while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) { | ||||
|         off -= 1; | ||||
|     } | ||||
|     memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3); | ||||
|     cfg.erase(&cfg, block) => 0; | ||||
|     cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     cfg.sync(&cfg) => 0; | ||||
|  | ||||
|     // corrupt the destination | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "c") => 0; | ||||
|     block = dir.m.pair[0]; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|     cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     off = LFS_BLOCK_SIZE-1; | ||||
|     while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) { | ||||
|         off -= 1; | ||||
|     } | ||||
|     memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3); | ||||
|     cfg.erase(&cfg, block) => 0; | ||||
|     cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     cfg.sync(&cfg) => 0; | ||||
|  | ||||
|     // continue move | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "a/hello", "c/hello") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "c") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hello") == 0); | ||||
|     assert(info.type == LFS_TYPE_REG); | ||||
|     assert(info.size == 5+8+6); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|  | ||||
|     lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 5) => 5; | ||||
|     memcmp(buffer, "hola\n", 5) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 8) => 8; | ||||
|     memcmp(buffer, "bonjour\n", 8) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 6) => 6; | ||||
|     memcmp(buffer, "ohayo\n", 6) => 0; | ||||
|     lfs_file_close(&lfs, &file) => 0; | ||||
|     lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| ''' | ||||
|  | ||||
| [[case]] # simple reentrant move file | ||||
| reentrant = true | ||||
| code = ''' | ||||
|     err = lfs_mount(&lfs, &cfg); | ||||
|     if (err) { | ||||
|         lfs_format(&lfs, &cfg) => 0; | ||||
|         lfs_mount(&lfs, &cfg) => 0; | ||||
|     } | ||||
|     err = lfs_mkdir(&lfs, "a"); | ||||
|     assert(!err || err == LFS_ERR_EXIST); | ||||
|     err = lfs_mkdir(&lfs, "b"); | ||||
|     assert(!err || err == LFS_ERR_EXIST); | ||||
|     err = lfs_mkdir(&lfs, "c"); | ||||
|     assert(!err || err == LFS_ERR_EXIST); | ||||
|     err = lfs_mkdir(&lfs, "d"); | ||||
|     assert(!err || err == LFS_ERR_EXIST); | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     while (true) { | ||||
|         lfs_mount(&lfs, &cfg) => 0; | ||||
|         // there should never exist _2_ hello files | ||||
|         int count = 0; | ||||
|         if (lfs_stat(&lfs, "a/hello", &info) == 0) { | ||||
|             assert(strcmp(info.name, "hello") == 0); | ||||
|             assert(info.type == LFS_TYPE_REG); | ||||
|             assert(info.size == 5+8+6 || info.size == 0); | ||||
|             count += 1; | ||||
|         } | ||||
|         if (lfs_stat(&lfs, "b/hello", &info) == 0) { | ||||
|             assert(strcmp(info.name, "hello") == 0); | ||||
|             assert(info.type == LFS_TYPE_REG); | ||||
|             assert(info.size == 5+8+6); | ||||
|             count += 1;  | ||||
|         } | ||||
|         if (lfs_stat(&lfs, "c/hello", &info) == 0) { | ||||
|             assert(strcmp(info.name, "hello") == 0); | ||||
|             assert(info.type == LFS_TYPE_REG); | ||||
|             assert(info.size == 5+8+6); | ||||
|             count += 1; | ||||
|         } | ||||
|         if (lfs_stat(&lfs, "d/hello", &info) == 0) { | ||||
|             assert(strcmp(info.name, "hello") == 0); | ||||
|             assert(info.type == LFS_TYPE_REG); | ||||
|             assert(info.size == 5+8+6); | ||||
|             count += 1; | ||||
|         } | ||||
|         assert(count <= 1); | ||||
|         lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|         lfs_mount(&lfs, &cfg) => 0; | ||||
|         if (lfs_stat(&lfs, "a/hello", &info) == 0 && info.size > 0) { | ||||
|             lfs_rename(&lfs, "a/hello", "b/hello") => 0; | ||||
|         } else if (lfs_stat(&lfs, "b/hello", &info) == 0) { | ||||
|             lfs_rename(&lfs, "b/hello", "c/hello") => 0; | ||||
|         } else if (lfs_stat(&lfs, "c/hello", &info) == 0) { | ||||
|             lfs_rename(&lfs, "c/hello", "d/hello") => 0; | ||||
|         } else if (lfs_stat(&lfs, "d/hello", &info) == 0) { | ||||
|             // success | ||||
|             break; | ||||
|         } else { | ||||
|             // create file | ||||
|             lfs_file_open(&lfs, &file, "a/hello", | ||||
|                     LFS_O_WRONLY | LFS_O_CREAT) => 0; | ||||
|             lfs_file_write(&lfs, &file, "hola\n", 5) => 5; | ||||
|             lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8; | ||||
|             lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6; | ||||
|             lfs_file_close(&lfs, &file) => 0; | ||||
|         } | ||||
|         lfs_unmount(&lfs) => 0; | ||||
|     } | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "d") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hello") == 0); | ||||
|     assert(info.type == LFS_TYPE_REG); | ||||
|     assert(info.size == 5+8+6); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|  | ||||
|     lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 5) => 5; | ||||
|     memcmp(buffer, "hola\n", 5) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 8) => 8; | ||||
|     memcmp(buffer, "bonjour\n", 8) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 6) => 6; | ||||
|     memcmp(buffer, "ohayo\n", 6) => 0; | ||||
|     lfs_file_close(&lfs, &file) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| ''' | ||||
|  | ||||
| [[case]] # move dir | ||||
| code = ''' | ||||
|     lfs_format(&lfs, &cfg) => 0; | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_mkdir(&lfs, "a") => 0; | ||||
|     lfs_mkdir(&lfs, "b") => 0; | ||||
|     lfs_mkdir(&lfs, "c") => 0; | ||||
|     lfs_mkdir(&lfs, "d") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi/hola") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi/bonjour") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi/ohayo") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "a/hi", "c/hi") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "c") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hi") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|  | ||||
|     lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT; | ||||
|     lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT; | ||||
|     lfs_dir_open(&lfs, &dir, "c/hi") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "bonjour") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hola") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "ohayo") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| ''' | ||||
|  | ||||
| [[case]] # move dir corrupt source | ||||
| in = "lfs.c" | ||||
| code = ''' | ||||
|     lfs_format(&lfs, &cfg) => 0; | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_mkdir(&lfs, "a") => 0; | ||||
|     lfs_mkdir(&lfs, "b") => 0; | ||||
|     lfs_mkdir(&lfs, "c") => 0; | ||||
|     lfs_mkdir(&lfs, "d") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi/hola") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi/bonjour") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi/ohayo") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "a/hi", "c/hi") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     // corrupt the source | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_block_t block = dir.m.pair[0]; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|     uint8_t bbuffer[LFS_BLOCK_SIZE]; | ||||
|     cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     int off = LFS_BLOCK_SIZE-1; | ||||
|     while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) { | ||||
|         off -= 1; | ||||
|     } | ||||
|     memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3); | ||||
|     cfg.erase(&cfg, block) => 0; | ||||
|     cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     cfg.sync(&cfg) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "c") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hi") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|  | ||||
|     lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT; | ||||
|     lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT; | ||||
|     lfs_dir_open(&lfs, &dir, "c/hi") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "bonjour") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hola") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "ohayo") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| ''' | ||||
|  | ||||
| [[case]] # move dir corrupt source and dest | ||||
| in = "lfs.c" | ||||
| code = ''' | ||||
|     lfs_format(&lfs, &cfg) => 0; | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_mkdir(&lfs, "a") => 0; | ||||
|     lfs_mkdir(&lfs, "b") => 0; | ||||
|     lfs_mkdir(&lfs, "c") => 0; | ||||
|     lfs_mkdir(&lfs, "d") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi/hola") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi/bonjour") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi/ohayo") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "a/hi", "c/hi") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     // corrupt the source | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_block_t block = dir.m.pair[0]; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|     uint8_t bbuffer[LFS_BLOCK_SIZE]; | ||||
|     cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     int off = LFS_BLOCK_SIZE-1; | ||||
|     while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) { | ||||
|         off -= 1; | ||||
|     } | ||||
|     memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3); | ||||
|     cfg.erase(&cfg, block) => 0; | ||||
|     cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     cfg.sync(&cfg) => 0; | ||||
|  | ||||
|     // corrupt the destination | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "c") => 0; | ||||
|     block = dir.m.pair[0]; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|     cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     off = LFS_BLOCK_SIZE-1; | ||||
|     while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) { | ||||
|         off -= 1; | ||||
|     } | ||||
|     memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3); | ||||
|     cfg.erase(&cfg, block) => 0; | ||||
|     cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     cfg.sync(&cfg) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hi") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "c") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|  | ||||
|     lfs_dir_open(&lfs, &dir, "a/hi") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "bonjour") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hola") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "ohayo") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT; | ||||
|     lfs_dir_open(&lfs, &dir, "c/hi") => LFS_ERR_NOENT; | ||||
|     lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| ''' | ||||
|  | ||||
| [[case]] # move dir after corrupt | ||||
| in = "lfs.c" | ||||
| code = ''' | ||||
|     lfs_format(&lfs, &cfg) => 0; | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_mkdir(&lfs, "a") => 0; | ||||
|     lfs_mkdir(&lfs, "b") => 0; | ||||
|     lfs_mkdir(&lfs, "c") => 0; | ||||
|     lfs_mkdir(&lfs, "d") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi/hola") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi/bonjour") => 0; | ||||
|     lfs_mkdir(&lfs, "a/hi/ohayo") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "a/hi", "c/hi") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     // corrupt the source | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_block_t block = dir.m.pair[0]; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|     uint8_t bbuffer[LFS_BLOCK_SIZE]; | ||||
|     cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     int off = LFS_BLOCK_SIZE-1; | ||||
|     while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) { | ||||
|         off -= 1; | ||||
|     } | ||||
|     memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3); | ||||
|     cfg.erase(&cfg, block) => 0; | ||||
|     cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     cfg.sync(&cfg) => 0; | ||||
|  | ||||
|     // corrupt the destination | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "c") => 0; | ||||
|     block = dir.m.pair[0]; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|     cfg.read(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     off = LFS_BLOCK_SIZE-1; | ||||
|     while (off >= 0 && bbuffer[off] == LFS_ERASE_VALUE) { | ||||
|         off -= 1; | ||||
|     } | ||||
|     memset(&bbuffer[off-3], LFS_BLOCK_SIZE, 3); | ||||
|     cfg.erase(&cfg, block) => 0; | ||||
|     cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; | ||||
|     cfg.sync(&cfg) => 0; | ||||
|  | ||||
|     // continue move | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "a/hi", "c/hi") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "c") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hi") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|  | ||||
|     lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT; | ||||
|     lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT; | ||||
|     lfs_dir_open(&lfs, &dir, "c/hi") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "bonjour") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hola") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "ohayo") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "d/hi") => LFS_ERR_NOENT; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| ''' | ||||
|  | ||||
| [[case]] # simple reentrant move dir | ||||
| reentrant = true | ||||
| code = ''' | ||||
|     err = lfs_mount(&lfs, &cfg); | ||||
|     if (err) { | ||||
|         lfs_format(&lfs, &cfg) => 0; | ||||
|         lfs_mount(&lfs, &cfg) => 0; | ||||
|     } | ||||
|     err = lfs_mkdir(&lfs, "a"); | ||||
|     assert(!err || err == LFS_ERR_EXIST); | ||||
|     err = lfs_mkdir(&lfs, "b"); | ||||
|     assert(!err || err == LFS_ERR_EXIST); | ||||
|     err = lfs_mkdir(&lfs, "c"); | ||||
|     assert(!err || err == LFS_ERR_EXIST); | ||||
|     err = lfs_mkdir(&lfs, "d"); | ||||
|     assert(!err || err == LFS_ERR_EXIST); | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     while (true) { | ||||
|         lfs_mount(&lfs, &cfg) => 0; | ||||
|         // there should never exist _2_ hi directories | ||||
|         int count = 0; | ||||
|         if (lfs_stat(&lfs, "a/hi", &info) == 0) { | ||||
|             assert(strcmp(info.name, "hi") == 0); | ||||
|             assert(info.type == LFS_TYPE_DIR); | ||||
|             count += 1; | ||||
|         } | ||||
|         if (lfs_stat(&lfs, "b/hi", &info) == 0) { | ||||
|             assert(strcmp(info.name, "hi") == 0); | ||||
|             assert(info.type == LFS_TYPE_DIR); | ||||
|             count += 1;  | ||||
|         } | ||||
|         if (lfs_stat(&lfs, "c/hi", &info) == 0) { | ||||
|             assert(strcmp(info.name, "hi") == 0); | ||||
|             assert(info.type == LFS_TYPE_DIR); | ||||
|             count += 1; | ||||
|         } | ||||
|         if (lfs_stat(&lfs, "d/hi", &info) == 0) { | ||||
|             assert(strcmp(info.name, "hi") == 0); | ||||
|             assert(info.type == LFS_TYPE_DIR); | ||||
|             count += 1; | ||||
|         } | ||||
|         assert(count <= 1); | ||||
|         lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|         lfs_mount(&lfs, &cfg) => 0; | ||||
|         if (lfs_stat(&lfs, "a/hi", &info) == 0) { | ||||
|             lfs_rename(&lfs, "a/hi", "b/hi") => 0; | ||||
|         } else if (lfs_stat(&lfs, "b/hi", &info) == 0) { | ||||
|             lfs_rename(&lfs, "b/hi", "c/hi") => 0; | ||||
|         } else if (lfs_stat(&lfs, "c/hi", &info) == 0) { | ||||
|             lfs_rename(&lfs, "c/hi", "d/hi") => 0; | ||||
|         } else if (lfs_stat(&lfs, "d/hi", &info) == 0) { | ||||
|             break; // success | ||||
|         } else { | ||||
|             // create dir and rename for atomicity | ||||
|             err = lfs_mkdir(&lfs, "temp"); | ||||
|             assert(!err || err == LFS_ERR_EXIST); | ||||
|             err = lfs_mkdir(&lfs, "temp/hola"); | ||||
|             assert(!err || err == LFS_ERR_EXIST); | ||||
|             err = lfs_mkdir(&lfs, "temp/bonjour"); | ||||
|             assert(!err || err == LFS_ERR_EXIST); | ||||
|             err = lfs_mkdir(&lfs, "temp/ohayo"); | ||||
|             assert(!err || err == LFS_ERR_EXIST); | ||||
|             lfs_rename(&lfs, "temp", "a/hi") => 0; | ||||
|         } | ||||
|         lfs_unmount(&lfs) => 0; | ||||
|     } | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "a") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_dir_open(&lfs, &dir, "d") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hi") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|  | ||||
|     lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT; | ||||
|     lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT; | ||||
|     lfs_dir_open(&lfs, &dir, "c/hi") => LFS_ERR_NOENT; | ||||
|     lfs_dir_open(&lfs, &dir, "d/hi") => 0; | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, ".") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "..") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "bonjour") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "hola") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 1; | ||||
|     assert(strcmp(info.name, "ohayo") == 0); | ||||
|     assert(info.type == LFS_TYPE_DIR); | ||||
|     lfs_dir_read(&lfs, &dir, &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| ''' | ||||
|  | ||||
| [[case]] # move state stealing | ||||
| code = ''' | ||||
|     lfs_format(&lfs, &cfg) => 0; | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_mkdir(&lfs, "a") => 0; | ||||
|     lfs_mkdir(&lfs, "b") => 0; | ||||
|     lfs_mkdir(&lfs, "c") => 0; | ||||
|     lfs_mkdir(&lfs, "d") => 0; | ||||
|     lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0; | ||||
|     lfs_file_write(&lfs, &file, "hola\n", 5) => 5; | ||||
|     lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8; | ||||
|     lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6; | ||||
|     lfs_file_close(&lfs, &file) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "a/hello", "b/hello") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "b/hello", "c/hello") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_rename(&lfs, "c/hello", "d/hello") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 5) => 5; | ||||
|     memcmp(buffer, "hola\n", 5) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 8) => 8; | ||||
|     memcmp(buffer, "bonjour\n", 8) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 6) => 6; | ||||
|     memcmp(buffer, "ohayo\n", 6) => 0; | ||||
|     lfs_file_close(&lfs, &file) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_remove(&lfs, "b") => 0; | ||||
|     lfs_remove(&lfs, "c") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
|  | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_stat(&lfs, "a", &info) => 0; | ||||
|     lfs_stat(&lfs, "b", &info) => LFS_ERR_NOENT; | ||||
|     lfs_stat(&lfs, "c", &info) => LFS_ERR_NOENT; | ||||
|     lfs_stat(&lfs, "d", &info) => 0; | ||||
|     lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; | ||||
|     lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 5) => 5; | ||||
|     memcmp(buffer, "hola\n", 5) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 8) => 8; | ||||
|     memcmp(buffer, "bonjour\n", 8) => 0; | ||||
|     lfs_file_read(&lfs, &file, buffer, 6) => 6; | ||||
|     memcmp(buffer, "ohayo\n", 6) => 0; | ||||
|     lfs_file_close(&lfs, &file) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| ''' | ||||
		Reference in New Issue
	
	Block a user