Skip to content

Commit f369f80

Browse files
committed
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.
1 parent 1941bbd commit f369f80

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

lfs.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,7 +2513,6 @@ int lfs_remove(lfs_t *lfs, const char *path) {
25132513
lfs_globaldeorphaned(lfs, true);
25142514

25152515
// steal state
2516-
// TODO test for global state stealing?
25172516
cwd.tail[0] = dir.tail[0];
25182517
cwd.tail[1] = dir.tail[1];
25192518
lfs_globalxor(&lfs->locals, &dir.locals);
@@ -2626,7 +2625,6 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) {
26262625
lfs_globaldeorphaned(lfs, true);
26272626

26282627
// steal state
2629-
// TODO test for global state stealing?
26302628
newcwd.tail[0] = prevdir.tail[0];
26312629
newcwd.tail[1] = prevdir.tail[1];
26322630
lfs_globalxor(&lfs->locals, &prevdir.locals);

tests/test_move.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,52 @@ tests/test.py << TEST
283283
lfs_unmount(&lfs) => 0;
284284
TEST
285285

286+
echo "--- Move state stealing ---"
287+
tests/test.py << TEST
288+
lfs_mount(&lfs, &cfg) => 0;
289+
290+
lfs_remove(&lfs, "b") => 0;
291+
lfs_remove(&lfs, "c") => 0;
292+
293+
lfs_unmount(&lfs) => 0;
294+
TEST
295+
tests/test.py << TEST
296+
lfs_mount(&lfs, &cfg) => 0;
297+
298+
lfs_dir_open(&lfs, &dir[0], "a/hi") => LFS_ERR_NOENT;
299+
lfs_dir_open(&lfs, &dir[0], "b") => LFS_ERR_NOENT;
300+
lfs_dir_open(&lfs, &dir[0], "c") => LFS_ERR_NOENT;
301+
302+
lfs_dir_open(&lfs, &dir[0], "d/hi") => 0;
303+
lfs_dir_read(&lfs, &dir[0], &info) => 1;
304+
strcmp(info.name, ".") => 0;
305+
lfs_dir_read(&lfs, &dir[0], &info) => 1;
306+
strcmp(info.name, "..") => 0;
307+
lfs_dir_read(&lfs, &dir[0], &info) => 1;
308+
strcmp(info.name, "hola") => 0;
309+
lfs_dir_read(&lfs, &dir[0], &info) => 1;
310+
strcmp(info.name, "bonjour") => 0;
311+
lfs_dir_read(&lfs, &dir[0], &info) => 1;
312+
strcmp(info.name, "ohayo") => 0;
313+
lfs_dir_read(&lfs, &dir[0], &info) => 0;
314+
lfs_dir_close(&lfs, &dir[0]) => 0;
315+
316+
lfs_dir_open(&lfs, &dir[0], "a/hello") => LFS_ERR_NOENT;
317+
lfs_dir_open(&lfs, &dir[0], "b") => LFS_ERR_NOENT;
318+
lfs_dir_open(&lfs, &dir[0], "c") => LFS_ERR_NOENT;
319+
320+
lfs_file_open(&lfs, &file[0], "d/hello", LFS_O_RDONLY) => 0;
321+
lfs_file_read(&lfs, &file[0], buffer, 5) => 5;
322+
memcmp(buffer, "hola\n", 5) => 0;
323+
lfs_file_read(&lfs, &file[0], buffer, 8) => 8;
324+
memcmp(buffer, "bonjour\n", 8) => 0;
325+
lfs_file_read(&lfs, &file[0], buffer, 6) => 6;
326+
memcmp(buffer, "ohayo\n", 6) => 0;
327+
lfs_file_close(&lfs, &file[0]) => 0;
328+
329+
lfs_unmount(&lfs) => 0;
330+
TEST
331+
286332

287333
echo "--- Results ---"
288334
tests/stats.py

0 commit comments

Comments
 (0)