Skip to content

Commit 7aa7c3f

Browse files
lonerzzzme-no-dev
authored andcommitted
Add additional test detail (#1099)
Update test to show more detail to help for checking for poor/inconsistent FLASH operation.
1 parent 0f9595e commit 7aa7c3f

File tree

1 file changed

+57
-43
lines changed

1 file changed

+57
-43
lines changed

libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino

+57-43
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
#include "SPIFFS.h"
33

44
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
5-
Serial.printf("Listing directory: %s\n", dirname);
5+
Serial.printf("Listing directory: %s\r\n", dirname);
66

77
File root = fs.open(dirname);
88
if(!root){
9-
Serial.println("Failed to open directory");
9+
Serial.println("- failed to open directory");
1010
return;
1111
}
1212
if(!root.isDirectory()){
13-
Serial.println("Not a directory");
13+
Serial.println(" - not a directory");
1414
return;
1515
}
1616

@@ -25,116 +25,128 @@ void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
2525
} else {
2626
Serial.print(" FILE: ");
2727
Serial.print(file.name());
28-
Serial.print(" SIZE: ");
28+
Serial.print("\tSIZE: ");
2929
Serial.println(file.size());
3030
}
3131
file = root.openNextFile();
3232
}
3333
}
3434

3535
void readFile(fs::FS &fs, const char * path){
36-
Serial.printf("Reading file: %s\n", path);
36+
Serial.printf("Reading file: %s\r\n", path);
3737

3838
File file = fs.open(path);
3939
if(!file || file.isDirectory()){
40-
Serial.println("Failed to open file for reading");
40+
Serial.println("- failed to open file for reading");
4141
return;
4242
}
4343

44-
Serial.print("Read from file: ");
44+
Serial.println("- read from file:");
4545
while(file.available()){
4646
Serial.write(file.read());
4747
}
4848
}
4949

5050
void writeFile(fs::FS &fs, const char * path, const char * message){
51-
Serial.printf("Writing file: %s\n", path);
51+
Serial.printf("Writing file: %s\r\n", path);
5252

5353
File file = fs.open(path, FILE_WRITE);
5454
if(!file){
55-
Serial.println("Failed to open file for writing");
55+
Serial.println("- failed to open file for writing");
5656
return;
5757
}
5858
if(file.print(message)){
59-
Serial.println("File written");
59+
Serial.println("- file written");
6060
} else {
61-
Serial.println("Write failed");
61+
Serial.println("- frite failed");
6262
}
6363
}
6464

6565
void appendFile(fs::FS &fs, const char * path, const char * message){
66-
Serial.printf("Appending to file: %s\n", path);
66+
Serial.printf("Appending to file: %s\r\n", path);
6767

6868
File file = fs.open(path, FILE_APPEND);
6969
if(!file){
70-
Serial.println("Failed to open file for appending");
70+
Serial.println("- failed to open file for appending");
7171
return;
7272
}
7373
if(file.print(message)){
74-
Serial.println("Message appended");
74+
Serial.println("- message appended");
7575
} else {
76-
Serial.println("Append failed");
76+
Serial.println("- append failed");
7777
}
7878
}
7979

8080
void renameFile(fs::FS &fs, const char * path1, const char * path2){
81-
Serial.printf("Renaming file %s to %s\n", path1, path2);
81+
Serial.printf("Renaming file %s to %s\r\n", path1, path2);
8282
if (fs.rename(path1, path2)) {
83-
Serial.println("File renamed");
83+
Serial.println("- file renamed");
8484
} else {
85-
Serial.println("Rename failed");
85+
Serial.println("- rename failed");
8686
}
8787
}
8888

8989
void deleteFile(fs::FS &fs, const char * path){
90-
Serial.printf("Deleting file: %s\n", path);
90+
Serial.printf("Deleting file: %s\r\n", path);
9191
if(fs.remove(path)){
92-
Serial.println("File deleted");
92+
Serial.println("- file deleted");
9393
} else {
94-
Serial.println("Delete failed");
94+
Serial.println("- delete failed");
9595
}
9696
}
9797

9898
void testFileIO(fs::FS &fs, const char * path){
99-
File file = fs.open(path);
99+
Serial.printf("Testing file I/O with %s\r\n", path);
100+
100101
static uint8_t buf[512];
101102
size_t len = 0;
103+
File file = fs.open(path, FILE_WRITE);
104+
if(!file){
105+
Serial.println("- failed to open file for writing");
106+
return;
107+
}
108+
109+
size_t i;
110+
Serial.print("- writing" );
102111
uint32_t start = millis();
103-
uint32_t end = start;
112+
for(i=0; i<2048; i++){
113+
if ((i & 0x001F) == 0x001F){
114+
Serial.print(".");
115+
}
116+
file.write(buf, 512);
117+
}
118+
Serial.println("");
119+
uint32_t end = millis() - start;
120+
Serial.printf(" - %u bytes written in %u ms\r\n", 2048 * 512, end);
121+
file.close();
122+
123+
file = fs.open(path);
124+
start = millis();
125+
end = start;
126+
i = 0;
104127
if(file && !file.isDirectory()){
105128
len = file.size();
106129
size_t flen = len;
107130
start = millis();
131+
Serial.print("- reading" );
108132
while(len){
109133
size_t toRead = len;
110134
if(toRead > 512){
111135
toRead = 512;
112136
}
113137
file.read(buf, toRead);
138+
if ((i++ & 0x001F) == 0x001F){
139+
Serial.print(".");
140+
}
114141
len -= toRead;
115142
}
143+
Serial.println("");
116144
end = millis() - start;
117-
Serial.printf("%u bytes read for %u ms\n", flen, end);
145+
Serial.printf("- %u bytes read in %u ms\r\n", flen, end);
118146
file.close();
119147
} else {
120-
Serial.println("Failed to open file for reading");
121-
}
122-
123-
124-
file = fs.open(path, FILE_WRITE);
125-
if(!file){
126-
Serial.println("Failed to open file for writing");
127-
return;
148+
Serial.println("- failed to open file for reading");
128149
}
129-
130-
size_t i;
131-
start = millis();
132-
for(i=0; i<2048; i++){
133-
file.write(buf, 512);
134-
}
135-
end = millis() - start;
136-
Serial.printf("%u bytes written for %u ms\n", 2048 * 512, end);
137-
file.close();
138150
}
139151

140152
void setup(){
@@ -146,12 +158,14 @@ void setup(){
146158

147159
listDir(SPIFFS, "/", 0);
148160
writeFile(SPIFFS, "/hello.txt", "Hello ");
149-
appendFile(SPIFFS, "/hello.txt", "World!\n");
161+
appendFile(SPIFFS, "/hello.txt", "World!\r\n");
150162
readFile(SPIFFS, "/hello.txt");
151-
deleteFile(SPIFFS, "/foo.txt");
152163
renameFile(SPIFFS, "/hello.txt", "/foo.txt");
153164
readFile(SPIFFS, "/foo.txt");
165+
deleteFile(SPIFFS, "/foo.txt");
154166
testFileIO(SPIFFS, "/test.txt");
167+
deleteFile(SPIFFS, "/test.txt");
168+
Serial.println( "Test complete" );
155169
}
156170

157171
void loop(){

0 commit comments

Comments
 (0)