test_relocations.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 "--- Dangling split dir 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. }
  40. lfs_dir_read(&lfs, &dir, &info) => 0;
  41. lfs_dir_close(&lfs, &dir) => 0;
  42. if (j == $ITERATIONS-1) {
  43. break;
  44. }
  45. for (int i = 0; i < $COUNT; i++) {
  46. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  47. lfs_remove(&lfs, path) => 0;
  48. }
  49. }
  50. lfs_unmount(&lfs) => 0;
  51. TEST
  52. scripts/test.py << TEST
  53. lfs_mount(&lfs, &cfg) => 0;
  54. lfs_dir_open(&lfs, &dir, "child") => 0;
  55. lfs_dir_read(&lfs, &dir, &info) => 1;
  56. lfs_dir_read(&lfs, &dir, &info) => 1;
  57. for (int i = 0; i < $COUNT; i++) {
  58. sprintf(path, "test%03d_loooooooooooooooooong_name", i);
  59. lfs_dir_read(&lfs, &dir, &info) => 1;
  60. strcmp(info.name, path) => 0;
  61. }
  62. lfs_dir_read(&lfs, &dir, &info) => 0;
  63. lfs_dir_close(&lfs, &dir) => 0;
  64. for (int i = 0; i < $COUNT; i++) {
  65. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  66. lfs_remove(&lfs, path) => 0;
  67. }
  68. lfs_unmount(&lfs) => 0;
  69. TEST
  70. echo "--- Outdated head test ---"
  71. scripts/test.py << TEST
  72. lfs_mount(&lfs, &cfg) => 0;
  73. for (int j = 0; j < $ITERATIONS; j++) {
  74. for (int i = 0; i < $COUNT; i++) {
  75. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  76. lfs_file_open(&lfs, &file, path, LFS_O_CREAT | LFS_O_WRONLY) => 0;
  77. lfs_file_close(&lfs, &file) => 0;
  78. }
  79. lfs_dir_open(&lfs, &dir, "child") => 0;
  80. lfs_dir_read(&lfs, &dir, &info) => 1;
  81. lfs_dir_read(&lfs, &dir, &info) => 1;
  82. for (int i = 0; i < $COUNT; i++) {
  83. sprintf(path, "test%03d_loooooooooooooooooong_name", i);
  84. lfs_dir_read(&lfs, &dir, &info) => 1;
  85. strcmp(info.name, path) => 0;
  86. info.size => 0;
  87. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  88. lfs_file_open(&lfs, &file, path, LFS_O_WRONLY) => 0;
  89. lfs_file_write(&lfs, &file, "hi", 2) => 2;
  90. lfs_file_close(&lfs, &file) => 0;
  91. }
  92. lfs_dir_read(&lfs, &dir, &info) => 0;
  93. lfs_dir_rewind(&lfs, &dir) => 0;
  94. lfs_dir_read(&lfs, &dir, &info) => 1;
  95. lfs_dir_read(&lfs, &dir, &info) => 1;
  96. for (int i = 0; i < $COUNT; i++) {
  97. sprintf(path, "test%03d_loooooooooooooooooong_name", i);
  98. lfs_dir_read(&lfs, &dir, &info) => 1;
  99. strcmp(info.name, path) => 0;
  100. info.size => 2;
  101. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  102. lfs_file_open(&lfs, &file, path, LFS_O_WRONLY) => 0;
  103. lfs_file_write(&lfs, &file, "hi", 2) => 2;
  104. lfs_file_close(&lfs, &file) => 0;
  105. }
  106. lfs_dir_read(&lfs, &dir, &info) => 0;
  107. lfs_dir_rewind(&lfs, &dir) => 0;
  108. lfs_dir_read(&lfs, &dir, &info) => 1;
  109. lfs_dir_read(&lfs, &dir, &info) => 1;
  110. for (int i = 0; i < $COUNT; i++) {
  111. sprintf(path, "test%03d_loooooooooooooooooong_name", i);
  112. lfs_dir_read(&lfs, &dir, &info) => 1;
  113. strcmp(info.name, path) => 0;
  114. info.size => 2;
  115. }
  116. lfs_dir_read(&lfs, &dir, &info) => 0;
  117. lfs_dir_close(&lfs, &dir) => 0;
  118. for (int i = 0; i < $COUNT; i++) {
  119. sprintf(path, "child/test%03d_loooooooooooooooooong_name", i);
  120. lfs_remove(&lfs, path) => 0;
  121. }
  122. }
  123. lfs_unmount(&lfs) => 0;
  124. TEST
  125. scripts/results.py