test_relocations.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. set -eu
  3. export TEST_FILE=$0
  4. trap 'export TEST_LINE=$LINENO' DEBUG
  5. ITERATIONS=20
  6. COUNT=10
  7. echo "=== Relocation tests ==="
  8. rm -rf blocks
  9. scripts/test.py << TEST
  10. lfs_format(&lfs, &cfg) => 0;
  11. // fill up filesystem so only ~16 blocks are left
  12. lfs_mount(&lfs, &cfg) => 0;
  13. lfs_file_open(&lfs, &file, "padding", LFS_O_CREAT | LFS_O_WRONLY) => 0;
  14. memset(buffer, 0, 512);
  15. while (LFS_BLOCK_COUNT - lfs_fs_size(&lfs) > 16) {
  16. lfs_file_write(&lfs, &file, buffer, 512) => 512;
  17. }
  18. lfs_file_close(&lfs, &file) => 0;
  19. // make a child dir to use in bounded space
  20. lfs_mkdir(&lfs, "child") => 0;
  21. lfs_unmount(&lfs) => 0;
  22. TEST
  23. echo "--- Outdated head test ---"
  24. scripts/test.py << TEST
  25. lfs_mount(&lfs, &cfg) => 0;
  26. for (int j = 0; j < $ITERATIONS; j++) {
  27. for (int i = 0; i < $COUNT; i++) {
  28. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  29. lfs_file_open(&lfs, &file, path, LFS_O_CREAT | LFS_O_WRONLY) => 0;
  30. lfs_file_close(&lfs, &file) => 0;
  31. }
  32. lfs_dir_open(&lfs, &dir, "child") => 0;
  33. lfs_dir_read(&lfs, &dir, &info) => 1;
  34. lfs_dir_read(&lfs, &dir, &info) => 1;
  35. for (int i = 0; i < $COUNT; i++) {
  36. sprintf(path, "test%03d_loooooooooooooooooong_name", i);
  37. lfs_dir_read(&lfs, &dir, &info) => 1;
  38. strcmp(info.name, path) => 0;
  39. info.size => 0;
  40. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  41. lfs_file_open(&lfs, &file, path, LFS_O_WRONLY) => 0;
  42. lfs_file_write(&lfs, &file, "hi", 2) => 2;
  43. lfs_file_close(&lfs, &file) => 0;
  44. }
  45. lfs_dir_read(&lfs, &dir, &info) => 0;
  46. lfs_dir_rewind(&lfs, &dir) => 0;
  47. lfs_dir_read(&lfs, &dir, &info) => 1;
  48. lfs_dir_read(&lfs, &dir, &info) => 1;
  49. for (int i = 0; i < $COUNT; i++) {
  50. sprintf(path, "test%03d_loooooooooooooooooong_name", i);
  51. lfs_dir_read(&lfs, &dir, &info) => 1;
  52. strcmp(info.name, path) => 0;
  53. info.size => 2;
  54. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  55. lfs_file_open(&lfs, &file, path, LFS_O_WRONLY) => 0;
  56. lfs_file_write(&lfs, &file, "hi", 2) => 2;
  57. lfs_file_close(&lfs, &file) => 0;
  58. }
  59. lfs_dir_read(&lfs, &dir, &info) => 0;
  60. lfs_dir_rewind(&lfs, &dir) => 0;
  61. lfs_dir_read(&lfs, &dir, &info) => 1;
  62. lfs_dir_read(&lfs, &dir, &info) => 1;
  63. for (int i = 0; i < $COUNT; i++) {
  64. sprintf(path, "test%03d_loooooooooooooooooong_name", i);
  65. lfs_dir_read(&lfs, &dir, &info) => 1;
  66. strcmp(info.name, path) => 0;
  67. info.size => 2;
  68. }
  69. lfs_dir_read(&lfs, &dir, &info) => 0;
  70. lfs_dir_close(&lfs, &dir) => 0;
  71. for (int i = 0; i < $COUNT; i++) {
  72. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  73. lfs_remove(&lfs, path) => 0;
  74. }
  75. }
  76. lfs_unmount(&lfs) => 0;
  77. TEST
  78. scripts/results.py