mirror of https://github.com/ARMmbed/mbed-os.git
littlefs: fix coding style
parent
bc4101e5f3
commit
20646d3da1
|
@ -24,7 +24,7 @@ using namespace mbed;
|
|||
|
||||
extern "C" void lfs_crc(uint32_t *crc, const void *buffer, size_t size)
|
||||
{
|
||||
uint32_t initial_xor = *crc;
|
||||
uint32_t initial_xor = *crc;
|
||||
MbedCRC<POLY_32BIT_REV_ANSI, 32> ct(initial_xor, 0x0, true, false);
|
||||
ct.compute((void *)buffer, size, (uint32_t *) crc);
|
||||
}
|
||||
|
@ -33,39 +33,54 @@ extern "C" void lfs_crc(uint32_t *crc, const void *buffer, size_t size)
|
|||
static int lfs_toerror(int err)
|
||||
{
|
||||
switch (err) {
|
||||
case LFS_ERR_OK: return 0;
|
||||
case LFS_ERR_IO: return -EIO;
|
||||
case LFS_ERR_NOENT: return -ENOENT;
|
||||
case LFS_ERR_EXIST: return -EEXIST;
|
||||
case LFS_ERR_NOTDIR: return -ENOTDIR;
|
||||
case LFS_ERR_ISDIR: return -EISDIR;
|
||||
case LFS_ERR_INVAL: return -EINVAL;
|
||||
case LFS_ERR_NOSPC: return -ENOSPC;
|
||||
case LFS_ERR_NOMEM: return -ENOMEM;
|
||||
case LFS_ERR_CORRUPT: return -EILSEQ;
|
||||
default: return err;
|
||||
case LFS_ERR_OK:
|
||||
return 0;
|
||||
case LFS_ERR_IO:
|
||||
return -EIO;
|
||||
case LFS_ERR_NOENT:
|
||||
return -ENOENT;
|
||||
case LFS_ERR_EXIST:
|
||||
return -EEXIST;
|
||||
case LFS_ERR_NOTDIR:
|
||||
return -ENOTDIR;
|
||||
case LFS_ERR_ISDIR:
|
||||
return -EISDIR;
|
||||
case LFS_ERR_INVAL:
|
||||
return -EINVAL;
|
||||
case LFS_ERR_NOSPC:
|
||||
return -ENOSPC;
|
||||
case LFS_ERR_NOMEM:
|
||||
return -ENOMEM;
|
||||
case LFS_ERR_CORRUPT:
|
||||
return -EILSEQ;
|
||||
default:
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
static int lfs_fromflags(int flags)
|
||||
{
|
||||
return (
|
||||
(((flags & 3) == O_RDONLY) ? LFS_O_RDONLY : 0) |
|
||||
(((flags & 3) == O_WRONLY) ? LFS_O_WRONLY : 0) |
|
||||
(((flags & 3) == O_RDWR) ? LFS_O_RDWR : 0) |
|
||||
((flags & O_CREAT) ? LFS_O_CREAT : 0) |
|
||||
((flags & O_EXCL) ? LFS_O_EXCL : 0) |
|
||||
((flags & O_TRUNC) ? LFS_O_TRUNC : 0) |
|
||||
((flags & O_APPEND) ? LFS_O_APPEND : 0));
|
||||
(((flags & 3) == O_RDONLY) ? LFS_O_RDONLY : 0) |
|
||||
(((flags & 3) == O_WRONLY) ? LFS_O_WRONLY : 0) |
|
||||
(((flags & 3) == O_RDWR) ? LFS_O_RDWR : 0) |
|
||||
((flags & O_CREAT) ? LFS_O_CREAT : 0) |
|
||||
((flags & O_EXCL) ? LFS_O_EXCL : 0) |
|
||||
((flags & O_TRUNC) ? LFS_O_TRUNC : 0) |
|
||||
((flags & O_APPEND) ? LFS_O_APPEND : 0));
|
||||
}
|
||||
|
||||
static int lfs_fromwhence(int whence)
|
||||
{
|
||||
switch (whence) {
|
||||
case SEEK_SET: return LFS_SEEK_SET;
|
||||
case SEEK_CUR: return LFS_SEEK_CUR;
|
||||
case SEEK_END: return LFS_SEEK_END;
|
||||
default: return whence;
|
||||
case SEEK_SET:
|
||||
return LFS_SEEK_SET;
|
||||
case SEEK_CUR:
|
||||
return LFS_SEEK_CUR;
|
||||
case SEEK_END:
|
||||
return LFS_SEEK_END;
|
||||
default:
|
||||
return whence;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,39 +88,47 @@ static int lfs_tomode(int type)
|
|||
{
|
||||
int mode = S_IRWXU | S_IRWXG | S_IRWXO;
|
||||
switch (type) {
|
||||
case LFS_TYPE_DIR: return mode | S_IFDIR;
|
||||
case LFS_TYPE_REG: return mode | S_IFREG;
|
||||
default: return 0;
|
||||
case LFS_TYPE_DIR:
|
||||
return mode | S_IFDIR;
|
||||
case LFS_TYPE_REG:
|
||||
return mode | S_IFREG;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int lfs_totype(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case LFS_TYPE_DIR: return DT_DIR;
|
||||
case LFS_TYPE_REG: return DT_REG;
|
||||
default: return DT_UNKNOWN;
|
||||
case LFS_TYPE_DIR:
|
||||
return DT_DIR;
|
||||
case LFS_TYPE_REG:
|
||||
return DT_REG;
|
||||
default:
|
||||
return DT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////// Block device operations //////
|
||||
static int lfs_bd_read(const struct lfs_config *c, lfs_block_t block,
|
||||
lfs_off_t off, void *buffer, lfs_size_t size) {
|
||||
lfs_off_t off, void *buffer, lfs_size_t size)
|
||||
{
|
||||
BlockDevice *bd = (BlockDevice *)c->context;
|
||||
return bd->read(buffer, (bd_addr_t)block*c->block_size + off, size);
|
||||
return bd->read(buffer, (bd_addr_t)block * c->block_size + off, size);
|
||||
}
|
||||
|
||||
static int lfs_bd_prog(const struct lfs_config *c, lfs_block_t block,
|
||||
lfs_off_t off, const void *buffer, lfs_size_t size) {
|
||||
lfs_off_t off, const void *buffer, lfs_size_t size)
|
||||
{
|
||||
BlockDevice *bd = (BlockDevice *)c->context;
|
||||
return bd->program(buffer, (bd_addr_t)block*c->block_size + off, size);
|
||||
return bd->program(buffer, (bd_addr_t)block * c->block_size + off, size);
|
||||
}
|
||||
|
||||
static int lfs_bd_erase(const struct lfs_config *c, lfs_block_t block)
|
||||
{
|
||||
BlockDevice *bd = (BlockDevice *)c->context;
|
||||
return bd->erase((bd_addr_t)block*c->block_size, c->block_size);
|
||||
return bd->erase((bd_addr_t)block * c->block_size, c->block_size);
|
||||
}
|
||||
|
||||
static int lfs_bd_sync(const struct lfs_config *c)
|
||||
|
@ -119,19 +142,21 @@ static int lfs_bd_sync(const struct lfs_config *c)
|
|||
|
||||
// Filesystem implementation (See LittleFileSystem.h)
|
||||
LittleFileSystem::LittleFileSystem(const char *name, BlockDevice *bd,
|
||||
lfs_size_t read_size, lfs_size_t prog_size,
|
||||
lfs_size_t block_size, lfs_size_t lookahead)
|
||||
: FileSystem(name)
|
||||
, _read_size(read_size)
|
||||
, _prog_size(prog_size)
|
||||
, _block_size(block_size)
|
||||
, _lookahead(lookahead) {
|
||||
lfs_size_t read_size, lfs_size_t prog_size,
|
||||
lfs_size_t block_size, lfs_size_t lookahead)
|
||||
: FileSystem(name)
|
||||
, _read_size(read_size)
|
||||
, _prog_size(prog_size)
|
||||
, _block_size(block_size)
|
||||
, _lookahead(lookahead)
|
||||
{
|
||||
if (bd) {
|
||||
mount(bd);
|
||||
}
|
||||
}
|
||||
|
||||
LittleFileSystem::~LittleFileSystem() {
|
||||
LittleFileSystem::~LittleFileSystem()
|
||||
{
|
||||
// nop if unmounted
|
||||
unmount();
|
||||
}
|
||||
|
@ -168,7 +193,7 @@ int LittleFileSystem::mount(BlockDevice *bd)
|
|||
_config.block_size = _block_size;
|
||||
}
|
||||
_config.block_count = bd->size() / _config.block_size;
|
||||
_config.lookahead = 32 * ((_config.block_count+31)/32);
|
||||
_config.lookahead = 32 * ((_config.block_count + 31) / 32);
|
||||
if (_config.lookahead > _lookahead) {
|
||||
_config.lookahead = _lookahead;
|
||||
}
|
||||
|
@ -204,17 +229,18 @@ int LittleFileSystem::unmount()
|
|||
|
||||
_bd = NULL;
|
||||
}
|
||||
|
||||
|
||||
LFS_INFO("unmount -> %d", res);
|
||||
_mutex.unlock();
|
||||
return res;
|
||||
}
|
||||
|
||||
int LittleFileSystem::format(BlockDevice *bd,
|
||||
lfs_size_t read_size, lfs_size_t prog_size,
|
||||
lfs_size_t block_size, lfs_size_t lookahead) {
|
||||
lfs_size_t read_size, lfs_size_t prog_size,
|
||||
lfs_size_t block_size, lfs_size_t lookahead)
|
||||
{
|
||||
LFS_INFO("format(%p, %ld, %ld, %ld, %ld)",
|
||||
bd, read_size, prog_size, block_size, lookahead);
|
||||
bd, read_size, prog_size, block_size, lookahead);
|
||||
int err = bd->init();
|
||||
if (err) {
|
||||
LFS_INFO("format -> %d", err);
|
||||
|
@ -223,7 +249,7 @@ int LittleFileSystem::format(BlockDevice *bd,
|
|||
|
||||
lfs_t _lfs;
|
||||
struct lfs_config _config;
|
||||
|
||||
|
||||
memset(&_config, 0, sizeof(_config));
|
||||
_config.context = bd;
|
||||
_config.read = lfs_bd_read;
|
||||
|
@ -243,7 +269,7 @@ int LittleFileSystem::format(BlockDevice *bd,
|
|||
_config.block_size = block_size;
|
||||
}
|
||||
_config.block_count = bd->size() / _config.block_size;
|
||||
_config.lookahead = 32 * ((_config.block_count+31)/32);
|
||||
_config.lookahead = 32 * ((_config.block_count + 31) / 32);
|
||||
if (_config.lookahead > lookahead) {
|
||||
_config.lookahead = lookahead;
|
||||
}
|
||||
|
@ -288,7 +314,7 @@ int LittleFileSystem::reformat(BlockDevice *bd)
|
|||
}
|
||||
|
||||
int err = LittleFileSystem::format(bd,
|
||||
_read_size, _prog_size, _block_size, _lookahead);
|
||||
_read_size, _prog_size, _block_size, _lookahead);
|
||||
if (err) {
|
||||
LFS_INFO("reformat -> %d", err);
|
||||
_mutex.unlock();
|
||||
|
|
|
@ -51,13 +51,13 @@ public:
|
|||
* The lookahead buffer requires only 1 bit per block so it can be quite
|
||||
* large with little ram impact. Should be a multiple of 32.
|
||||
*/
|
||||
LittleFileSystem(const char *name=NULL, BlockDevice *bd=NULL,
|
||||
lfs_size_t read_size=MBED_LFS_READ_SIZE,
|
||||
lfs_size_t prog_size=MBED_LFS_PROG_SIZE,
|
||||
lfs_size_t block_size=MBED_LFS_BLOCK_SIZE,
|
||||
lfs_size_t lookahead=MBED_LFS_LOOKAHEAD);
|
||||
LittleFileSystem(const char *name = NULL, BlockDevice *bd = NULL,
|
||||
lfs_size_t read_size = MBED_LFS_READ_SIZE,
|
||||
lfs_size_t prog_size = MBED_LFS_PROG_SIZE,
|
||||
lfs_size_t block_size = MBED_LFS_BLOCK_SIZE,
|
||||
lfs_size_t lookahead = MBED_LFS_LOOKAHEAD);
|
||||
virtual ~LittleFileSystem();
|
||||
|
||||
|
||||
/** Formats a block device with the LittleFileSystem
|
||||
*
|
||||
* The block device to format should be mounted when this function is called.
|
||||
|
@ -82,10 +82,10 @@ public:
|
|||
* large with little ram impact. Should be a multiple of 32.
|
||||
*/
|
||||
static int format(BlockDevice *bd,
|
||||
lfs_size_t read_size=MBED_LFS_READ_SIZE,
|
||||
lfs_size_t prog_size=MBED_LFS_PROG_SIZE,
|
||||
lfs_size_t block_size=MBED_LFS_BLOCK_SIZE,
|
||||
lfs_size_t lookahead=MBED_LFS_LOOKAHEAD);
|
||||
lfs_size_t read_size = MBED_LFS_READ_SIZE,
|
||||
lfs_size_t prog_size = MBED_LFS_PROG_SIZE,
|
||||
lfs_size_t block_size = MBED_LFS_BLOCK_SIZE,
|
||||
lfs_size_t lookahead = MBED_LFS_LOOKAHEAD);
|
||||
|
||||
/** Mounts a filesystem to a block device
|
||||
*
|
||||
|
@ -182,7 +182,7 @@ protected:
|
|||
*
|
||||
* @param file File handle
|
||||
* @param buffer The buffer to write from
|
||||
* @param size The number of bytes to write
|
||||
* @param size The number of bytes to write
|
||||
* @return The number of bytes written, negative error on failure
|
||||
*/
|
||||
virtual ssize_t file_write(mbed::fs_file_t file, const void *buffer, size_t size);
|
||||
|
@ -263,7 +263,7 @@ protected:
|
|||
* @param dir Dir handle
|
||||
*/
|
||||
virtual void dir_rewind(mbed::fs_dir_t dir);
|
||||
|
||||
|
||||
private:
|
||||
lfs_t _lfs; // _the actual filesystem
|
||||
struct lfs_config _config;
|
||||
|
|
|
@ -157,9 +157,9 @@ static int file_scanf(File *file, const char *format, ...)
|
|||
int res = file->read(buf, sizeof(buf) - 1);
|
||||
TEST_ASSERT_OR_EXIT(res >= 0);
|
||||
|
||||
va_start (args, format);
|
||||
int count = vsscanf((char*)buf, format, args);
|
||||
va_end (args);
|
||||
va_start(args, format);
|
||||
int count = vsscanf((char *)buf, format, args);
|
||||
va_end(args);
|
||||
TEST_ASSERT_OR_EXIT(count >= 0);
|
||||
|
||||
return count;
|
||||
|
@ -176,9 +176,9 @@ static int file_printf(File *file, const char *format, ...)
|
|||
{
|
||||
uint8_t buf[BUFFER_SIZE];
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
int size = vsprintf((char*)buf, format, args);
|
||||
va_end (args);
|
||||
va_start(args, format);
|
||||
int size = vsprintf((char *)buf, format, args);
|
||||
va_end(args);
|
||||
TEST_ASSERT_OR_EXIT((size >= 0) && (size <= (int)sizeof(buf)));
|
||||
|
||||
if (file_write(file, buf, size)) {
|
||||
|
@ -254,7 +254,7 @@ static void check_file_rename(FileSystem *fs)
|
|||
|
||||
int files = 0;
|
||||
int valids = 0;
|
||||
const char * const filenames[] = {FILE_RENAME_A, FILE_RENAME_B};
|
||||
const char *const filenames[] = {FILE_RENAME_A, FILE_RENAME_B};
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
File file;
|
||||
|
@ -300,7 +300,7 @@ static void setup_file_rename_replace(FileSystem *fs)
|
|||
uint32_t count = 0;
|
||||
uint8_t buf[BUFFER_SIZE];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
const int length = sprintf((char*)buf, FILE_RENAME_REPLACE_FMT, count);
|
||||
const int length = sprintf((char *)buf, FILE_RENAME_REPLACE_FMT, count);
|
||||
TEST_ASSERT_OR_EXIT(length > 0);
|
||||
|
||||
res = file.write(buf, length);
|
||||
|
@ -602,7 +602,7 @@ static bool format_required(BlockDevice *bd)
|
|||
|
||||
// Get the test version
|
||||
uint32_t version = 0;
|
||||
res = sscanf((char*)buf, FILE_SETUP_COMPLETE_FMT, &version);
|
||||
res = sscanf((char *)buf, FILE_SETUP_COMPLETE_FMT, &version);
|
||||
if (res != 1) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -300,8 +300,8 @@ void test_multi_block_directory()
|
|||
res = fs.mkdir("cactus", 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
for (int i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "cactus/test%d", i);
|
||||
res = fs.mkdir((char*)buffer, 0777);
|
||||
sprintf((char *)buffer, "cactus/test%d", i);
|
||||
res = fs.mkdir((char *)buffer, 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
res = fs.unmount();
|
||||
|
@ -326,10 +326,10 @@ void test_multi_block_directory()
|
|||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_DIR, res);
|
||||
for (int i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "test%d", i);
|
||||
sprintf((char *)buffer, "test%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
res = dir[0].read(&ent);
|
||||
|
|
|
@ -167,7 +167,7 @@ void test_small_file_test()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ void test_medium_file_test()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ void test_large_file_test()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ void test_non_overlap_check()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ void test_non_overlap_check()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ void test_non_overlap_check()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = file[0].read(buffer, chunk);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -388,28 +388,28 @@ void test_dir_check()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, "smallavacado");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, "mediumavacado");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, "largeavacado");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].close();
|
||||
|
|
|
@ -111,18 +111,18 @@ void test_parallel_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[3].open(&fs, "d", O_WRONLY | O_CREAT);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
res = file[0].write((const void*)"a", 1);
|
||||
res = file[0].write((const void *)"a", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[1].write((const void*)"b", 1);
|
||||
res = file[1].write((const void *)"b", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[2].write((const void*)"c", 1);
|
||||
res = file[2].write((const void *)"c", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[3].write((const void*)"d", 1);
|
||||
res = file[3].write((const void *)"d", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
|
||||
|
||||
file[0].close();
|
||||
file[1].close();
|
||||
file[2].close();
|
||||
|
@ -147,28 +147,28 @@ void test_parallel_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, "b");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, "c");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, "d");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].close();
|
||||
|
@ -181,7 +181,7 @@ void test_parallel_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[3].open(&fs, "d", O_RDONLY);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
res = file[0].read(buffer, 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
@ -200,7 +200,7 @@ void test_parallel_file_test()
|
|||
res = buffer[0];
|
||||
TEST_ASSERT_EQUAL('d', res);
|
||||
}
|
||||
|
||||
|
||||
file[0].close();
|
||||
file[1].close();
|
||||
file[2].close();
|
||||
|
@ -223,9 +223,9 @@ void test_parallel_remove_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "e", O_WRONLY | O_CREAT);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = file[0].write((const void*)"e", 1);
|
||||
res = file[0].write((const void *)"e", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
res = fs.remove("a");
|
||||
|
@ -236,12 +236,12 @@ void test_parallel_remove_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fs.remove("d");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = file[0].write((const void*)"e", 1);
|
||||
res = file[0].write((const void *)"e", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
|
||||
|
||||
file[0].close();
|
||||
res = dir[0].open(&fs, "/");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -263,21 +263,21 @@ void test_parallel_remove_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "e", O_RDONLY);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
res = file[0].read(buffer, 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = buffer[0];
|
||||
TEST_ASSERT_EQUAL('e', res);
|
||||
}
|
||||
|
||||
|
||||
file[0].close();
|
||||
res = fs.unmount();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -301,27 +301,27 @@ void test_remove_inconveniently_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[2].open(&fs, "g", O_WRONLY | O_CREAT);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = file[0].write((const void*)"e", 1);
|
||||
res = file[0].write((const void *)"e", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[1].write((const void*)"f", 1);
|
||||
res = file[1].write((const void *)"f", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[2].write((const void*)"g", 1);
|
||||
res = file[2].write((const void *)"g", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
res = fs.remove("f");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = file[0].write((const void*)"e", 1);
|
||||
res = file[0].write((const void *)"e", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[1].write((const void*)"f", 1);
|
||||
res = file[1].write((const void *)"f", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = file[2].write((const void*)"g", 1);
|
||||
res = file[2].write((const void *)"g", 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
|
||||
|
||||
file[0].close();
|
||||
file[1].close();
|
||||
file[2].close();
|
||||
|
@ -345,14 +345,14 @@ void test_remove_inconveniently_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, "g");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ent.d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].close();
|
||||
|
@ -361,7 +361,7 @@ void test_remove_inconveniently_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[1].open(&fs, "g", O_RDONLY);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
res = file[0].read(buffer, 1);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
@ -372,7 +372,7 @@ void test_remove_inconveniently_test()
|
|||
res = buffer[0];
|
||||
TEST_ASSERT_EQUAL('g', res);
|
||||
}
|
||||
|
||||
|
||||
file[0].close();
|
||||
file[1].close();
|
||||
res = fs.unmount();
|
||||
|
|
|
@ -94,11 +94,11 @@ void test_seek_tests()
|
|||
res = fs.mkdir("hello", 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
for (int i = 0; i < 132; i++) {
|
||||
sprintf((char*)buffer, "hello/kitty%d", i);
|
||||
res = file[0].open(&fs, (char*)buffer,
|
||||
O_WRONLY | O_CREAT | O_APPEND);
|
||||
sprintf((char *)buffer, "hello/kitty%d", i);
|
||||
res = file[0].open(&fs, (char *)buffer,
|
||||
O_WRONLY | O_CREAT | O_APPEND);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size = strlen("kittycatcat");
|
||||
memcpy(buffer, "kittycatcat", size);
|
||||
for (int j = 0; j < 132; j++) {
|
||||
|
@ -133,29 +133,29 @@ void test_simple_dir_seek()
|
|||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, "..");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
pos = dir[0].tell();
|
||||
}
|
||||
res = pos >= 0;
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
|
||||
dir[0].seek(pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
dir[0].rewind();
|
||||
sprintf((char*)buffer, "kitty%d", 0);
|
||||
sprintf((char *)buffer, "kitty%d", 0);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, ".");
|
||||
|
@ -166,14 +166,14 @@ void test_simple_dir_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
dir[0].seek(pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -203,29 +203,29 @@ void test_large_dir_seek()
|
|||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, "..");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
int i;
|
||||
for (i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
pos = dir[0].tell();
|
||||
}
|
||||
res = pos >= 0;
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
|
||||
dir[0].seek(pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
dir[0].rewind();
|
||||
sprintf((char*)buffer, "kitty%d", 0);
|
||||
sprintf((char *)buffer, "kitty%d", 0);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, ".");
|
||||
|
@ -236,14 +236,14 @@ void test_large_dir_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
dir[0].seek(pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = dir[0].read(&ent);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ent.d_name, (char*)buffer);
|
||||
res = strcmp(ent.d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = dir[0].close();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -265,7 +265,7 @@ void test_simple_file_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "hello/kitty42", O_RDONLY);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
size = strlen("kittycatcat");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
@ -283,7 +283,7 @@ void test_simple_file_seek()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
file[0].rewind();
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -307,7 +307,7 @@ void test_simple_file_seek()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size_t size = file[0].size();
|
||||
res = file[0].seek(0, SEEK_CUR);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -331,7 +331,7 @@ void test_large_file_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "hello/kitty42", O_RDONLY);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
size = strlen("kittycatcat");
|
||||
for (int i = 0; i < 128; i++) {
|
||||
|
@ -349,7 +349,7 @@ void test_large_file_seek()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
file[0].rewind();
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -373,7 +373,7 @@ void test_large_file_seek()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size_t size = file[0].size();
|
||||
res = file[0].seek(0, SEEK_CUR);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -397,7 +397,7 @@ void test_simple_file_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "hello/kitty42", O_RDWR);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
size = strlen("kittycatcat");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
@ -409,7 +409,7 @@ void test_simple_file_seek_and_write()
|
|||
}
|
||||
res = pos >= 0;
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
|
||||
memcpy(buffer, "doggodogdog", size);
|
||||
res = file[0].seek(pos, SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(pos, res);
|
||||
|
@ -421,7 +421,7 @@ void test_simple_file_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "doggodogdog", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
file[0].rewind();
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -439,7 +439,7 @@ void test_simple_file_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size_t size = file[0].size();
|
||||
res = file[0].seek(0, SEEK_CUR);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -463,7 +463,7 @@ void test_large_file_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "hello/kitty42", O_RDWR);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
size = strlen("kittycatcat");
|
||||
for (int i = 0; i < 128; i++) {
|
||||
|
@ -477,7 +477,7 @@ void test_large_file_seek_and_write()
|
|||
}
|
||||
res = pos >= 0;
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
|
||||
memcpy(buffer, "doggodogdog", size);
|
||||
res = file[0].seek(pos, SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(pos, res);
|
||||
|
@ -489,7 +489,7 @@ void test_large_file_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "doggodogdog", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
file[0].rewind();
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -507,7 +507,7 @@ void test_large_file_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size_t size = file[0].size();
|
||||
res = file[0].seek(0, SEEK_CUR);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -531,10 +531,10 @@ void test_boundary_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "hello/kitty42", O_RDWR);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size = strlen("hedgehoghog");
|
||||
const off_t offsets[] = {512, 1020, 513, 1021, 511, 1019};
|
||||
|
||||
|
||||
for (int i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
|
||||
off_t off = offsets[i];
|
||||
memcpy(buffer, "hedgehoghog", size);
|
||||
|
@ -577,29 +577,29 @@ void test_out_of_bounds_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].open(&fs, "hello/kitty42", O_RDWR);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size = strlen("kittycatcat");
|
||||
res = file[0].size();
|
||||
TEST_ASSERT_EQUAL(132*size, res);
|
||||
res = file[0].seek((132+4)*size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL((132+4)*size, res);
|
||||
TEST_ASSERT_EQUAL(132 * size, res);
|
||||
res = file[0].seek((132 + 4) * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL((132 + 4)*size, res);
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
memcpy(buffer, "porcupineee", size);
|
||||
res = file[0].write(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = file[0].seek((132+4)*size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL((132+4)*size, res);
|
||||
res = file[0].seek((132 + 4) * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL((132 + 4)*size, res);
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "porcupineee", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = file[0].seek(132*size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(132*size, res);
|
||||
res = file[0].seek(132 * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(132 * size, res);
|
||||
res = file[0].read(buffer, size);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "\0\0\0\0\0\0\0\0\0\0\0", size);
|
||||
|
|
|
@ -117,10 +117,10 @@ void test_bad_mount()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
{
|
||||
res = bd.erase(0, 2*bd.get_erase_size());
|
||||
res = bd.erase(0, 2 * bd.get_erase_size());
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
memset(buffer, 0, bd.get_program_size());
|
||||
for (int i = 0; i < 2*bd.get_erase_size(); i += bd.get_program_size()) {
|
||||
for (int i = 0; i < 2 * bd.get_erase_size(); i += bd.get_program_size()) {
|
||||
res = bd.program(buffer, i, bd.get_program_size());
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ void test_resilience()
|
|||
bd_size_t block_size = bd.get_erase_size();
|
||||
bd.deinit();
|
||||
|
||||
SlicingBlockDevice slice(&bd, 0, MBED_TEST_BLOCK_COUNT*block_size);
|
||||
SlicingBlockDevice slice(&bd, 0, MBED_TEST_BLOCK_COUNT * block_size);
|
||||
|
||||
// Setup the test
|
||||
setup_atomic_operations(&slice, true);
|
||||
|
|
|
@ -62,11 +62,11 @@ static uint32_t test_wear_leveling_size(uint32_t block_count)
|
|||
bd_size_t block_size = bd.get_erase_size();
|
||||
bd.deinit();
|
||||
|
||||
SlicingBlockDevice slice(&bd, 0, block_count*block_size);
|
||||
SlicingBlockDevice slice(&bd, 0, block_count * block_size);
|
||||
ExhaustibleBlockDevice ebd(&slice, MBED_TEST_ERASE_CYCLES);
|
||||
|
||||
printf("Testing size %llu bytes (%lux%llu) blocks\n",
|
||||
block_count*block_size, block_count, block_size);
|
||||
block_count * block_size, block_count, block_size);
|
||||
setup_atomic_operations(&ebd, true);
|
||||
|
||||
int64_t cycles = 0;
|
||||
|
|
|
@ -301,8 +301,8 @@ void test_multi_block_directory()
|
|||
res = mkdir("/fs/" "cactus", 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
for (int i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "/fs/" "cactus/test%d", i);
|
||||
res = mkdir((char*)buffer, 0777);
|
||||
sprintf((char *)buffer, "/fs/" "cactus/test%d", i);
|
||||
res = mkdir((char *)buffer, 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
res = fs.unmount();
|
||||
|
@ -327,10 +327,10 @@ void test_multi_block_directory()
|
|||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_DIR, res);
|
||||
for (int i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "test%d", i);
|
||||
sprintf((char *)buffer, "test%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
}
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
|
|
|
@ -167,7 +167,7 @@ void test_small_file_test()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = fread(buffer, 1, chunk, fd[0]);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ void test_medium_file_test()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = fread(buffer, 1, chunk, fd[0]);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ void test_large_file_test()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = fread(buffer, 1, chunk, fd[0]);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ void test_non_overlap_check()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = fread(buffer, 1, chunk, fd[0]);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ void test_non_overlap_check()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = fread(buffer, 1, chunk, fd[0]);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ void test_non_overlap_check()
|
|||
chunk = (chunk < size - i) ? chunk : size - i;
|
||||
res = fread(buffer, 1, chunk, fd[0]);
|
||||
TEST_ASSERT_EQUAL(chunk, res);
|
||||
for (size_t b = 0; b < chunk && i+b < size; b++) {
|
||||
for (size_t b = 0; b < chunk && i + b < size; b++) {
|
||||
res = buffer[b];
|
||||
TEST_ASSERT_EQUAL(rand() & 0xff, res);
|
||||
}
|
||||
|
@ -388,28 +388,28 @@ void test_dir_check()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, "smallavacado");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, "mediumavacado");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, "largeavacado");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = closedir(dd[0]);
|
||||
|
|
|
@ -111,18 +111,18 @@ void test_parallel_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = !((fd[3] = fopen("/fs/" "d", "wb")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
res = fwrite((const void*)"a", 1, 1, fd[0]);
|
||||
res = fwrite((const void *)"a", 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"b", 1, 1, fd[1]);
|
||||
res = fwrite((const void *)"b", 1, 1, fd[1]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"c", 1, 1, fd[2]);
|
||||
res = fwrite((const void *)"c", 1, 1, fd[2]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"d", 1, 1, fd[3]);
|
||||
res = fwrite((const void *)"d", 1, 1, fd[3]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
|
||||
|
||||
fclose(fd[0]);
|
||||
fclose(fd[1]);
|
||||
fclose(fd[2]);
|
||||
|
@ -147,28 +147,28 @@ void test_parallel_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, "b");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, "c");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, "d");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = closedir(dd[0]);
|
||||
|
@ -181,7 +181,7 @@ void test_parallel_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = !((fd[3] = fopen("/fs/" "d", "rb")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
res = fread(buffer, 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
@ -200,7 +200,7 @@ void test_parallel_file_test()
|
|||
res = buffer[0];
|
||||
TEST_ASSERT_EQUAL('d', res);
|
||||
}
|
||||
|
||||
|
||||
fclose(fd[0]);
|
||||
fclose(fd[1]);
|
||||
fclose(fd[2]);
|
||||
|
@ -223,9 +223,9 @@ void test_parallel_remove_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = !((fd[0] = fopen("/fs/" "e", "wb")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = fwrite((const void*)"e", 1, 1, fd[0]);
|
||||
res = fwrite((const void *)"e", 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
res = remove("/fs/" "a");
|
||||
|
@ -236,12 +236,12 @@ void test_parallel_remove_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = remove("/fs/" "d");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = fwrite((const void*)"e", 1, 1, fd[0]);
|
||||
res = fwrite((const void *)"e", 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
|
||||
|
||||
fclose(fd[0]);
|
||||
res = !((dd[0] = opendir("/fs/" "/")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -263,21 +263,21 @@ void test_parallel_remove_file_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = closedir(dd[0]);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = !((fd[0] = fopen("/fs/" "e", "rb")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
res = fread(buffer, 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = buffer[0];
|
||||
TEST_ASSERT_EQUAL('e', res);
|
||||
}
|
||||
|
||||
|
||||
fclose(fd[0]);
|
||||
res = fs.unmount();
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -301,27 +301,27 @@ void test_remove_inconveniently_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = !((fd[2] = fopen("/fs/" "g", "wb")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = fwrite((const void*)"e", 1, 1, fd[0]);
|
||||
res = fwrite((const void *)"e", 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"f", 1, 1, fd[1]);
|
||||
res = fwrite((const void *)"f", 1, 1, fd[1]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"g", 1, 1, fd[2]);
|
||||
res = fwrite((const void *)"g", 1, 1, fd[2]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
res = remove("/fs/" "f");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
res = fwrite((const void*)"e", 1, 1, fd[0]);
|
||||
res = fwrite((const void *)"e", 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"f", 1, 1, fd[1]);
|
||||
res = fwrite((const void *)"f", 1, 1, fd[1]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = fwrite((const void*)"g", 1, 1, fd[2]);
|
||||
res = fwrite((const void *)"g", 1, 1, fd[2]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
}
|
||||
|
||||
|
||||
fclose(fd[0]);
|
||||
fclose(fd[1]);
|
||||
fclose(fd[2]);
|
||||
|
@ -345,14 +345,14 @@ void test_remove_inconveniently_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, "g");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ed->d_type;
|
||||
TEST_ASSERT_EQUAL(DT_REG, res);
|
||||
|
||||
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = closedir(dd[0]);
|
||||
|
@ -361,7 +361,7 @@ void test_remove_inconveniently_test()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = !((fd[1] = fopen("/fs/" "g", "rb")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
res = fread(buffer, 1, 1, fd[0]);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
@ -372,7 +372,7 @@ void test_remove_inconveniently_test()
|
|||
res = buffer[0];
|
||||
TEST_ASSERT_EQUAL('g', res);
|
||||
}
|
||||
|
||||
|
||||
fclose(fd[0]);
|
||||
fclose(fd[1]);
|
||||
res = fs.unmount();
|
||||
|
|
|
@ -94,11 +94,11 @@ void test_seek_tests()
|
|||
res = mkdir("/fs/" "hello", 0777);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
for (int i = 0; i < 132; i++) {
|
||||
sprintf((char*)buffer, "/fs/" "hello/kitty%d", i);
|
||||
res = !((fd[0] = fopen((char*)buffer,
|
||||
"ab")) != NULL);
|
||||
sprintf((char *)buffer, "/fs/" "hello/kitty%d", i);
|
||||
res = !((fd[0] = fopen((char *)buffer,
|
||||
"ab")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size = strlen("kittycatcat");
|
||||
memcpy(buffer, "kittycatcat", size);
|
||||
for (int j = 0; j < 132; j++) {
|
||||
|
@ -133,29 +133,29 @@ void test_simple_dir_seek()
|
|||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, "..");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
pos = telldir(dd[0]);
|
||||
}
|
||||
res = pos >= 0;
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
|
||||
seekdir(dd[0], pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
rewinddir(dd[0]);
|
||||
sprintf((char*)buffer, "kitty%d", 0);
|
||||
sprintf((char *)buffer, "kitty%d", 0);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, ".");
|
||||
|
@ -166,14 +166,14 @@ void test_simple_dir_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
seekdir(dd[0], pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = closedir(dd[0]);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -203,29 +203,29 @@ void test_large_dir_seek()
|
|||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, "..");
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
int i;
|
||||
for (i = 0; i < 128; i++) {
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
pos = telldir(dd[0]);
|
||||
}
|
||||
res = pos >= 0;
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
|
||||
seekdir(dd[0], pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
rewinddir(dd[0]);
|
||||
sprintf((char*)buffer, "kitty%d", 0);
|
||||
sprintf((char *)buffer, "kitty%d", 0);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, ".");
|
||||
|
@ -236,14 +236,14 @@ void test_large_dir_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
seekdir(dd[0], pos);
|
||||
sprintf((char*)buffer, "kitty%d", i);
|
||||
sprintf((char *)buffer, "kitty%d", i);
|
||||
res = ((ed = readdir(dd[0])) != NULL);
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
res = strcmp(ed->d_name, (char*)buffer);
|
||||
res = strcmp(ed->d_name, (char *)buffer);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = closedir(dd[0]);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -265,7 +265,7 @@ void test_simple_file_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = !((fd[0] = fopen("/fs/" "hello/kitty42", "rb")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
size = strlen("kittycatcat");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
@ -283,7 +283,7 @@ void test_simple_file_seek()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
rewind(fd[0]);
|
||||
res = fread(buffer, 1, size, fd[0]);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -307,7 +307,7 @@ void test_simple_file_seek()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
res = fseek(fd[0], 0, SEEK_CUR);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fclose(fd[0]);
|
||||
|
@ -330,7 +330,7 @@ void test_large_file_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = !((fd[0] = fopen("/fs/" "hello/kitty42", "rb")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
size = strlen("kittycatcat");
|
||||
for (int i = 0; i < 128; i++) {
|
||||
|
@ -348,7 +348,7 @@ void test_large_file_seek()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
rewind(fd[0]);
|
||||
res = fread(buffer, 1, size, fd[0]);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -372,7 +372,7 @@ void test_large_file_seek()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
res = fseek(fd[0], 0, SEEK_CUR);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fclose(fd[0]);
|
||||
|
@ -395,7 +395,7 @@ void test_simple_file_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = !((fd[0] = fopen("/fs/" "hello/kitty42", "r+b")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
size = strlen("kittycatcat");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
@ -407,7 +407,7 @@ void test_simple_file_seek_and_write()
|
|||
}
|
||||
res = pos >= 0;
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
|
||||
memcpy(buffer, "doggodogdog", size);
|
||||
res = fseek(fd[0], pos, SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -419,7 +419,7 @@ void test_simple_file_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "doggodogdog", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
rewind(fd[0]);
|
||||
res = fread(buffer, 1, size, fd[0]);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -437,7 +437,7 @@ void test_simple_file_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
res = fseek(fd[0], 0, SEEK_CUR);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fclose(fd[0]);
|
||||
|
@ -460,7 +460,7 @@ void test_large_file_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = !((fd[0] = fopen("/fs/" "hello/kitty42", "r+b")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
off_t pos;
|
||||
size = strlen("kittycatcat");
|
||||
for (int i = 0; i < 128; i++) {
|
||||
|
@ -474,7 +474,7 @@ void test_large_file_seek_and_write()
|
|||
}
|
||||
res = pos >= 0;
|
||||
TEST_ASSERT_EQUAL(1, res);
|
||||
|
||||
|
||||
memcpy(buffer, "doggodogdog", size);
|
||||
res = fseek(fd[0], pos, SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
@ -486,7 +486,7 @@ void test_large_file_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "doggodogdog", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
rewind(fd[0]);
|
||||
res = fread(buffer, 1, size, fd[0]);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
@ -504,7 +504,7 @@ void test_large_file_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "kittycatcat", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
res = fseek(fd[0], 0, SEEK_CUR);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fclose(fd[0]);
|
||||
|
@ -527,10 +527,10 @@ void test_boundary_seek_and_write()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = !((fd[0] = fopen("/fs/" "hello/kitty42", "r+b")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size = strlen("hedgehoghog");
|
||||
const off_t offsets[] = {512, 1020, 513, 1021, 511, 1019};
|
||||
|
||||
|
||||
for (int i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
|
||||
off_t off = offsets[i];
|
||||
memcpy(buffer, "hedgehoghog", size);
|
||||
|
@ -573,30 +573,30 @@ void test_out_of_bounds_seek()
|
|||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = !((fd[0] = fopen("/fs/" "hello/kitty42", "r+b")) != NULL);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
size = strlen("kittycatcat");
|
||||
res = fseek(fd[0], 0, SEEK_END);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = ftell(fd[0]);
|
||||
TEST_ASSERT_EQUAL(132*size, res);
|
||||
res = fseek(fd[0], (132+4)*size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(132 * size, res);
|
||||
res = fseek(fd[0], (132 + 4) * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fread(buffer, 1, size, fd[0]);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
|
||||
|
||||
memcpy(buffer, "porcupineee", size);
|
||||
res = fwrite(buffer, 1, size, fd[0]);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = fseek(fd[0], (132+4)*size,
|
||||
SEEK_SET);
|
||||
res = fseek(fd[0], (132 + 4) * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fread(buffer, 1, size, fd[0]);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
res = memcmp(buffer, "porcupineee", size);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fseek(fd[0], 132*size,
|
||||
SEEK_SET);
|
||||
res = fseek(fd[0], 132 * size,
|
||||
SEEK_SET);
|
||||
TEST_ASSERT_EQUAL(0, res);
|
||||
res = fread(buffer, 1, size, fd[0]);
|
||||
TEST_ASSERT_EQUAL(size, res);
|
||||
|
|
Loading…
Reference in New Issue