From f369f80540193f28103a73b30acbc2063768c98a Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sat, 4 Aug 2018 18:55:04 -0500 Subject: [PATCH] Added tests for global state stealing State stealing is a tricky part of managing the xored-globals. When removing a metadata-pair from the metadata chain, whichever metadata-pair does the removing is also responsible for stealing the removed metadata-pair's global delta and incorporating it into it's own global delta. Otherwise the global state would become corrupted. --- lfs.c | 2 -- tests/test_move.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lfs.c b/lfs.c index dd47916..46c769a 100644 --- a/lfs.c +++ b/lfs.c @@ -2513,7 +2513,6 @@ int lfs_remove(lfs_t *lfs, const char *path) { lfs_globaldeorphaned(lfs, true); // steal state - // TODO test for global state stealing? cwd.tail[0] = dir.tail[0]; cwd.tail[1] = dir.tail[1]; lfs_globalxor(&lfs->locals, &dir.locals); @@ -2626,7 +2625,6 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { lfs_globaldeorphaned(lfs, true); // steal state - // TODO test for global state stealing? newcwd.tail[0] = prevdir.tail[0]; newcwd.tail[1] = prevdir.tail[1]; lfs_globalxor(&lfs->locals, &prevdir.locals); diff --git a/tests/test_move.sh b/tests/test_move.sh index bea618c..a36d058 100755 --- a/tests/test_move.sh +++ b/tests/test_move.sh @@ -283,6 +283,52 @@ tests/test.py << TEST lfs_unmount(&lfs) => 0; TEST +echo "--- Move state stealing ---" +tests/test.py << TEST + lfs_mount(&lfs, &cfg) => 0; + + lfs_remove(&lfs, "b") => 0; + lfs_remove(&lfs, "c") => 0; + + lfs_unmount(&lfs) => 0; +TEST +tests/test.py << TEST + lfs_mount(&lfs, &cfg) => 0; + + lfs_dir_open(&lfs, &dir[0], "a/hi") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir[0], "b") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir[0], "c") => LFS_ERR_NOENT; + + lfs_dir_open(&lfs, &dir[0], "d/hi") => 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, "hola") => 0; + lfs_dir_read(&lfs, &dir[0], &info) => 1; + strcmp(info.name, "bonjour") => 0; + lfs_dir_read(&lfs, &dir[0], &info) => 1; + strcmp(info.name, "ohayo") => 0; + lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_close(&lfs, &dir[0]) => 0; + + lfs_dir_open(&lfs, &dir[0], "a/hello") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir[0], "b") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir[0], "c") => LFS_ERR_NOENT; + + lfs_file_open(&lfs, &file[0], "d/hello", LFS_O_RDONLY) => 0; + lfs_file_read(&lfs, &file[0], buffer, 5) => 5; + memcmp(buffer, "hola\n", 5) => 0; + lfs_file_read(&lfs, &file[0], buffer, 8) => 8; + memcmp(buffer, "bonjour\n", 8) => 0; + lfs_file_read(&lfs, &file[0], buffer, 6) => 6; + memcmp(buffer, "ohayo\n", 6) => 0; + lfs_file_close(&lfs, &file[0]) => 0; + + lfs_unmount(&lfs) => 0; +TEST + echo "--- Results ---" tests/stats.py