Selaa lähdekoodia

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.
Christopher Haster 7 vuotta sitten
vanhempi
sitoutus
f369f80540
2 muutettua tiedostoa jossa 46 lisäystä ja 2 poistoa
  1. 0 2
      lfs.c
  2. 46 0
      tests/test_move.sh

+ 0 - 2
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);

+ 46 - 0
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