test_orphan.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. set -eu
  3. echo "=== Orphan tests ==="
  4. rm -rf blocks
  5. tests/test.py << TEST
  6. lfs_format(&lfs, &config) => 0;
  7. TEST
  8. echo "--- Orphan test ---"
  9. tests/test.py << TEST
  10. lfs_mount(&lfs, &config) => 0;
  11. lfs_mkdir(&lfs, "parent") => 0;
  12. lfs_mkdir(&lfs, "parent/orphan") => 0;
  13. lfs_mkdir(&lfs, "parent/child") => 0;
  14. lfs_remove(&lfs, "parent/orphan") => 0;
  15. TEST
  16. # remove most recent file, this should be the update to the previous
  17. # linked-list entry and should orphan the child
  18. rm -v "blocks/$(ls -t blocks | sed -n '/^[0-9a-f]*$/p' | sed -n '1p')"
  19. tests/test.py << TEST
  20. lfs_mount(&lfs, &config) => 0;
  21. lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERROR_NO_ENTRY;
  22. unsigned before = 0;
  23. lfs_traverse(&lfs, test_count, &before) => 0;
  24. test_log("before", before);
  25. lfs_deorphan(&lfs) => 0;
  26. lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERROR_NO_ENTRY;
  27. unsigned after = 0;
  28. lfs_traverse(&lfs, test_count, &after) => 0;
  29. test_log("after", after);
  30. int diff = before - after;
  31. diff => 2;
  32. lfs_unmount(&lfs) => 0;
  33. TEST
  34. echo "--- Results ---"
  35. tests/stats.py