mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 08:42:40 +01:00 
			
		
		
		
	Fixed testing issues introduced by expanding superblocks
This was mostly tweaking test cases to be accommodating for variable sized superblock-lists. Though there were a few bugs that needed fixing: - Changed compact to use source dir for move since the original dir could have changed as a result of an expand. - Created copy of current directory so we don't overwrite ourselves during an internal commit update. Also made sure all of the test suites provide reproducable results when ran independently (the entry tests were behaving differently based on which tests were ran before). (Some where legitimate test failures)
This commit is contained in:
		| @@ -194,55 +194,98 @@ tests/test.py << TEST | ||||
|     lfs_file_read(&lfs, &file[0], buffer, size) => size; | ||||
|     memcmp(buffer, "exhaustion", size) => 0; | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|     lfs_remove(&lfs, "exhaustion") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
|  | ||||
| echo "--- Dir exhaustion test ---" | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_remove(&lfs, "exhaustion") => 0; | ||||
|  | ||||
|     lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); | ||||
|     // find out max file size | ||||
|     lfs_mkdir(&lfs, "exhaustiondir") => 0; | ||||
|     size = strlen("blahblahblahblah"); | ||||
|     memcpy(buffer, "blahblahblahblah", size); | ||||
|     for (lfs_size_t i = 0; | ||||
|             i < (cfg.block_count-4)*(cfg.block_size-8); | ||||
|             i += size) { | ||||
|     lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); | ||||
|     int count = 0; | ||||
|     int err; | ||||
|     while (true) { | ||||
|         err = lfs_file_write(&lfs, &file[0], buffer, size); | ||||
|         if (err < 0) { | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         count += 1; | ||||
|     } | ||||
|     err => LFS_ERR_NOSPC; | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|  | ||||
|     lfs_remove(&lfs, "exhaustion") => 0; | ||||
|     lfs_remove(&lfs, "exhaustiondir") => 0; | ||||
|  | ||||
|     // see if dir fits with max file size | ||||
|     lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); | ||||
|     for (int i = 0; i < count; i++) { | ||||
|         lfs_file_write(&lfs, &file[0], buffer, size) => size; | ||||
|     } | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|  | ||||
|     lfs_mkdir(&lfs, "exhaustiondir") => 0; | ||||
|     lfs_remove(&lfs, "exhaustiondir") => 0; | ||||
|     lfs_remove(&lfs, "exhaustion") => 0; | ||||
|  | ||||
|     lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_APPEND); | ||||
|     size = strlen("blahblahblahblah"); | ||||
|     memcpy(buffer, "blahblahblahblah", size); | ||||
|     for (lfs_size_t i = 0; | ||||
|             i < (cfg.block_size-8); | ||||
|             i += size) { | ||||
|     // see if dir fits with > max file size | ||||
|     lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); | ||||
|     for (int i = 0; i < count+1; i++) { | ||||
|         lfs_file_write(&lfs, &file[0], buffer, size) => size; | ||||
|     } | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|  | ||||
|     lfs_mkdir(&lfs, "exhaustiondir") => LFS_ERR_NOSPC; | ||||
|  | ||||
|     lfs_remove(&lfs, "exhaustion") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
|  | ||||
| echo "--- Chained dir exhaustion test ---" | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_remove(&lfs, "exhaustion") => 0; | ||||
|  | ||||
|     lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); | ||||
|     // find out max file size | ||||
|     lfs_mkdir(&lfs, "exhaustiondir") => 0; | ||||
|     for (int i = 0; i < 9; i++) { | ||||
|         sprintf((char*)buffer, "dirwithanexhaustivelylongnameforpadding%d", i); | ||||
|         lfs_mkdir(&lfs, (char*)buffer) => 0; | ||||
|     } | ||||
|     size = strlen("blahblahblahblah"); | ||||
|     memcpy(buffer, "blahblahblahblah", size); | ||||
|     for (lfs_size_t i = 0; | ||||
|             i < (cfg.block_count-24)*(cfg.block_size-8); | ||||
|             i += size) { | ||||
|     lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); | ||||
|     int count = 0; | ||||
|     int err; | ||||
|     while (true) { | ||||
|         err = lfs_file_write(&lfs, &file[0], buffer, size); | ||||
|         if (err < 0) { | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         count += 1; | ||||
|     } | ||||
|     err => LFS_ERR_NOSPC; | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|  | ||||
|     lfs_remove(&lfs, "exhaustion") => 0; | ||||
|     lfs_remove(&lfs, "exhaustiondir") => 0; | ||||
|     for (int i = 0; i < 9; i++) { | ||||
|         sprintf((char*)buffer, "dirwithanexhaustivelylongnameforpadding%d", i); | ||||
|         lfs_remove(&lfs, (char*)buffer) => 0; | ||||
|     } | ||||
|  | ||||
|     // see that chained dir fails | ||||
|     lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); | ||||
|     for (int i = 0; i < count+1; i++) { | ||||
|         lfs_file_write(&lfs, &file[0], buffer, size) => size; | ||||
|     } | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|     lfs_file_sync(&lfs, &file[0]) => 0; | ||||
|  | ||||
|     for (int i = 0; i < 9; i++) { | ||||
|         sprintf((char*)buffer, "dirwithanexhaustivelylongnameforpadding%d", i); | ||||
| @@ -251,19 +294,25 @@ tests/test.py << TEST | ||||
|  | ||||
|     lfs_mkdir(&lfs, "exhaustiondir") => LFS_ERR_NOSPC; | ||||
|  | ||||
|     lfs_remove(&lfs, "exhaustion") => 0; | ||||
|     lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); | ||||
|     size = strlen("blahblahblahblah"); | ||||
|     memcpy(buffer, "blahblahblahblah", size); | ||||
|     for (lfs_size_t i = 0; | ||||
|             i < (cfg.block_count-26)*(cfg.block_size-8); | ||||
|             i += size) { | ||||
|         lfs_file_write(&lfs, &file[0], buffer, size) => size; | ||||
|     } | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|     // shorten file to try a second chained dir | ||||
|     while (true) { | ||||
|         err = lfs_mkdir(&lfs, "exhaustiondir"); | ||||
|         if (err != LFS_ERR_NOSPC) { | ||||
|             break; | ||||
|         } | ||||
|  | ||||
|         lfs_ssize_t filesize = lfs_file_size(&lfs, &file[0]); | ||||
|         filesize > 0 => true; | ||||
|  | ||||
|         lfs_file_truncate(&lfs, &file[0], filesize - size) => 0; | ||||
|         lfs_file_sync(&lfs, &file[0]) => 0; | ||||
|     } | ||||
|     err => 0; | ||||
|  | ||||
|     lfs_mkdir(&lfs, "exhaustiondir") => 0; | ||||
|     lfs_mkdir(&lfs, "exhaustiondir2") => LFS_ERR_NOSPC; | ||||
|  | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
|  | ||||
| echo "--- Split dir test ---" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user