mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
* Use newlib libc library This change adds libcmin.a, which is created from newlib libc by selectively removing some of the object files (mostly related to heap management). The list of files is available in tools/sdk/lib/make_libcmin.sh. Files which are not needed are commented out. This change adds support for various functions which were missing, like sscanf, strftime, etc. * Fix some of the time functions * Redirect stdout to serial * Implement __putc_r * Switch to custom newlib build Built from https://github.com/igrr/newlib-xtensa using: ./configure --with-newlib --enable-multilib --disable-newlib-io-c99-formats --enable-newlib-supplied-syscalls --enable-target-optspace --program-transform-name="s&^&xtensa-lx106-elf-&" --disable-option-checking --with-target-subdir=xtensa-lx106-elf --target=xtensa-lx106-elf --enable-newlib-nano-formatted-io --enable-newlib-reent-small --prefix=path-to-arduino-core/tools/sdk/libc CROSS_CFLAGS="-DMALLOC_PROVIDED -DSIGNAL_PROVIDED -DABORT_PROVIDED" make make install * Update tests
144 lines
2.8 KiB
C++
144 lines
2.8 KiB
C++
#include <ESP8266WiFi.h>
|
|
#include "FS.h"
|
|
#include <BSTest.h>
|
|
|
|
BS_ENV_DECLARE();
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
BS_RUN(Serial);
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("read-write test","[fs]")
|
|
{
|
|
REQUIRE(SPIFFS.begin());
|
|
|
|
String text = "write test";
|
|
{
|
|
File out = SPIFFS.open("/tmp.txt", "w");
|
|
REQUIRE(out);
|
|
out.print(text);
|
|
}
|
|
|
|
{
|
|
File in = SPIFFS.open("/tmp.txt", "r");
|
|
REQUIRE(in);
|
|
CHECK(in.size() == text.length());
|
|
in.setTimeout(0);
|
|
String result = in.readString();
|
|
CHECK(result == text);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("A bunch of files show up in openDir, and can be removed", "[fs]")
|
|
{
|
|
REQUIRE(SPIFFS.begin());
|
|
const int n = 10;
|
|
int found[n] = {0};
|
|
|
|
{
|
|
Dir root = SPIFFS.openDir("");
|
|
while (root.next()) {
|
|
CHECK(SPIFFS.remove(root.fileName()));
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
String name = "/seq_";
|
|
name += i;
|
|
name += ".txt";
|
|
|
|
File out = SPIFFS.open(name, "w");
|
|
REQUIRE(out);
|
|
|
|
out.println(i);
|
|
}
|
|
|
|
{
|
|
Dir root = SPIFFS.openDir("/");
|
|
while (root.next()) {
|
|
String fileName = root.fileName();
|
|
CHECK(fileName.indexOf("/seq_") == 0);
|
|
int i = fileName.substring(5).toInt();
|
|
CHECK(i >= 0 && i < n);
|
|
found[i]++;
|
|
}
|
|
|
|
for (auto f : found) {
|
|
CHECK(f == 1);
|
|
}
|
|
}
|
|
|
|
{
|
|
Dir root = SPIFFS.openDir("/");
|
|
while (root.next()) {
|
|
String fileName = root.fileName();
|
|
CHECK(SPIFFS.remove(fileName));
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_CASE("files can be renamed", "[fs]")
|
|
{
|
|
REQUIRE(SPIFFS.begin());
|
|
{
|
|
File tmp = SPIFFS.open("/tmp1.txt", "w");
|
|
tmp.println("rename test");
|
|
}
|
|
|
|
{
|
|
CHECK(SPIFFS.rename("/tmp1.txt", "/tmp2.txt"));
|
|
|
|
File tmp2 = SPIFFS.open("/tmp2.txt", "r");
|
|
CHECK(tmp2);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("FS::info works","[fs]")
|
|
{
|
|
REQUIRE(SPIFFS.begin());
|
|
FSInfo info;
|
|
CHECK(SPIFFS.info(info));
|
|
|
|
Serial.printf("Total: %u\nUsed: %u\nBlock: %u\nPage: %u\nMax open files: %u\nMax path len: %u\n",
|
|
info.totalBytes,
|
|
info.usedBytes,
|
|
info.blockSize,
|
|
info.pageSize,
|
|
info.maxOpenFiles,
|
|
info.maxPathLength
|
|
);
|
|
}
|
|
|
|
TEST_CASE("FS is empty after format","[fs]")
|
|
{
|
|
REQUIRE(SPIFFS.begin());
|
|
REQUIRE(SPIFFS.format());
|
|
|
|
Dir root = SPIFFS.openDir("/");
|
|
int count = 0;
|
|
while (root.next()) {
|
|
++count;
|
|
}
|
|
CHECK(count == 0);
|
|
}
|
|
|
|
TEST_CASE("Can reopen empty file","[fs]")
|
|
{
|
|
REQUIRE(SPIFFS.begin());
|
|
{
|
|
File tmp = SPIFFS.open("/tmp.txt", "w");
|
|
}
|
|
{
|
|
File tmp = SPIFFS.open("/tmp.txt", "w");
|
|
CHECK(tmp);
|
|
}
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
}
|