1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-30 17:01:19 +01:00

unittests/tests-spiffs: add partition test

This commit is contained in:
Vincent Dupont 2018-01-04 17:14:24 +01:00
parent ced65bbf5b
commit 647133f5c5

View File

@ -143,6 +143,9 @@ static void test_spiffs_teardown(void)
vfs_unlink("/test-spiffs/test1.txt");
vfs_unlink("/test-spiffs/a/test2.txt");
vfs_umount(&_test_spiffs_mount);
spiffs_desc.base_addr = 0;
spiffs_desc.block_count = 0;
}
static void tests_spiffs_format(void)
@ -382,6 +385,58 @@ static void tests_spiffs_statvfs(void)
TEST_ASSERT(sizeof(buf) <= (stat1.f_bavail - stat2.f_bavail));
}
static void tests_spiffs_partition(void)
{
vfs_umount(&_test_spiffs_mount);
spiffs_desc.base_addr = _dev->page_size * _dev->pages_per_sector;
spiffs_desc.block_count = 2;
mtd_erase(_dev, 0, _dev->page_size * _dev->pages_per_sector * _dev->sector_count);
int res = vfs_format(&_test_spiffs_mount);
TEST_ASSERT_EQUAL_INT(0, res);
res = vfs_mount(&_test_spiffs_mount);
TEST_ASSERT_EQUAL_INT(0, res);
#if SPIFFS_USE_MAGIC
/* if SPIFFS_USE_MAGIC is used, a magic word is written in each sector */
uint8_t buf[4];
const uint8_t buf_erased[4] = {0xff, 0xff, 0xff, 0xff};
int nread;
res = 0;
for (size_t i = 0; i < _dev->page_size * _dev->pages_per_sector; i += sizeof(buf)) {
nread = mtd_read(_dev, buf, _dev->page_size * _dev->pages_per_sector + i, sizeof(buf));
TEST_ASSERT_EQUAL_INT(sizeof(buf), nread);
res |= memcmp(buf, buf_erased, sizeof(buf));
}
TEST_ASSERT(res != 0);
res = 0;
for (size_t i = 0; i < _dev->page_size * _dev->pages_per_sector; i += sizeof(buf)) {
nread = mtd_read(_dev, buf, (2 * _dev->page_size * _dev->pages_per_sector) + i, sizeof(buf));
TEST_ASSERT_EQUAL_INT(sizeof(buf), nread);
res |= memcmp(buf, buf_erased, sizeof(buf));
}
TEST_ASSERT(res != 0);
/* Check previous sector (must be erased) */
res = 0;
for (size_t i = 0; i < _dev->page_size * _dev->pages_per_sector; i += sizeof(buf)) {
nread = mtd_read(_dev, buf, i, sizeof(buf));
TEST_ASSERT_EQUAL_INT(sizeof(buf), nread);
res |= memcmp(buf, buf_erased, sizeof(buf));
}
TEST_ASSERT(res == 0);
/* Check next sector (must be erased) */
res = 0;
for (size_t i = 0; i < _dev->page_size * _dev->pages_per_sector; i += sizeof(buf)) {
nread = mtd_read(_dev, buf, (3 * _dev->page_size * _dev->pages_per_sector) + i, sizeof(buf));
TEST_ASSERT_EQUAL_INT(sizeof(buf), nread);
res |= memcmp(buf, buf_erased, sizeof(buf));
}
TEST_ASSERT(res == 0);
#endif
}
Test *tests_spiffs_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
@ -393,6 +448,7 @@ Test *tests_spiffs_tests(void)
new_TestFixture(tests_spiffs_readdir),
new_TestFixture(tests_spiffs_rename),
new_TestFixture(tests_spiffs_statvfs),
new_TestFixture(tests_spiffs_partition),
};
EMB_UNIT_TESTCALLER(spiffs_tests, test_spiffs_setup, test_spiffs_teardown, fixtures);