mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 08:42:40 +01:00 
			
		
		
		
	Added dir tests, test fixes, config
This commit is contained in:
		| @@ -18,13 +18,13 @@ def main(): | ||||
|         os.path.getsize(os.path.join('blocks', f)) | ||||
|         for f in os.listdir('blocks') if re.match('\d+', f)) | ||||
|  | ||||
|     print 'runtime: %.3f' % (time.time() - os.stat('blocks').st_ctime) | ||||
|  | ||||
|     with open('blocks/stats') as file: | ||||
|         s = struct.unpack('<QQQ', file.read()) | ||||
|         print 'read_count: %d' % s[0] | ||||
|         print 'prog_count: %d' % s[1] | ||||
|         print 'erase_count: %d' % s[2] | ||||
|  | ||||
|     print 'runtime: %.3f' % (time.time() - os.stat('blocks').st_ctime) | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     main(*sys.argv[1:]) | ||||
|   | ||||
| @@ -23,8 +23,9 @@ lfs_t lfs; | ||||
| lfs_emubd_t bd; | ||||
| lfs_file_t file[4]; | ||||
| lfs_dir_t dir[4]; | ||||
| struct lfs_bd_info info; | ||||
| struct lfs_bd_stats stats; | ||||
| struct lfs_bd_info bd_info; | ||||
| struct lfs_bd_stats bd_stats; | ||||
| struct lfs_info info; | ||||
|  | ||||
| uint8_t buffer[1024]; | ||||
| uint8_t wbuffer[1024]; | ||||
| @@ -35,6 +36,11 @@ lfs_size_t rsize; | ||||
|  | ||||
| uintmax_t res; | ||||
|  | ||||
| const struct lfs_config config = {{ | ||||
|     .bd = &bd, | ||||
|     .bd_ops = &lfs_emubd_ops, | ||||
| }}; | ||||
|  | ||||
|  | ||||
| int main() {{ | ||||
|     lfs_emubd_create(&bd, "blocks"); | ||||
|   | ||||
							
								
								
									
										59
									
								
								tests/test_dirs.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										59
									
								
								tests/test_dirs.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,59 @@ | ||||
| #!/bin/bash | ||||
| set -eu | ||||
|  | ||||
| echo "=== Directory tests ===" | ||||
| rm -rf blocks | ||||
|  | ||||
| echo "--- Root directory ---" | ||||
| tests/test.py << TEST | ||||
|     lfs_format(&lfs, &config) => 0; | ||||
|  | ||||
|     lfs_dir_open(&lfs, &dir[0], "/") => 0; | ||||
|     lfs_dir_close(&lfs, &dir[0]) => 0; | ||||
| TEST | ||||
|  | ||||
| echo "--- Directory creation ---" | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &config) => 0; | ||||
|     lfs_mkdir(&lfs, "potato") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
|  | ||||
| echo "--- File creation ---" | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &config) => 0; | ||||
|     lfs_file_open(&lfs, &file[0], "burito", LFS_O_CREAT | LFS_O_WRONLY) => 0; | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
|  | ||||
| echo "--- Directory iteration ---" | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &config) => 0; | ||||
|     lfs_dir_open(&lfs, &dir[0], "/") => 0; | ||||
|     lfs_dir_read(&lfs, &dir[0], &info) => 1; | ||||
|     strcmp(info.name, ".") => 0; | ||||
|     lfs_dir_read(&lfs, &dir[0], &info) => 1; | ||||
|     strcmp(info.name, "..") => 0; | ||||
|     lfs_dir_read(&lfs, &dir[0], &info) => 1; | ||||
|     strcmp(info.name, "potato") => 0; | ||||
|     lfs_dir_read(&lfs, &dir[0], &info) => 1; | ||||
|     strcmp(info.name, "burito") => 0; | ||||
|     lfs_dir_read(&lfs, &dir[0], &info) => 0; | ||||
|     lfs_dir_close(&lfs, &dir[0]) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
|  | ||||
| echo "--- Directory failures ---" | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &config) => 0; | ||||
|     lfs_mkdir(&lfs, "potato") => LFS_ERROR_EXISTS; | ||||
|     lfs_dir_open(&lfs, &dir[0], "tomato") => LFS_ERROR_NO_ENTRY; | ||||
|     lfs_dir_open(&lfs, &dir[0], "burito") => LFS_ERROR_NOT_DIR; | ||||
|     lfs_file_open(&lfs, &file[0], "tomato", LFS_O_RDONLY) => LFS_ERROR_NO_ENTRY; | ||||
|     lfs_file_open(&lfs, &file[0], "potato", LFS_O_RDONLY) => LFS_ERROR_IS_DIR; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
|  | ||||
| echo "--- Results ---" | ||||
| tests/stats.py | ||||
| @@ -5,41 +5,41 @@ echo "=== Formatting tests ===" | ||||
| rm -rf blocks | ||||
|  | ||||
| echo "--- Basic formatting ---" | ||||
| ./tests/test.py << TEST | ||||
|     lfs_format(&lfs, &bd, &lfs_emubd_ops) => 0; | ||||
| tests/test.py << TEST | ||||
|     lfs_format(&lfs, &config) => 0; | ||||
| TEST | ||||
|  | ||||
| echo "--- Invalid superblocks ---" | ||||
| ln -f -s /dev/null blocks/0 | ||||
| ./tests/test.py << TEST | ||||
|     lfs_format(&lfs, &bd, &lfs_emubd_ops) => LFS_ERROR_CORRUPT; | ||||
| tests/test.py << TEST | ||||
|     lfs_format(&lfs, &config) => LFS_ERROR_CORRUPT; | ||||
| TEST | ||||
| rm blocks/0 | ||||
|  | ||||
| echo "--- Basic mounting ---" | ||||
| ./tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &bd, &lfs_emubd_ops) => 0; | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &config) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
|  | ||||
| echo "--- Invalid mount ---" | ||||
| ./tests/test.py << TEST | ||||
|     lfs_format(&lfs, &bd, &lfs_emubd_ops) => 0; | ||||
| tests/test.py << TEST | ||||
|     lfs_format(&lfs, &config) => 0; | ||||
| TEST | ||||
| rm blocks/0 blocks/1 | ||||
| ./tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &bd, &lfs_emubd_ops) => LFS_ERROR_CORRUPT; | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &config) => LFS_ERROR_CORRUPT; | ||||
| TEST | ||||
|  | ||||
| echo "--- Valid corrupt mount ---" | ||||
| ./tests/test.py << TEST | ||||
|     lfs_format(&lfs, &bd, &lfs_emubd_ops) => 0; | ||||
| tests/test.py << TEST | ||||
|     lfs_format(&lfs, &config) => 0; | ||||
| TEST | ||||
| rm blocks/0 | ||||
| ./tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &bd, &lfs_emubd_ops) => 0; | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &config) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
|  | ||||
| echo "--- Results ---" | ||||
| ./tests/stats.py | ||||
| tests/stats.py | ||||
|   | ||||
		Reference in New Issue
	
	Block a user