test_bugreports.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * test_bugreports.c
  3. *
  4. * Created on: Mar 8, 2015
  5. * Author: petera
  6. */
  7. #include "testrunner.h"
  8. #include "test_spiffs.h"
  9. #include "spiffs_nucleus.h"
  10. #include "spiffs.h"
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <fcntl.h>
  14. #include <dirent.h>
  15. #include <unistd.h>
  16. SUITE(bug_tests)
  17. void setup() {
  18. _setup_test_only();
  19. }
  20. void teardown() {
  21. _teardown();
  22. }
  23. TEST(nodemcu_full_fs_1) {
  24. fs_reset_specific(0, 4096*20, 4096, 4096, 256);
  25. int res;
  26. spiffs_file fd;
  27. printf(" fill up system by writing one byte a lot\n");
  28. fd = SPIFFS_open(FS, "test1.txt", SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0);
  29. TEST_CHECK(fd > 0);
  30. int i;
  31. spiffs_stat s;
  32. res = SPIFFS_OK;
  33. for (i = 0; i < 100*1000; i++) {
  34. u8_t buf = 'x';
  35. res = SPIFFS_write(FS, fd, &buf, 1);
  36. }
  37. int errno = SPIFFS_errno(FS);
  38. int res2 = SPIFFS_fstat(FS, fd, &s);
  39. TEST_CHECK(res2 == SPIFFS_OK);
  40. printf(" >>> file %s size: %i\n", s.name, s.size);
  41. TEST_CHECK(errno == SPIFFS_ERR_FULL);
  42. SPIFFS_close(FS, fd);
  43. printf(" remove big file\n");
  44. res = SPIFFS_remove(FS, "test1.txt");
  45. printf("res:%i errno:%i\n",res, SPIFFS_errno(FS));
  46. TEST_CHECK(res == SPIFFS_OK);
  47. res2 = SPIFFS_fstat(FS, fd, &s);
  48. TEST_CHECK(res2 == -1);
  49. TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_ERR_FILE_CLOSED);
  50. res2 = SPIFFS_stat(FS, "test1.txt", &s);
  51. TEST_CHECK(res2 == -1);
  52. TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_ERR_NOT_FOUND);
  53. printf(" create small file\n");
  54. fd = SPIFFS_open(FS, "test2.txt", SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0);
  55. TEST_CHECK(fd > 0);
  56. res = SPIFFS_OK;
  57. for (i = 0; res >= 0 && i < 1000; i++) {
  58. u8_t buf = 'x';
  59. res = SPIFFS_write(FS, fd, &buf, 1);
  60. }
  61. TEST_CHECK(res >= SPIFFS_OK);
  62. res2 = SPIFFS_fstat(FS, fd, &s);
  63. TEST_CHECK(res2 == SPIFFS_OK);
  64. printf(" >>> file %s size: %i\n", s.name, s.size);
  65. TEST_CHECK(s.size == 1000);
  66. SPIFFS_close(FS, fd);
  67. return TEST_RES_OK;
  68. } TEST_END(nodemcu_full_fs_1)
  69. TEST(nodemcu_full_fs_2) {
  70. fs_reset_specific(0, 4096*22, 4096, 4096, 256);
  71. int res;
  72. spiffs_file fd;
  73. printf(" fill up system by writing one byte a lot\n");
  74. fd = SPIFFS_open(FS, "test1.txt", SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0);
  75. TEST_CHECK(fd > 0);
  76. int i;
  77. spiffs_stat s;
  78. res = SPIFFS_OK;
  79. for (i = 0; i < 100*1000; i++) {
  80. u8_t buf = 'x';
  81. res = SPIFFS_write(FS, fd, &buf, 1);
  82. }
  83. int errno = SPIFFS_errno(FS);
  84. int res2 = SPIFFS_fstat(FS, fd, &s);
  85. TEST_CHECK(res2 == SPIFFS_OK);
  86. printf(" >>> file %s size: %i\n", s.name, s.size);
  87. TEST_CHECK(errno == SPIFFS_ERR_FULL);
  88. SPIFFS_close(FS, fd);
  89. res2 = SPIFFS_stat(FS, "test1.txt", &s);
  90. TEST_CHECK(res2 == SPIFFS_OK);
  91. SPIFFS_clearerr(FS);
  92. printf(" create small file\n");
  93. fd = SPIFFS_open(FS, "test2.txt", SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0);
  94. TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_OK);
  95. TEST_CHECK(fd > 0);
  96. for (i = 0; i < 1000; i++) {
  97. u8_t buf = 'x';
  98. res = SPIFFS_write(FS, fd, &buf, 1);
  99. }
  100. TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_ERR_FULL);
  101. res2 = SPIFFS_fstat(FS, fd, &s);
  102. TEST_CHECK(res2 == SPIFFS_OK);
  103. printf(" >>> file %s size: %i\n", s.name, s.size);
  104. TEST_CHECK(s.size == 0);
  105. SPIFFS_clearerr(FS);
  106. printf(" remove files\n");
  107. res = SPIFFS_remove(FS, "test1.txt");
  108. TEST_CHECK(res == SPIFFS_OK);
  109. res = SPIFFS_remove(FS, "test2.txt");
  110. TEST_CHECK(res == SPIFFS_OK);
  111. printf(" create medium file\n");
  112. fd = SPIFFS_open(FS, "test3.txt", SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0);
  113. TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_OK);
  114. TEST_CHECK(fd > 0);
  115. for (i = 0; i < 20*1000; i++) {
  116. u8_t buf = 'x';
  117. res = SPIFFS_write(FS, fd, &buf, 1);
  118. }
  119. TEST_CHECK(SPIFFS_errno(FS) == SPIFFS_OK);
  120. res2 = SPIFFS_fstat(FS, fd, &s);
  121. TEST_CHECK(res2 == SPIFFS_OK);
  122. printf(" >>> file %s size: %i\n", s.name, s.size);
  123. TEST_CHECK(s.size == 20*1000);
  124. return TEST_RES_OK;
  125. } TEST_END(nodemcu_full_fs_2)
  126. SUITE_END(bug_tests)