Skip to content

Commit 558b135

Browse files
fixed TestUnified
1 parent e33eab0 commit 558b135

File tree

7 files changed

+76
-56
lines changed

7 files changed

+76
-56
lines changed

src/InternalStorage.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ int InternalStorage::begin(){
2828
this -> blockDevice = QSPIFBlockDevice::get_default_instance();
2929
this -> userData = new mbed::MBRBlockDevice(this->blockDevice, this->partitionNumber);
3030
if(this -> fs == FS_FAT){
31+
if(this -> userDataFileSystem != nullptr){
32+
delete(this -> userDataFileSystem);
33+
}
3134
this -> userDataFileSystem = new mbed::FATFileSystem(this->partitionName);
3235
} else {
36+
if(this -> userDataFileSystem != nullptr){
37+
delete(this -> userDataFileSystem);
38+
}
3339
this -> userDataFileSystem = new mbed::LittleFileSystem(this->partitionName);
3440
}
3541
int err = this -> userDataFileSystem -> mount(this -> userData);

src/InternalStorage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
#include "Arduino_UnifiedStorage.h"
77

8+
9+
10+
811
class InternalStorage : public Arduino_UnifiedStorage {
912

1013

@@ -26,6 +29,7 @@ class InternalStorage : public Arduino_UnifiedStorage {
2629
int formatFAT();
2730

2831
int formatLittleFS();
32+
2933

3034
#if defined(ARDUINO_PORTENTA_C33)
3135
BlockDevice * getBlockDevice();

src/Types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <vector>
1111

1212

13+
14+
1315
static bool copyFolder(const char* source, const char* destination) {
1416
DIR* dir = opendir(source);
1517
if (dir == nullptr) {

src/UFile.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ bool UFile::open(String filename, FileMode mode) {
5454
void UFile::close() {
5555
// Close the file
5656
if (fp != nullptr) {
57-
fflush(fp); // ?!?
5857
fclose(fp);
59-
fp = nullptr;
58+
//fp = nullptr;
6059
}
6160
}
6261

tests/TestMultipleQSPIPartitions/TestMultipleQSPIPartitions.ino

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
2-
3-
#if defined()
4-
QSPIFBlockDevice root(QSPI_SO0, QSPI_SO1, QSPI_SO2, QSPI_SO3, QSPI_SCK, QSPI_CS, QSPIF_POLARITY_MODE_1, 40000000);
5-
mbed::MBRBlockDevice wifi_data(&root, 1);
6-
mbed::MBRBlockDevice ota_data(&root, 2);
7-
mbed::MBRBlockDevice user_data(&root, 3);
1+
#include <Arduino_UnifiedStorage.h>
82

93

104
void setup(){

tests/TestUnified/TestUnified.ino

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void test(String opperation, Arduino_UnifiedStorage* sourceStorage, Arduino_Unif
2929

3030
if(mountSource && mountDest){
3131

32-
String fileName = "/test_" + String(millis()) + ".txt";
32+
String fileName = "test_" + String(millis()) + ".txt";
3333
// Create a file in the source storage
3434
UFile fileToMove = sourceStorage->getRootFolder().createFile(fileName, FileMode::WRITE);
3535
fileToMove.write(reinterpret_cast<const uint8_t*>("Test data"), 9);
@@ -38,109 +38,114 @@ void test(String opperation, Arduino_UnifiedStorage* sourceStorage, Arduino_Unif
3838
int opperationResult = -1;
3939
if (opperation == "move") {
4040
opperationResult = fileToMove.moveTo(destinationStorage->getRootFolder(), true);
41+
fileToMove.close();
42+
fileToMove.remove();
4143
} else if(opperation == "copy"){
4244
opperationResult = fileToMove.copyTo(destinationStorage->getRootFolder(), true);
45+
fileToMove.close();
46+
fileToMove.remove();
4347
}
4448

4549
if (opperationResult) {
4650
Serial.println(opperation + " from " + String(storageTypeA) + " to " + String(storageTypeB) + " successful");
47-
48-
// Delete the moved file from the destination storage
49-
UFile movedFile;
50-
movedFile.open(destinationStorage->getRootFolder().getPathString() + fileName, FileMode::READ);
51-
if (movedFile.remove()) {
52-
Serial.println("File deletion from " + String(storageTypeB) + " successful");
53-
} else {
54-
Serial.println("File deletion from " + String(storageTypeB) + " failed");
55-
Serial.println(getErrno());
56-
}
57-
} else {
58-
Serial.println(opperation + " from " + String(storageTypeA) + " to " + String(storageTypeB) + " failed");
59-
Serial.println(getErrno());
6051
}
6152

53+
6254
Serial.println();
6355
int unmountSource = sourceStorage->unmount();
64-
Serial.println("Unmount " + String(storageTypeA) + ": " + unmountSource);
65-
6656
int unmountDest = destinationStorage->unmount();
67-
Serial.println("Unmount " + String(storageTypeB) + ": " + unmountDest);
6857

6958
delay(1000);
59+
7060
} else {
7161
Serial.println("cannot execute test, fs not mounted");
7262
}
7363
}
7464

7565

66+
7667
void sd_and_usb(){
77-
Serial.println("Formatting both USB and SD to FAT");
78-
usb->formatFAT();
79-
sd->formatFAT();
68+
Serial.println("TESTING SD AND USB \n\n\n\n");
69+
70+
Serial.println("-----------------------------");
71+
Serial.println("Formatting USB to FAT: " + String(usb->formatFAT()));
72+
Serial.println("Formatting SD to FAT: " + String(sd->formatFAT()));
73+
Serial.println("-----------------------------");
74+
8075

8176
test("move", usb, sd, "USB FAT", "SD FAT");
8277
test("copy", usb, sd, "USB FAT", "SD FAT");
8378

8479
test("move", sd, usb, "SD FAT", "USB FAT");
8580
test("copy", sd, usb, "SD FAT", "USB FAT");
8681

87-
Serial.println("Formatting USB to LittleFS");
88-
usb->formatLittleFS();
82+
Serial.println("-----------------------------");
83+
Serial.println("Formatting USB to LittleFS:" + String(usb->formatLittleFS()));
84+
Serial.println("-----------------------------");
85+
8986
test("move", usb, sd, "USB LittleFS", "SD FAT ");
9087
test("copy", usb, sd, "USB LittleFS", "SD FAT ");
9188

9289
test("move", sd, usb, "SD FAT", "USB LittleFS");
9390
test("copy", sd, usb, "SD FAT", "USB LittleFS");
9491

95-
Serial.println("Formatting SD to LittleFS");
96-
sd->formatLittleFS();
92+
Serial.println("-----------------------------");
93+
Serial.println("Formatting SD to LittleFS: "+ String(sd->formatLittleFS()));
94+
Serial.println("-----------------------------");
95+
9796
test("move", sd, usb, "SD LittleFS", "USB LittleFS");
9897
test("copy", sd, usb, "SD LittleFS", "USB LittleFS");
9998

10099
test("move", usb, sd, "USB LittleFS", "SD LittleFS");
101100
test("copy", usb, sd, "USB LittleFS", "SD LittleFS");
102101

103-
Serial.println("Formatting USB to FAT");
104-
usb->formatFAT();
102+
Serial.println("-----------------------------");
103+
Serial.println("Formatting USB to FAT: " + String(usb->formatFAT()));
104+
Serial.println("-----------------------------");
105+
105106
test("move", usb, sd, "USB FAT", "SD LittleFS");
106107
test("copy", usb, sd, "USB FAT", "SD LittleFS");
107108

108109
test("move", sd, usb, "SD LittleFS", "USB FAT");
109110
test("copy", sd, usb, "SD LittleFS", "USB FAT");
110-
111-
112-
113111
}
114112

115113
void qspi_and_sd() {
116-
Serial.println("Formatting both QSPI and SD to FAT");
117-
qspi->formatFAT();
118-
sd->formatFAT();
114+
Serial.println("TESTING QSPI AND SD \n\n\n\n");
115+
Serial.println("-----------------------------");
116+
Serial.println("Formatting QSPI to FAT: " + String(qspi->formatFAT()));
117+
Serial.println("Formatting SD to FAT: " + String(sd->formatFAT()));
118+
Serial.println("-----------------------------");
119119

120120
test("move", qspi, sd, "QSPI FAT", "SD FAT");
121121
test("copy", qspi, sd, "QSPI FAT", "SD FAT");
122122

123123
test("move", sd, qspi, "SD FAT", "QSPI FAT");
124124
test("copy", sd, qspi, "SD FAT", "QSPI FAT");
125125

126-
Serial.println("Formatting QSPI to LittleFS");
127-
qspi->formatLittleFS();
126+
Serial.println("-----------------------------");
127+
Serial.println("Formatting QSPI to LittleFS:" + String(qspi->formatLittleFS()));
128+
Serial.println("-----------------------------");
129+
128130
test("move", qspi, sd, "QSPI LittleFS", "SD FAT");
129131
test("copy", qspi, sd, "QSPI LittleFS", "SD FAT");
130132

131133
test("move", sd, qspi, "SD FAT", "QSPI LittleFS");
132134
test("copy", sd, qspi, "SD FAT", "QSPI LittleFS");
133135

134-
Serial.println("Formatting SD to LittleFS");
135-
sd->formatLittleFS();
136+
Serial.println("-----------------------------");
137+
Serial.println("Formatting SD to LittleFS: "+ String(sd->formatLittleFS()));
138+
Serial.println("-----------------------------");
139+
136140
test("move", qspi, sd, "QSPI LittleFS", "SD LittleFS");
137141
test("copy", qspi, sd, "QSPI LittleFS", "SD LittleFS");
138142

139143
test("move", sd, qspi, "SD LittleFS", "QSPI LittleFS");
140144
test("copy", sd, qspi, "SD LittleFS", "QSPI LittleFS");
141145

142-
Serial.println("Formatting QSPI to FAT");
143-
qspi->formatFAT();
146+
Serial.println("-----------------------------");
147+
Serial.println("Formatting QSPI to FAT: " + String(qspi->formatFAT()));
148+
Serial.println("-----------------------------");
144149

145150
test("move", sd, qspi, "SD LittleFS", "QSPI FAT");
146151
test("copy", sd, qspi, "SD LittleFS", "QSPI FAT");
@@ -151,26 +156,32 @@ void qspi_and_sd() {
151156

152157

153158
void qspi_and_usb() {
154-
Serial.println("Formatting both QSPI and USB to FAT");
155-
qspi->formatFAT();
156-
usb->formatFAT();
159+
160+
Serial.println("TESTING QSPI AND USB \n\n\n\n");
161+
Serial.println("-----------------------------");
162+
Serial.println("Formatting QSPI to FAT: " + String(qspi->formatFAT()));
163+
Serial.println("Formatting USB to FAT: " + String(usb->formatFAT()));
164+
Serial.println("-----------------------------");
157165

158166
test("move", qspi, usb, "QSPI FAT", "USB FAT");
159167
test("copy", qspi, usb, "QSPI FAT", "USB FAT");
160168

161169
test("move", usb, qspi, "USB FAT", "QSPI FAT");
162170
test("copy", usb, qspi, "USB FAT", "QSPI FAT");
163171

164-
Serial.println("Formatting QSPI to LittleFS");
165-
qspi->formatLittleFS();
172+
Serial.println("-----------------------------");
173+
Serial.println("Formatting QSPI to LittleFS:" + String(qspi->formatLittleFS()));
174+
Serial.println("-----------------------------");
175+
166176
test("move", qspi, usb, "QSPI LittleFS", "USB FAT");
167177
test("copy", qspi, usb, "QSPI LittleFS", "USB FAT");
168178

169179
test("move", usb, qspi, "USB FAT", "QSPI LittleFS");
170180
test("copy", usb, qspi, "USB FAT", "QSPI LittleFS");
171181

172-
Serial.println("Formatting USB to LittleFS");
173-
usb->formatLittleFS();
182+
Serial.println("-----------------------------");
183+
Serial.println("Formatting USB to LittleFS: "+ String(usb->formatLittleFS()));
184+
Serial.println("-----------------------------");
174185

175186
test("move", qspi, usb, "QSPI LittleFS", "USB LittleFS");
176187
test("copy", qspi, usb, "QSPI LittleFS", "USB LittleFS");
@@ -179,7 +190,10 @@ void qspi_and_usb() {
179190
test("move", usb, qspi, "USB LittleFS", "QSPI LittleFS");
180191
test("copy", usb, qspi, "USB LittleFS", "QSPI LittleFS");
181192

182-
qspi->formatFAT();
193+
Serial.println("-----------------------------");
194+
Serial.println("Formatting QSPI to FAT:" + String(qspi->formatFAT()));
195+
Serial.println("-----------------------------");
196+
183197
test("move", usb, qspi, "USB LittleFS", "QSPI FAT");
184198
test("copy", usb, qspi, "USB LittleFS", "QSPI FAT");
185199

@@ -195,8 +209,9 @@ void setup(){
195209

196210
#if defined(HAS_USB) && defined(HAS_SD) && defined(HAS_QSPI)
197211
qspi_and_usb();
198-
qspi_and_sd();
199212
sd_and_usb();
213+
qspi_and_sd();
214+
Serial.println("Tests finished");
200215
#elif defined(HAS_USB) && defined(HAS_SD)
201216
sd_and_usb();
202217
#elif defined(HAS_USB) && defined(HAS_QSPI)

tests/test_qspi_usb_sd/test_qspi_usb_sd.ino

Whitespace-only changes.

0 commit comments

Comments
 (0)