-
Notifications
You must be signed in to change notification settings - Fork 13.3k
/
Copy pathtest_fs.cpp
170 lines (151 loc) · 4.97 KB
/
test_fs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
test_fs.cpp - host side file system tests
Copyright © 2016 Ivan Grokhotkov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
*/
#include <catch.hpp>
#include <map>
#include <FS.h>
#include "../common/spiffs_mock.h"
#include "../common/littlefs_mock.h"
#include "../common/sdfs_mock.h"
#include <spiffs/spiffs.h>
#include <LittleFS.h>
#include "../../../libraries/SDFS/src/SDFS.h"
#include "../../../libraries/SD/src/SD.h"
namespace spiffs_test
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#define FSTYPE SPIFFS
#define TESTPRE "SPIFFS - "
#define TESTPAT "[fs]"
#define TOOLONGFILENAME "/2345678901234567890123456789012"
#define FS_MOCK_DECLARE SPIFFS_MOCK_DECLARE
#define FS_MOCK_RESET SPIFFS_MOCK_RESET
#undef FS_HAS_DIRS
#include "test_fs.inc"
#undef FSTYPE
#undef TESTPRE
#undef TESTPAT
#undef TOOLONGFILENAME
#undef FS_MOCK_DECLARE
#undef FS_MOCK_RESET
TEST_CASE("SPIFFS checks the config object passed in", "[fs]")
{
SPIFFS_MOCK_DECLARE(64, 8, 512, "");
FSConfig f;
SPIFFSConfig s;
SDFSConfig d;
LittleFSConfig l;
REQUIRE_FALSE(SPIFFS.setConfig(f));
REQUIRE(SPIFFS.setConfig(s));
REQUIRE_FALSE(SPIFFS.setConfig(d));
REQUIRE_FALSE(LittleFS.setConfig(l));
}
#pragma GCC diagnostic pop
}; // namespace spiffs_test
namespace littlefs_test
{
#define FSTYPE LittleFS
#define TESTPRE "LittleFS - "
#define TESTPAT "[lfs]"
// LittleFS routines strip leading slashes before doing anything, so up to 31 char names are
// allowable
#define TOOLONGFILENAME "/12345678901234567890123456789012"
#define FS_MOCK_DECLARE LITTLEFS_MOCK_DECLARE
#define FS_MOCK_RESET LITTLEFS_MOCK_RESET
#define FS_HAS_DIRS
#include "test_fs.inc"
#undef FSTYPE
#undef TESTPRE
#undef TESTPAT
#undef TOOLONGFILENAME
#undef FS_MOCK_DECLARE
#undef FS_MOCK_RESET
TEST_CASE("LittleFS checks the config object passed in", "[fs]")
{
LITTLEFS_MOCK_DECLARE(64, 8, 512, "");
FSConfig f;
SPIFFSConfig s;
SDFSConfig d;
LittleFSConfig l;
REQUIRE_FALSE(LittleFS.setConfig(f));
REQUIRE_FALSE(LittleFS.setConfig(s));
REQUIRE_FALSE(LittleFS.setConfig(d));
REQUIRE(LittleFS.setConfig(l));
}
}; // namespace littlefs_test
namespace sdfs_test
{
#define FSTYPE SDFS
#define TESTPRE "SDFS - "
#define TESTPAT "[sdfs]"
// SDFS supports long paths (MAXPATH)
#define TOOLONGFILENAME \
"/" \
"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012" \
"34567890" \
"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012" \
"34567890" \
"12345678901234567890123456789012345678901234567890123456"
#define FS_MOCK_DECLARE SDFS_MOCK_DECLARE
#define FS_MOCK_RESET SDFS_MOCK_RESET
#define FS_HAS_DIRS
#include "test_fs.inc"
#undef FSTYPE
#undef TESTPRE
#undef TESTPAT
#undef TOOLONGFILENAME
#undef FS_MOCK_DECLARE
#undef FS_MOCK_RESET
TEST_CASE("SDFS checks the config object passed in", "[fs]")
{
SDFS_MOCK_DECLARE(64, 8, 512, "");
FSConfig f;
SPIFFSConfig s;
SDFSConfig d;
LittleFSConfig l;
REQUIRE_FALSE(SDFS.setConfig(f));
REQUIRE_FALSE(SDFS.setConfig(s));
REQUIRE(SDFS.setConfig(d));
REQUIRE_FALSE(SDFS.setConfig(l));
}
// Also a SD specific test to check that FILE_OPEN is really an append operation:
TEST_CASE("SD.h FILE_WRITE macro is append", "[fs]")
{
SDFS_MOCK_DECLARE(64, 8, 512, "");
REQUIRE(SDFS.begin());
REQUIRE(SD.begin(4));
File f = SD.open("/file.txt", FILE_WRITE);
f.write('a');
f.write(65);
f.write("bbcc");
f.write("theend", 6);
char block[3] = { 'x', 'y', 'z' };
f.write(block, 3);
uint32_t bigone = 0x40404040;
f.write((const uint8_t*)&bigone, 4);
f.close();
REQUIRE(readFile("/file.txt") == "aAbbcctheendxyz@@@@");
f = SD.open("/file.txt", FILE_WRITE);
f.write("append", 6);
f.close();
REQUIRE(readFile("/file.txt") == "aAbbcctheendxyz@@@@append");
File g = SD.open("/file2.txt", FILE_WRITE);
g.write(0);
g.close();
g = SD.open("/file2.txt", FILE_READ);
uint8_t u = 0x66;
g.read(&u, 1);
g.close();
REQUIRE(u == 0);
}
}; // namespace sdfs_test