MCPcopy Create free account
hub / github.com/SmingHub/Sming / cycleFlash

Method cycleFlash

tests/HostTests/modules/Spiffs.cpp:35–73  ·  view source on GitHub ↗

* Repeatedly write to a SPIFFS file until sector #0 gets erased. * At that point, re-mount the filesystem then check the test file is still present. * This confirms that a re-format was not done. */

Source from the content-addressed store, hash-verified

33 * This confirms that a re-format was not done.
34 */
35 void cycleFlash()
36 {
37 fileFreeFileSystem();
38 if(!spiffs_mount()) {
39 debug_e("SPIFFS mount failed");
40 return;
41 }
42
43 DEFINE_FSTR_LOCAL(testFile, "testfile");
44 DEFINE_FSTR_LOCAL(testContent, "Some test content to write to a file");
45
46 auto part = *Storage::findPartition(Storage::Partition::SubType::Data::spiffs);
47 REQUIRE(part.name() == "spiffs0");
48
49 // Write to filesystem until sector #0 gets erased
50 unsigned writeCount = 0;
51 uint32_t word0 = 0;
52 do {
53 if(fileSetContent(testFile, testContent) != int(testContent.length())) {
54 debug_e("fileSetContent() failed");
55 TEST_ASSERT(false);
56 break;
57 }
58 ++writeCount;
59 if(!part.read(0, word0)) {
60 debug_e("part.read() failed");
61 TEST_ASSERT(false);
62 break;
63 }
64 } while(word0 != 0xFFFFFFFF);
65
66 debug_i("Sector #0 erased after %u writes", writeCount);
67
68 // Re-mount file system and confirm test file is still present
69 fileFreeFileSystem();
70 spiffs_mount();
71 auto content = fileGetContent(testFile);
72 REQUIRE(testContent == content);
73 }
74
75#ifdef ARCH_HOST
76 /*

Callers

nothing calls this directly

Calls 8

fileFreeFileSystemFunction · 0.85
spiffs_mountFunction · 0.85
fileSetContentFunction · 0.85
fileGetContentFunction · 0.85
findPartitionFunction · 0.50
nameMethod · 0.45
lengthMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected