tests/fs: remove nffs testsuite
NFFS was removed, so it tests need to be removed too. Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
This commit is contained in:
parent
f7af1dc3a2
commit
b61e6d3787
56 changed files with 0 additions and 10922 deletions
|
@ -1,39 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
if(BOARD STREQUAL nrf52840_pca10056)
|
||||
set(CONF_FILE nrf5x.conf)
|
||||
endif()
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(basic)
|
||||
|
||||
if(BOARD STREQUAL qemu_x86)
|
||||
zephyr_compile_definitions(
|
||||
-DTEST_FLASH_OFFSET=0
|
||||
)
|
||||
elseif(BOARD STREQUAL nrf52840_pca10056)
|
||||
zephyr_compile_definitions(
|
||||
-DTEST_FLASH_OFFSET=0x20000
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT TEST)
|
||||
target_compile_definitions(app PRIVATE
|
||||
-DTEST_basic
|
||||
)
|
||||
else()
|
||||
target_compile_definitions(app PRIVATE
|
||||
-DTEST_${TEST}
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
zephyr_include_directories(../common)
|
||||
FILE(GLOB app_sources ../common/*.c src/*.c)
|
||||
|
||||
if(CONFIG_QEMU_TARGET)
|
||||
list(APPEND app_sources ../ram_backend/test_ram_backend.c)
|
||||
endif()
|
||||
|
||||
target_sources(app PRIVATE ${app_sources})
|
|
@ -1,21 +0,0 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_MAIN_STACK_SIZE=1024
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_SOC_FLASH_NRF_RADIO_SYNC=y
|
||||
CONFIG_MPU_ALLOW_FLASH_WRITE=y
|
||||
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_FILE_SYSTEM_NFFS=y
|
||||
CONFIG_FS_NFFS_FLASH_DEV_NAME="NRF_FLASH_DRV_NAME"
|
||||
CONFIG_FS_NFFS_NUM_FILES=4
|
||||
CONFIG_FS_NFFS_NUM_DIRS=4
|
||||
CONFIG_FS_NFFS_NUM_INODES=1024
|
||||
CONFIG_FS_NFFS_NUM_BLOCKS=1024
|
||||
CONFIG_FS_NFFS_NUM_CACHE_INODES=1
|
||||
CONFIG_FS_NFFS_NUM_CACHE_BLOCKS=1
|
||||
CONFIG_FILE_SYSTEM_NFFS=y
|
||||
CONFIG_NFFS_FILESYSTEM_MAX_AREAS=12
|
|
@ -1,19 +0,0 @@
|
|||
CONFIG_TEST_FLASH_DRIVERS=y
|
||||
CONFIG_FILE_SYSTEM_NFFS=y
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FS_NFFS_FLASH_DEV_NAME="ram_flash_test_drv"
|
||||
CONFIG_FS_NFFS_NUM_BLOCKS=1024
|
||||
CONFIG_FS_NFFS_NUM_CACHE_BLOCKS=1
|
||||
CONFIG_FS_NFFS_NUM_CACHE_INODES=1
|
||||
CONFIG_FS_NFFS_NUM_DIRS=4
|
||||
CONFIG_FS_NFFS_NUM_FILES=4
|
||||
CONFIG_FS_NFFS_NUM_INODES=1024
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||
CONFIG_MAIN_STACK_SIZE=1024
|
||||
CONFIG_NFFS_FILESYSTEM_MAX_AREAS=12
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_LOG=y
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/delete-node/ &storage_partition;
|
||||
|
||||
&flash_sim0 {
|
||||
/*
|
||||
* For more information, see:
|
||||
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
|
||||
*/
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
storage_partition: partition@0 {
|
||||
label = "storage";
|
||||
reg = <0x00000000 0x100000>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Codecoup
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <nffs/nffs.h>
|
||||
#include "test_nffs.h"
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(nffs_fs_basic_test,
|
||||
ztest_unit_test_setup_teardown(test_fs_mount,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_unlink,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_mkdir,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_rename,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_append,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_read,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_open,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_overwrite_one,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_overwrite_two,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_overwrite_three,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_overwrite_many,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_long_filename,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_large_write,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_many_children,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_gc,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_wear_level,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_corrupt_scratch,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_incomplete_block,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_corrupt_block,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_lost_found,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_readdir,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_split_file,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_gc_on_oom,
|
||||
test_setup, test_teardown));
|
||||
ztest_run_test_suite(nffs_fs_basic_test);
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
common:
|
||||
tags: nffs filesystem
|
||||
tests:
|
||||
filesystem.nffs.basic:
|
||||
extra_args: TEST=basic
|
||||
platform_whitelist: qemu_x86 nrf52840_pca10056
|
||||
timeout: 500
|
39
tests/subsys/fs/nffs_fs_api/cache/CMakeLists.txt
vendored
39
tests/subsys/fs/nffs_fs_api/cache/CMakeLists.txt
vendored
|
@ -1,39 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
if(BOARD STREQUAL nrf52840_pca10056)
|
||||
set(CONF_FILE nrf5x.conf)
|
||||
endif()
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(cache)
|
||||
|
||||
if(BOARD STREQUAL qemu_x86)
|
||||
zephyr_compile_definitions(
|
||||
-DTEST_FLASH_OFFSET=0
|
||||
)
|
||||
elseif(BOARD STREQUAL nrf52840_pca10056)
|
||||
zephyr_compile_definitions(
|
||||
-DTEST_FLASH_OFFSET=0x20000
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT TEST)
|
||||
target_compile_definitions(app PRIVATE
|
||||
-DTEST_basic
|
||||
)
|
||||
else()
|
||||
target_compile_definitions(app PRIVATE
|
||||
-DTEST_${TEST}
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
zephyr_include_directories(../common)
|
||||
FILE(GLOB app_sources ../common/*.c src/*.c)
|
||||
|
||||
if(CONFIG_QEMU_TARGET)
|
||||
list(APPEND app_sources ../ram_backend/test_ram_backend.c)
|
||||
endif()
|
||||
|
||||
target_sources(app PRIVATE ${app_sources})
|
21
tests/subsys/fs/nffs_fs_api/cache/nrf5x.conf
vendored
21
tests/subsys/fs/nffs_fs_api/cache/nrf5x.conf
vendored
|
@ -1,21 +0,0 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_MAIN_STACK_SIZE=1024
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_SOC_FLASH_NRF_RADIO_SYNC=y
|
||||
CONFIG_MPU_ALLOW_FLASH_WRITE=y
|
||||
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_FILE_SYSTEM_NFFS=y
|
||||
CONFIG_FS_NFFS_FLASH_DEV_NAME="NRF_FLASH_DRV_NAME"
|
||||
CONFIG_FS_NFFS_NUM_FILES=4
|
||||
CONFIG_FS_NFFS_NUM_DIRS=4
|
||||
CONFIG_FS_NFFS_NUM_INODES=1024
|
||||
CONFIG_FS_NFFS_NUM_BLOCKS=1024
|
||||
CONFIG_FS_NFFS_NUM_CACHE_INODES=1
|
||||
CONFIG_FS_NFFS_NUM_CACHE_BLOCKS=1
|
||||
CONFIG_FILE_SYSTEM_NFFS=y
|
||||
CONFIG_NFFS_FILESYSTEM_MAX_AREAS=12
|
18
tests/subsys/fs/nffs_fs_api/cache/prj.conf
vendored
18
tests/subsys/fs/nffs_fs_api/cache/prj.conf
vendored
|
@ -1,18 +0,0 @@
|
|||
CONFIG_TEST_FLASH_DRIVERS=y
|
||||
CONFIG_FILE_SYSTEM_NFFS=y
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FS_NFFS_FLASH_DEV_NAME="ram_flash_test_drv"
|
||||
CONFIG_FS_NFFS_NUM_BLOCKS=1024
|
||||
CONFIG_FS_NFFS_NUM_CACHE_BLOCKS=1
|
||||
CONFIG_FS_NFFS_NUM_CACHE_INODES=1
|
||||
CONFIG_FS_NFFS_NUM_DIRS=4
|
||||
CONFIG_FS_NFFS_NUM_FILES=4
|
||||
CONFIG_FS_NFFS_NUM_INODES=1024
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||
CONFIG_MAIN_STACK_SIZE=1024
|
||||
CONFIG_NFFS_FILESYSTEM_MAX_AREAS=12
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_ZTEST=y
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/delete-node/ &storage_partition;
|
||||
|
||||
&flash_sim0 {
|
||||
/*
|
||||
* For more information, see:
|
||||
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
|
||||
*/
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
storage_partition: partition@0 {
|
||||
label = "storage";
|
||||
reg = <0x00000000 0x100000>;
|
||||
};
|
||||
};
|
||||
};
|
18
tests/subsys/fs/nffs_fs_api/cache/src/main.c
vendored
18
tests/subsys/fs/nffs_fs_api/cache/src/main.c
vendored
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Codecoup
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <nffs/nffs.h>
|
||||
#include "test_nffs.h"
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(nffs_fs_cache_test,
|
||||
ztest_unit_test_setup_teardown(test_fs_mount,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_cache_large_file,
|
||||
test_setup, test_teardown));
|
||||
ztest_run_test_suite(nffs_fs_cache_test);
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
common:
|
||||
tags: nffs filesystem
|
||||
tests:
|
||||
filesystem.nffs.cache:
|
||||
extra_args: TEST=cache
|
||||
extra_configs:
|
||||
- CONFIG_FS_NFFS_NUM_CACHE_BLOCKS=64
|
||||
- CONFIG_FS_NFFS_NUM_CACHE_INODES=4
|
||||
platform_whitelist: qemu_x86 nrf52840_pca10056
|
File diff suppressed because it is too large
Load diff
|
@ -1,674 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <fs/fs.h>
|
||||
#include <nffs/queue.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <nffs/os.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <ztest_assert.h>
|
||||
#include "nffs_test_utils.h"
|
||||
|
||||
/*
|
||||
* This should fit the largest area used in test (128K).
|
||||
*/
|
||||
#define AREA_BUF_MAX_SIZE (128 * 1024)
|
||||
static u8_t area_buf[AREA_BUF_MAX_SIZE];
|
||||
|
||||
#define NFFS_TEST_BUF_SIZE (24 * 1024)
|
||||
u8_t nffs_test_buf[NFFS_TEST_BUF_SIZE];
|
||||
|
||||
void nffs_test_util_overwrite_data(u8_t *data, u32_t data_len,
|
||||
u32_t addr)
|
||||
{
|
||||
struct device *dev;
|
||||
struct flash_pages_info info;
|
||||
off_t off;
|
||||
|
||||
dev = device_get_binding(CONFIG_FS_NFFS_FLASH_DEV_NAME);
|
||||
flash_get_page_info_by_offs(dev, addr, &info);
|
||||
|
||||
nffs_os_flash_read(0, info.start_offset, area_buf, info.size);
|
||||
|
||||
/*
|
||||
* To make this simpler, assume we always overwrite within sector
|
||||
* boundary (which is the case here).
|
||||
*/
|
||||
off = addr - info.start_offset;
|
||||
memcpy(&area_buf[off], data, data_len);
|
||||
|
||||
nffs_os_flash_erase(0, info.start_offset, info.size);
|
||||
nffs_os_flash_write(0, info.start_offset, area_buf, info.size);
|
||||
}
|
||||
|
||||
void nffs_test_util_assert_ent_name(struct fs_dirent *fs_dirent,
|
||||
const char *expected_name)
|
||||
{
|
||||
zassert_equal(strcmp(fs_dirent->name, expected_name), 0, NULL);
|
||||
}
|
||||
|
||||
void nffs_test_util_assert_file_len(struct nffs_file *file, u32_t expected)
|
||||
{
|
||||
uint32_t len;
|
||||
int rc;
|
||||
|
||||
rc = nffs_inode_data_len(file->nf_inode_entry, &len);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
zassert_equal(len, expected, NULL);
|
||||
}
|
||||
|
||||
void nffs_test_util_assert_cache_is_sane(const char *filename)
|
||||
{
|
||||
struct nffs_cache_inode *cache_inode;
|
||||
struct nffs_cache_block *cache_block;
|
||||
struct nffs_file *file;
|
||||
struct fs_file_t fs_file;
|
||||
uint32_t cache_start;
|
||||
uint32_t cache_end;
|
||||
uint32_t block_end;
|
||||
int rc;
|
||||
|
||||
rc = fs_open(&fs_file, filename);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
file = fs_file.filep;
|
||||
rc = nffs_cache_inode_ensure(&cache_inode, file->nf_inode_entry);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
nffs_cache_inode_range(cache_inode, &cache_start, &cache_end);
|
||||
|
||||
if (TAILQ_EMPTY(&cache_inode->nci_block_list)) {
|
||||
zassert_equal(cache_start, 0, NULL);
|
||||
zassert_equal(cache_end, 0, NULL);
|
||||
} else {
|
||||
block_end = 0U; /* Pacify gcc. */
|
||||
TAILQ_FOREACH(cache_block, &cache_inode->nci_block_list,
|
||||
ncb_link) {
|
||||
if (cache_block ==
|
||||
TAILQ_FIRST(&cache_inode->nci_block_list)) {
|
||||
zassert_equal(cache_block->ncb_file_offset,
|
||||
cache_start, NULL);
|
||||
} else {
|
||||
/* Ensure no gap between this block and its
|
||||
* predecessor.
|
||||
*/
|
||||
zassert_equal(cache_block->ncb_file_offset,
|
||||
block_end, NULL);
|
||||
}
|
||||
|
||||
block_end = cache_block->ncb_file_offset +
|
||||
cache_block->ncb_block.nb_data_len;
|
||||
if (cache_block == TAILQ_LAST(&cache_inode->nci_block_list,
|
||||
nffs_cache_block_list)) {
|
||||
zassert_equal(block_end, cache_end, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rc = fs_close(&fs_file);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
nffs_test_util_assert_contents(const char *filename, const char *contents,
|
||||
int contents_len)
|
||||
{
|
||||
struct fs_file_t file;
|
||||
u32_t bytes_read;
|
||||
void *buf;
|
||||
int rc;
|
||||
|
||||
rc = fs_open(&file, filename);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
zassert_true(contents_len <= AREA_BUF_MAX_SIZE, "contents too large");
|
||||
buf = area_buf;
|
||||
|
||||
bytes_read = fs_read(&file, buf, contents_len);
|
||||
zassert_equal(bytes_read, contents_len, NULL);
|
||||
zassert_equal(memcmp(buf, contents, contents_len), 0, NULL);
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
nffs_test_util_assert_cache_is_sane(filename);
|
||||
}
|
||||
|
||||
int nffs_test_util_block_count(const char *filename)
|
||||
{
|
||||
struct nffs_hash_entry *entry;
|
||||
struct nffs_block block;
|
||||
struct nffs_file *file;
|
||||
struct fs_file_t fs_file;
|
||||
int count;
|
||||
int rc;
|
||||
|
||||
rc = fs_open(&fs_file, filename);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
file = fs_file.filep;
|
||||
count = 0;
|
||||
entry = file->nf_inode_entry->nie_last_block_entry;
|
||||
while (entry != NULL) {
|
||||
count++;
|
||||
rc = nffs_block_from_hash_entry(&block, entry);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
zassert_not_equal(block.nb_prev, entry, NULL);
|
||||
entry = block.nb_prev;
|
||||
}
|
||||
|
||||
rc = fs_close(&fs_file);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void nffs_test_util_assert_block_count(const char *filename, int expected_count)
|
||||
{
|
||||
int actual_count;
|
||||
|
||||
actual_count = nffs_test_util_block_count(filename);
|
||||
zassert_equal(actual_count, expected_count, NULL);
|
||||
}
|
||||
|
||||
void nffs_test_util_assert_cache_range(const char *filename,
|
||||
u32_t expected_cache_start,
|
||||
u32_t expected_cache_end)
|
||||
{
|
||||
struct nffs_cache_inode *cache_inode;
|
||||
struct nffs_file *file;
|
||||
struct fs_file_t fs_file;
|
||||
uint32_t cache_start;
|
||||
uint32_t cache_end;
|
||||
int rc;
|
||||
|
||||
rc = fs_open(&fs_file, filename);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
file = fs_file.filep;
|
||||
rc = nffs_cache_inode_ensure(&cache_inode, file->nf_inode_entry);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
nffs_cache_inode_range(cache_inode, &cache_start, &cache_end);
|
||||
zassert_equal(cache_start, expected_cache_start, NULL);
|
||||
zassert_equal(cache_end, expected_cache_end, NULL);
|
||||
|
||||
rc = fs_close(&fs_file);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
nffs_test_util_assert_cache_is_sane(filename);
|
||||
}
|
||||
|
||||
void nffs_test_util_create_file_blocks(const char *filename,
|
||||
const struct nffs_test_block_desc *blocks,
|
||||
int num_blocks)
|
||||
{
|
||||
struct fs_file_t file;
|
||||
u32_t total_len;
|
||||
u32_t offset;
|
||||
char *buf;
|
||||
int num_writes;
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
/* We do not have 'truncate' flag in fs_open, so unlink here instead*/
|
||||
rc = fs_unlink(filename);
|
||||
/* Don't fail on -ENOENT or 0, as can't truncate as file doesn't exists
|
||||
* or 0 on successful, fail on all other error values
|
||||
*/
|
||||
zassert_true(((rc == 0) || (rc == -ENOENT)), "unlink/truncate failed");
|
||||
|
||||
rc = fs_open(&file, filename);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
total_len = 0U;
|
||||
if (num_blocks <= 0) {
|
||||
num_writes = 1;
|
||||
} else {
|
||||
num_writes = num_blocks;
|
||||
}
|
||||
for (i = 0; i < num_writes; i++) {
|
||||
rc = fs_write(&file, blocks[i].data, blocks[i].data_len);
|
||||
zassert_equal(rc, blocks[i].data_len, NULL);
|
||||
|
||||
total_len += blocks[i].data_len;
|
||||
}
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
zassert_true(total_len <= AREA_BUF_MAX_SIZE, "contents too large");
|
||||
buf = area_buf;
|
||||
|
||||
offset = 0U;
|
||||
for (i = 0; i < num_writes; i++) {
|
||||
memcpy(buf + offset, blocks[i].data, blocks[i].data_len);
|
||||
offset += blocks[i].data_len;
|
||||
}
|
||||
zassert_equal(offset, total_len, NULL);
|
||||
|
||||
nffs_test_util_assert_contents(filename, buf, total_len);
|
||||
if (num_blocks > 0) {
|
||||
nffs_test_util_assert_block_count(filename, num_blocks);
|
||||
}
|
||||
}
|
||||
|
||||
void nffs_test_util_create_file(const char *filename, const char *contents,
|
||||
int contents_len)
|
||||
{
|
||||
struct nffs_test_block_desc block;
|
||||
|
||||
block.data = contents;
|
||||
block.data_len = contents_len;
|
||||
|
||||
nffs_test_util_create_file_blocks(filename, &block, 0);
|
||||
}
|
||||
|
||||
void nffs_test_util_append_file(const char *filename, const char *contents,
|
||||
int contents_len)
|
||||
{
|
||||
struct fs_file_t file;
|
||||
int rc;
|
||||
|
||||
rc = fs_open(&file, filename);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
rc = fs_seek(&file, 0, FS_SEEK_END);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
rc = fs_write(&file, contents, contents_len);
|
||||
zassert_equal(rc, contents_len, NULL);
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
}
|
||||
|
||||
void nffs_test_copy_area(const struct nffs_area_desc *from,
|
||||
const struct nffs_area_desc *to)
|
||||
{
|
||||
int rc;
|
||||
void *buf;
|
||||
|
||||
zassert_equal(from->nad_length, to->nad_length, NULL);
|
||||
|
||||
zassert_true(from->nad_length <= AREA_BUF_MAX_SIZE, "area too large");
|
||||
buf = area_buf;
|
||||
|
||||
rc = nffs_os_flash_read(from->nad_flash_id, from->nad_offset, buf,
|
||||
from->nad_length);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
rc = nffs_os_flash_erase(from->nad_flash_id, to->nad_offset,
|
||||
to->nad_length);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
rc = nffs_os_flash_write(to->nad_flash_id, to->nad_offset, buf,
|
||||
to->nad_length);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
}
|
||||
|
||||
void nffs_test_util_create_subtree(const char *parent_path,
|
||||
const struct nffs_test_file_desc *elem)
|
||||
{
|
||||
char *path;
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
if (parent_path == NULL) {
|
||||
path = k_malloc(1);
|
||||
zassert_not_null(path, NULL);
|
||||
path[0] = '\0';
|
||||
} else {
|
||||
path = k_malloc(strlen(parent_path) + strlen(elem->filename) + 2);
|
||||
zassert_not_null(path, NULL);
|
||||
|
||||
sprintf(path, "%s/%s", parent_path, elem->filename);
|
||||
}
|
||||
|
||||
if (elem->is_dir) {
|
||||
if ((parent_path != NULL) &&
|
||||
(strlen(parent_path) > strlen(NFFS_MNTP))) {
|
||||
rc = fs_mkdir(path);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
}
|
||||
|
||||
if (elem->children != NULL) {
|
||||
for (i = 0; elem->children[i].filename != NULL; i++) {
|
||||
nffs_test_util_create_subtree(path,
|
||||
elem->children + i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nffs_test_util_create_file(path, elem->contents,
|
||||
elem->contents_len);
|
||||
}
|
||||
|
||||
k_free(path);
|
||||
}
|
||||
|
||||
void nffs_test_util_create_tree(const struct nffs_test_file_desc *root_dir)
|
||||
{
|
||||
nffs_test_util_create_subtree(NFFS_MNTP, root_dir);
|
||||
}
|
||||
|
||||
#define NFFS_TEST_TOUCHED_ARR_SZ (16 * 64)
|
||||
/*#define NFFS_TEST_TOUCHED_ARR_SZ (16 * 1024)*/
|
||||
struct nffs_hash_entry
|
||||
*nffs_test_touched_entries[NFFS_TEST_TOUCHED_ARR_SZ];
|
||||
int nffs_test_num_touched_entries;
|
||||
|
||||
/* Recursively descend directory structure */
|
||||
void nffs_test_assert_file(const struct nffs_test_file_desc *file,
|
||||
struct nffs_inode_entry *inode_entry,
|
||||
const char *path)
|
||||
{
|
||||
const struct nffs_test_file_desc *child_file;
|
||||
struct nffs_inode inode;
|
||||
struct nffs_inode_entry *child_inode_entry;
|
||||
char *child_path, *abs_path;
|
||||
int child_filename_len;
|
||||
int path_len;
|
||||
int rc;
|
||||
|
||||
/*
|
||||
* track of hash entries that have been examined
|
||||
*/
|
||||
zassert_true(nffs_test_num_touched_entries < NFFS_TEST_TOUCHED_ARR_SZ,
|
||||
NULL);
|
||||
nffs_test_touched_entries[nffs_test_num_touched_entries] =
|
||||
&inode_entry->nie_hash_entry;
|
||||
nffs_test_num_touched_entries++;
|
||||
|
||||
path_len = strlen(path);
|
||||
|
||||
rc = nffs_inode_from_entry(&inode, inode_entry);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
/* recursively examine each child of directory */
|
||||
if (nffs_hash_id_is_dir(inode_entry->nie_hash_entry.nhe_id)) {
|
||||
for (child_file = file->children;
|
||||
child_file != NULL && child_file->filename != NULL;
|
||||
child_file++) {
|
||||
|
||||
/*
|
||||
* Construct full pathname for file
|
||||
* Not null terminated
|
||||
*/
|
||||
child_filename_len = strlen(child_file->filename);
|
||||
child_path = k_malloc(path_len + child_filename_len + 2);
|
||||
zassert_not_null(child_path, NULL);
|
||||
memcpy(child_path, path, path_len);
|
||||
child_path[path_len] = '/';
|
||||
memcpy(child_path + path_len + 1, child_file->filename,
|
||||
child_filename_len);
|
||||
child_path[path_len + 1 + child_filename_len] = '\0';
|
||||
|
||||
/*
|
||||
* Verify child inode can be found using full pathname
|
||||
*/
|
||||
rc = nffs_path_find_inode_entry(child_path,
|
||||
&child_inode_entry);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
nffs_test_assert_file(child_file, child_inode_entry,
|
||||
child_path);
|
||||
|
||||
k_free(child_path);
|
||||
}
|
||||
} else {
|
||||
abs_path = k_malloc(strlen(NFFS_MNTP) + path_len + 2);
|
||||
sprintf(abs_path, "%s%s", NFFS_MNTP, path);
|
||||
nffs_test_util_assert_contents(abs_path, file->contents,
|
||||
file->contents_len);
|
||||
k_free(abs_path);
|
||||
}
|
||||
}
|
||||
|
||||
void nffs_test_assert_branch_touched(struct nffs_inode_entry *inode_entry)
|
||||
{
|
||||
struct nffs_inode_entry *child;
|
||||
int i;
|
||||
|
||||
if (inode_entry == nffs_lost_found_dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < nffs_test_num_touched_entries; i++) {
|
||||
if (nffs_test_touched_entries[i] == &inode_entry->nie_hash_entry) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
zassert_true(i < nffs_test_num_touched_entries, NULL);
|
||||
nffs_test_touched_entries[i] = NULL;
|
||||
|
||||
if (nffs_hash_id_is_dir(inode_entry->nie_hash_entry.nhe_id)) {
|
||||
SLIST_FOREACH(child, &inode_entry->nie_child_list,
|
||||
nie_sibling_next) {
|
||||
nffs_test_assert_branch_touched(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nffs_test_assert_child_inode_present(struct nffs_inode_entry *child)
|
||||
{
|
||||
const struct nffs_inode_entry *inode_entry;
|
||||
const struct nffs_inode_entry *parent;
|
||||
struct nffs_inode inode;
|
||||
int rc;
|
||||
|
||||
/*
|
||||
* Successfully read inode data from flash
|
||||
*/
|
||||
rc = nffs_inode_from_entry(&inode, child);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
/*
|
||||
* Validate parent
|
||||
*/
|
||||
parent = inode.ni_parent;
|
||||
zassert_not_null(parent, NULL);
|
||||
zassert_true(nffs_hash_id_is_dir(parent->nie_hash_entry.nhe_id), NULL);
|
||||
|
||||
/*
|
||||
* Make sure inode is in parents child list
|
||||
*/
|
||||
SLIST_FOREACH(inode_entry, &parent->nie_child_list, nie_sibling_next) {
|
||||
if (inode_entry == child) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
zassert_true(0, NULL);
|
||||
}
|
||||
|
||||
void nffs_test_assert_block_present(struct nffs_hash_entry *block_entry)
|
||||
{
|
||||
const struct nffs_inode_entry *inode_entry;
|
||||
struct nffs_hash_entry *cur;
|
||||
struct nffs_block block;
|
||||
int rc;
|
||||
|
||||
/*
|
||||
* Successfully read block data from flash
|
||||
*/
|
||||
rc = nffs_block_from_hash_entry(&block, block_entry);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
/*
|
||||
* Validate owning inode
|
||||
*/
|
||||
inode_entry = block.nb_inode_entry;
|
||||
zassert_not_null(inode_entry, NULL);
|
||||
zassert_true(nffs_hash_id_is_file(inode_entry->nie_hash_entry.nhe_id),
|
||||
NULL);
|
||||
|
||||
/*
|
||||
* Validate that block is in owning inode's block chain
|
||||
*/
|
||||
cur = inode_entry->nie_last_block_entry;
|
||||
while (cur != NULL) {
|
||||
if (cur == block_entry) {
|
||||
return;
|
||||
}
|
||||
|
||||
rc = nffs_block_from_hash_entry(&block, cur);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
cur = block.nb_prev;
|
||||
}
|
||||
|
||||
zassert_true(0, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Recursively verify that the children of each directory are sorted
|
||||
* on the directory children linked list by filename length
|
||||
*/
|
||||
void nffs_test_assert_children_sorted(struct nffs_inode_entry *inode_entry)
|
||||
{
|
||||
struct nffs_inode_entry *child_entry;
|
||||
struct nffs_inode_entry *prev_entry;
|
||||
struct nffs_inode child_inode;
|
||||
struct nffs_inode prev_inode;
|
||||
int cmp;
|
||||
int rc;
|
||||
|
||||
prev_entry = NULL;
|
||||
SLIST_FOREACH(child_entry, &inode_entry->nie_child_list,
|
||||
nie_sibling_next) {
|
||||
rc = nffs_inode_from_entry(&child_inode, child_entry);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
if (prev_entry != NULL) {
|
||||
rc = nffs_inode_from_entry(&prev_inode, prev_entry);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
rc = nffs_inode_filename_cmp_flash(&prev_inode,
|
||||
&child_inode, &cmp);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
zassert_true(cmp < 0, NULL);
|
||||
}
|
||||
|
||||
if (nffs_hash_id_is_dir(child_entry->nie_hash_entry.nhe_id)) {
|
||||
nffs_test_assert_children_sorted(child_entry);
|
||||
}
|
||||
|
||||
prev_entry = child_entry;
|
||||
}
|
||||
}
|
||||
|
||||
void nffs_test_assert_system_once(const struct nffs_test_file_desc *root_dir)
|
||||
{
|
||||
struct nffs_inode_entry *inode_entry;
|
||||
struct nffs_hash_entry *entry;
|
||||
struct nffs_hash_entry *next;
|
||||
int i;
|
||||
|
||||
nffs_test_num_touched_entries = 0;
|
||||
nffs_test_assert_file(root_dir, nffs_root_dir, "");
|
||||
nffs_test_assert_branch_touched(nffs_root_dir);
|
||||
|
||||
/* Ensure no orphaned inodes or blocks. */
|
||||
NFFS_HASH_FOREACH(entry, i, next) {
|
||||
zassert_true(entry->nhe_flash_loc != NFFS_FLASH_LOC_NONE, NULL);
|
||||
if (nffs_hash_id_is_inode(entry->nhe_id)) {
|
||||
inode_entry = (void *)entry;
|
||||
zassert_equal(inode_entry->nie_refcnt, 1, NULL);
|
||||
if (entry->nhe_id == NFFS_ID_ROOT_DIR) {
|
||||
zassert_true(inode_entry == nffs_root_dir,
|
||||
NULL);
|
||||
} else {
|
||||
nffs_test_assert_child_inode_present(inode_entry);
|
||||
}
|
||||
} else {
|
||||
nffs_test_assert_block_present(entry);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure proper sorting. */
|
||||
nffs_test_assert_children_sorted(nffs_root_dir);
|
||||
}
|
||||
|
||||
void nffs_test_assert_system(const struct nffs_test_file_desc *root_dir,
|
||||
const struct nffs_area_desc *area_descs)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* Ensure files are as specified, and that there are no other files or
|
||||
* orphaned inodes / blocks.
|
||||
*/
|
||||
nffs_test_assert_system_once(root_dir);
|
||||
|
||||
/* Force a garbage collection cycle. */
|
||||
rc = nffs_gc(NULL);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
/* Ensure file system is still as expected. */
|
||||
nffs_test_assert_system_once(root_dir);
|
||||
|
||||
/* Clear cached data and restore from flash (i.e, simulate a reboot). */
|
||||
rc = nffs_misc_reset();
|
||||
zassert_equal(rc, 0, NULL);
|
||||
rc = nffs_restore_full(area_descs);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
/* Ensure file system is still as expected. */
|
||||
nffs_test_assert_system_once(root_dir);
|
||||
}
|
||||
|
||||
void nffs_test_assert_area_seqs(int seq1, int count1, int seq2, int count2)
|
||||
{
|
||||
struct nffs_disk_area disk_area;
|
||||
int cur1;
|
||||
int cur2;
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
cur1 = 0;
|
||||
cur2 = 0;
|
||||
|
||||
for (i = 0; i < nffs_num_areas; i++) {
|
||||
rc = nffs_flash_read(i, 0, &disk_area, sizeof(disk_area));
|
||||
zassert_equal(rc, 0, NULL);
|
||||
zassert_true(nffs_area_magic_is_set(&disk_area), NULL);
|
||||
zassert_equal(disk_area.nda_gc_seq, nffs_areas[i].na_gc_seq,
|
||||
NULL);
|
||||
if (i == nffs_scratch_area_idx) {
|
||||
zassert_equal(disk_area.nda_id, NFFS_AREA_ID_NONE,
|
||||
NULL);
|
||||
}
|
||||
|
||||
if (nffs_areas[i].na_gc_seq == seq1) {
|
||||
cur1++;
|
||||
} else if (nffs_areas[i].na_gc_seq == seq2) {
|
||||
cur2++;
|
||||
} else {
|
||||
zassert_true(0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
zassert_equal(cur1, count1, NULL);
|
||||
zassert_equal(cur2, count2, NULL);
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef H_NFFS_TEST_UTILS_
|
||||
#define H_NFFS_TEST_UTILS_
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <nffs/nffs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NFFS_MNTP "/nffs"
|
||||
|
||||
extern struct nffs_area_desc *nffs_default_area_descs;
|
||||
|
||||
struct nffs_test_block_desc {
|
||||
const char *data;
|
||||
int data_len;
|
||||
};
|
||||
|
||||
struct nffs_test_file_desc {
|
||||
const char *filename;
|
||||
int is_dir;
|
||||
const char *contents;
|
||||
int contents_len;
|
||||
struct nffs_test_file_desc *children;
|
||||
};
|
||||
|
||||
extern int nffs_test_num_touched_entries;
|
||||
|
||||
extern int flash_native_memset(u32_t offset, uint8_t c, u32_t len);
|
||||
extern u8_t nffs_test_buf[];
|
||||
|
||||
void nffs_test_util_overwrite_data(u8_t *data, u32_t data_len, u32_t addr);
|
||||
void nffs_test_util_assert_ent_name(struct fs_dirent *dirent,
|
||||
const char *expected_name);
|
||||
void nffs_test_util_assert_file_len(struct nffs_file *file, u32_t expected);
|
||||
void nffs_test_util_assert_cache_is_sane(const char *filename);
|
||||
void nffs_test_util_assert_contents(const char *filename,
|
||||
const char *contents, int contents_len);
|
||||
int nffs_test_util_block_count(const char *filename);
|
||||
void nffs_test_util_assert_block_count(const char *filename,
|
||||
int expected_count);
|
||||
void nffs_test_util_assert_cache_range(const char *filename,
|
||||
u32_t expected_cache_start,
|
||||
u32_t expected_cache_end);
|
||||
void nffs_test_util_create_file_blocks(const char *filename,
|
||||
const struct nffs_test_block_desc *blocks,
|
||||
int num_blocks);
|
||||
void nffs_test_util_create_file(const char *filename, const char *contents,
|
||||
int contents_len);
|
||||
void nffs_test_util_append_file(const char *filename, const char *contents,
|
||||
int contents_len);
|
||||
void nffs_test_copy_area(const struct nffs_area_desc *from,
|
||||
const struct nffs_area_desc *to);
|
||||
void nffs_test_util_create_subtree(const char *parent_path,
|
||||
const struct nffs_test_file_desc *elem);
|
||||
void nffs_test_util_create_tree(const struct nffs_test_file_desc *root_dir);
|
||||
|
||||
/*
|
||||
* Recursively descend directory structure
|
||||
*/
|
||||
void nffs_test_assert_file(const struct nffs_test_file_desc *file,
|
||||
struct nffs_inode_entry *inode_entry,
|
||||
const char *path);
|
||||
void nffs_test_assert_branch_touched(struct nffs_inode_entry *inode_entry);
|
||||
void nffs_test_assert_child_inode_present(struct nffs_inode_entry *child);
|
||||
void nffs_test_assert_block_present(struct nffs_hash_entry *block_entry);
|
||||
/*
|
||||
* Recursively verify that the children of each directory are sorted
|
||||
* on the directory children linked list by filename length
|
||||
*/
|
||||
void nffs_test_assert_children_sorted(struct nffs_inode_entry *inode_entry);
|
||||
void nffs_test_assert_system_once(const struct nffs_test_file_desc *root_dir);
|
||||
void nffs_test_assert_system(const struct nffs_test_file_desc *root_dir,
|
||||
const struct nffs_area_desc *area_descs);
|
||||
void nffs_test_assert_area_seqs(int seq1, int count1, int seq2, int count2);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* H_NFFS_TEST_UTILS_ */
|
|
@ -1,177 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE &file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_append(void)
|
||||
{
|
||||
struct fs_file_t file;
|
||||
struct nffs_file *nffs_file;
|
||||
struct fs_dirent info;
|
||||
char c;
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
static const struct nffs_area_desc area_descs_append[] = {
|
||||
{ 0x00000000 + TEST_FLASH_OFFSET, 128 * 1024 },
|
||||
{ 0x00020000 + TEST_FLASH_OFFSET, 128 * 1024 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
rc = nffs_format_full(area_descs_append);
|
||||
zassert_equal(rc, 0, "cannot format to nffs");
|
||||
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_file = file.filep;
|
||||
nffs_test_util_assert_file_len(nffs_file, 0);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid file length");
|
||||
|
||||
rc = fs_write(&file, "abcdefgh", 8);
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 8, "invalid file size");
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt", "abcdefgh", 8);
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
rc = fs_seek(&file, 0, FS_SEEK_END);
|
||||
zassert_equal(rc, 0, "cannot seek file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 8, "invalid file length");
|
||||
|
||||
/*
|
||||
* File position should always be at the end of a file after an append.
|
||||
* Seek to the middle prior to writing to test this.
|
||||
*/
|
||||
rc = fs_seek(&file, 2, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set position");
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 2, "invalid file length");
|
||||
|
||||
rc = fs_seek(&file, 0, FS_SEEK_END);
|
||||
zassert_equal(rc, 0, "cannot seek file");
|
||||
rc = fs_write(&file, "ijklmnop", 8);
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 16, "invalid file length");
|
||||
rc = fs_write(&file, "qrstuvwx", 8);
|
||||
nffs_test_util_assert_file_len(nffs_file, 24);
|
||||
zassert_equal(fs_tell(&file), 24, "invalid file length");
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"abcdefghijklmnopqrstuvwx", 24);
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/mydir");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
rc = fs_open(&file, NFFS_MNTP"/mydir/gaga.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
|
||||
/*** Repeated appends to a large file. */
|
||||
for (i = 0; i < 1000; i++) {
|
||||
rc = fs_stat(NFFS_MNTP"/mydir/gaga.txt", &info);
|
||||
zassert_equal(rc, 0, "fs_stat returned error");
|
||||
zassert_equal(info.size, i, "file lengths not matching");
|
||||
|
||||
c = '0' + i % 10;
|
||||
rc = fs_write(&file, &c, 1);
|
||||
}
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/mydir/gaga.txt",
|
||||
"01234567890123456789012345678901234567890123456789" /* 1 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 2 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 3 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 4 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 5 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 6 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 7 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 8 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 9 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 10 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 11 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 12 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 13 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 14 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 15 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 16 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 17 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 18 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 19 */
|
||||
"01234567890123456789012345678901234567890123456789" /* 20 */
|
||||
,
|
||||
1000);
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "myfile.txt",
|
||||
.contents = "abcdefghijklmnopqrstuvwx",
|
||||
.contents_len = 24,
|
||||
}, {
|
||||
.filename = "mydir",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "gaga.txt",
|
||||
.contents =
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789"
|
||||
,
|
||||
.contents_len = 1000,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_cache_large_file(void)
|
||||
{
|
||||
struct fs_file_t file;
|
||||
u8_t b;
|
||||
int rc;
|
||||
|
||||
/*** Setup. */
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "canot format nffs");
|
||||
|
||||
nffs_test_util_create_file(NFFS_MNTP"/myfile.txt", nffs_test_buf,
|
||||
NFFS_BLOCK_MAX_DATA_SZ_MAX * 5);
|
||||
nffs_cache_clear();
|
||||
|
||||
/* Opening a file should not cause any blocks to get cached. */
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_cache_range(NFFS_MNTP"/myfile.txt", 0, 0);
|
||||
|
||||
/* Cache first block. */
|
||||
rc = fs_seek(&file, nffs_block_max_data_sz * 0, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
rc = fs_read(&file, &b, 1);
|
||||
zassert_equal(rc, 1, "cannot read file");
|
||||
nffs_test_util_assert_cache_range(NFFS_MNTP"/myfile.txt",
|
||||
nffs_block_max_data_sz * 0,
|
||||
nffs_block_max_data_sz * 1);
|
||||
|
||||
/* Cache second block. */
|
||||
rc = fs_seek(&file, nffs_block_max_data_sz * 1, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
rc = fs_read(&file, &b, 1);
|
||||
zassert_equal(rc, 1, "cannot read file");
|
||||
nffs_test_util_assert_cache_range(NFFS_MNTP"/myfile.txt",
|
||||
nffs_block_max_data_sz * 0,
|
||||
nffs_block_max_data_sz * 2);
|
||||
|
||||
|
||||
/* Cache fourth block; prior cache should get erased. */
|
||||
rc = fs_seek(&file, nffs_block_max_data_sz * 3, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
rc = fs_read(&file, &b, 1);
|
||||
zassert_equal(rc, 1, "cannot read file");
|
||||
nffs_test_util_assert_cache_range(NFFS_MNTP"/myfile.txt",
|
||||
nffs_block_max_data_sz * 3,
|
||||
nffs_block_max_data_sz * 4);
|
||||
|
||||
/* Cache second and third blocks. */
|
||||
rc = fs_seek(&file, nffs_block_max_data_sz * 1, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
rc = fs_read(&file, &b, 1);
|
||||
zassert_equal(rc, 1, "cannot read file");
|
||||
nffs_test_util_assert_cache_range(NFFS_MNTP"/myfile.txt",
|
||||
nffs_block_max_data_sz * 1,
|
||||
nffs_block_max_data_sz * 4);
|
||||
|
||||
/* Cache fifth block. */
|
||||
rc = fs_seek(&file, nffs_block_max_data_sz * 4, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
rc = fs_read(&file, &b, 1);
|
||||
zassert_equal(rc, 1, "cannot read file");
|
||||
nffs_test_util_assert_cache_range(NFFS_MNTP"/myfile.txt",
|
||||
nffs_block_max_data_sz * 1,
|
||||
nffs_block_max_data_sz * 5);
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <nffs/os.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
static u8_t data1[] = {0x43};
|
||||
|
||||
void test_corrupt_block(void)
|
||||
{
|
||||
struct fs_file_t fs_file;
|
||||
struct nffs_file *file;
|
||||
struct nffs_block block;
|
||||
uint32_t flash_offset;
|
||||
uint32_t area_offset;
|
||||
uint8_t area_idx;
|
||||
u8_t off; /* offset to corrupt */
|
||||
int rc;
|
||||
struct nffs_disk_block ndb;
|
||||
|
||||
/* Setup. */
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, NULL);
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/mydir");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
nffs_test_util_create_file(NFFS_MNTP"/mydir/a", "aaaa", 4);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/mydir/b", "bbbb", 4);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/mydir/c", "cccc", 4);
|
||||
|
||||
/* Add a second block to the 'b' file. */
|
||||
nffs_test_util_append_file(NFFS_MNTP"/mydir/b", "1234", 4);
|
||||
|
||||
/* Corrupt the 'b' file; overwrite the second block's magic number. */
|
||||
rc = fs_open(&fs_file, NFFS_MNTP"/mydir/b");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
|
||||
file = fs_file.filep;
|
||||
rc = nffs_block_from_hash_entry(&block,
|
||||
file->nf_inode_entry->nie_last_block_entry);
|
||||
zassert_equal(rc, 0, "block from hash entry error");
|
||||
|
||||
nffs_flash_loc_expand(block.nb_hash_entry->nhe_flash_loc, &area_idx,
|
||||
&area_offset);
|
||||
flash_offset = nffs_areas[area_idx].na_offset + area_offset;
|
||||
|
||||
/*
|
||||
* Overwriting the reserved16 field should invalidate the CRC
|
||||
*/
|
||||
off = (char *)&ndb.reserved16 - (char *)&ndb;
|
||||
nffs_test_util_overwrite_data(data1, sizeof(data1), flash_offset + off);
|
||||
|
||||
zassert_equal(rc, 0, "flash native memset error");
|
||||
|
||||
/*
|
||||
* Write a fourth file. This file should get restored even though the
|
||||
* previous object has an invalid magic number.
|
||||
*/
|
||||
nffs_test_util_create_file(NFFS_MNTP"/mydir/d", "dddd", 4);
|
||||
|
||||
rc = nffs_misc_reset();
|
||||
zassert_equal(rc, 0, "cannot reset nffs");
|
||||
rc = nffs_restore_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot detect nffs");
|
||||
|
||||
/*
|
||||
* The entire second block should be removed; the file should only
|
||||
* contain the first block.
|
||||
*/
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "mydir",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "a",
|
||||
.contents = "aaaa",
|
||||
.contents_len = 4,
|
||||
}, {
|
||||
.filename = "c",
|
||||
.contents = "cccc",
|
||||
.contents_len = 4,
|
||||
}, {
|
||||
.filename = "d",
|
||||
.contents = "dddd",
|
||||
.contents_len = 4,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_corrupt_scratch(void)
|
||||
{
|
||||
int non_scratch_id;
|
||||
int scratch_id;
|
||||
int rc;
|
||||
|
||||
static const struct nffs_area_desc area_descs_two[] = {
|
||||
{ 0x00020000, 128 * 1024 },
|
||||
{ 0x00040000, 128 * 1024 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
nffs_current_area_descs = (struct nffs_area_desc *)area_descs_two;
|
||||
|
||||
/*** Setup. */
|
||||
rc = nffs_format_full(area_descs_two);
|
||||
zassert_equal(rc, 0, "cannot format file");
|
||||
|
||||
nffs_test_util_create_file(NFFS_MNTP"/myfile.txt", "contents", 8);
|
||||
|
||||
/* Copy the current contents of the non-scratch area to the scratch area.
|
||||
* This will make the scratch area look like it only partially
|
||||
* participated in a garbage collection cycle.
|
||||
*/
|
||||
scratch_id = nffs_scratch_area_idx;
|
||||
non_scratch_id = scratch_id ^ 1;
|
||||
nffs_test_copy_area(area_descs_two + non_scratch_id,
|
||||
area_descs_two + nffs_scratch_area_idx);
|
||||
|
||||
/* Add some more data to the non-scratch area. */
|
||||
rc = fs_mkdir(NFFS_MNTP"/mydir");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
/*
|
||||
* Ensure the file system is successfully detected and valid, despite
|
||||
* corruption.
|
||||
*/
|
||||
|
||||
rc = nffs_misc_reset();
|
||||
zassert_equal(rc, 0, "cannot reset nffs");
|
||||
|
||||
rc = nffs_restore_full(area_descs_two);
|
||||
zassert_equal(rc, 0, "cannot detect nffs");
|
||||
|
||||
zassert_equal(nffs_scratch_area_idx, scratch_id,
|
||||
"scratch index not matching");
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "mydir",
|
||||
.is_dir = 1,
|
||||
}, {
|
||||
.filename = "myfile.txt",
|
||||
.contents = "contents",
|
||||
.contents_len = 8,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, area_descs_two);
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_gc(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
static const struct nffs_area_desc area_descs_two[] = {
|
||||
{ 0x00000000 + TEST_FLASH_OFFSET, 128 * 1024 },
|
||||
{ 0x00020000 + TEST_FLASH_OFFSET, 128 * 1024 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
struct nffs_test_block_desc blocks[8] = { {
|
||||
.data = "1",
|
||||
.data_len = 1,
|
||||
}, {
|
||||
.data = "2",
|
||||
.data_len = 1,
|
||||
}, {
|
||||
.data = "3",
|
||||
.data_len = 1,
|
||||
}, {
|
||||
.data = "4",
|
||||
.data_len = 1,
|
||||
}, {
|
||||
.data = "5",
|
||||
.data_len = 1,
|
||||
}, {
|
||||
.data = "6",
|
||||
.data_len = 1,
|
||||
}, {
|
||||
.data = "7",
|
||||
.data_len = 1,
|
||||
}, {
|
||||
.data = "8",
|
||||
.data_len = 1,
|
||||
} };
|
||||
|
||||
|
||||
rc = nffs_format_full(area_descs_two);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 8);
|
||||
|
||||
nffs_gc(NULL);
|
||||
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 1);
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
extern struct k_mem_slab nffs_block_entry_pool;
|
||||
|
||||
void test_gc_on_oom(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/*** Setup. */
|
||||
/* Ensure all areas are the same size. */
|
||||
static const struct nffs_area_desc area_descs_two[] = {
|
||||
{ 0x00000000 + TEST_FLASH_OFFSET, 16 * 1024 },
|
||||
{ 0x00004000 + TEST_FLASH_OFFSET, 16 * 1024 },
|
||||
{ 0x00008000 + TEST_FLASH_OFFSET, 16 * 1024 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
rc = nffs_format_full(area_descs_two);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
/* Leak block entries until only four are left. */
|
||||
/*
|
||||
* XXX: This is ridiculous. Need to fix nffs configuration so that the
|
||||
* caller passes a config object rather than writing to a global
|
||||
* variable.
|
||||
*/
|
||||
while (k_mem_slab_num_free_get(&nffs_block_entry_pool) != 4) {
|
||||
nffs_block_entry_alloc();
|
||||
}
|
||||
|
||||
/*** Write 4 data blocks. */
|
||||
struct nffs_test_block_desc blocks[4] = { {
|
||||
.data = "1",
|
||||
.data_len = 1,
|
||||
}, {
|
||||
.data = "2",
|
||||
.data_len = 1,
|
||||
}, {
|
||||
.data = "3",
|
||||
.data_len = 1,
|
||||
}, {
|
||||
.data = "4",
|
||||
.data_len = 1,
|
||||
} };
|
||||
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 4);
|
||||
|
||||
zassert_equal(k_mem_slab_num_free_get(&nffs_block_entry_pool), 0,
|
||||
"file blocks problem");
|
||||
|
||||
/* Attempt another one-byte write. This should trigger a garbage
|
||||
* collection cycle, resulting in the four blocks being collated. The
|
||||
* fifth write consumes an additional block, resulting in 2 out of 4
|
||||
* blocks in use.
|
||||
*/
|
||||
nffs_test_util_append_file(NFFS_MNTP"/myfile.txt", "5", 1);
|
||||
|
||||
zassert_equal(k_mem_slab_num_free_get(&nffs_block_entry_pool), 2,
|
||||
"file blocks problem");
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "myfile.txt",
|
||||
.contents = "12345",
|
||||
.contents_len = 5,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, area_descs_two);
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <nffs/os.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
/*
|
||||
* This test no longer works with the current implementation. The
|
||||
* expectation is that intermediate blocks can be removed and the old
|
||||
* method of finding the last current block after restore will allow the
|
||||
* file to be salvaged. Instead, the file should be removed and all data
|
||||
* declared invalid.
|
||||
*/
|
||||
void test_incomplete_block(void)
|
||||
{
|
||||
static u8_t corrupt_data[] = { 0xff, 0xff };
|
||||
struct nffs_file *file;
|
||||
struct nffs_block block;
|
||||
struct fs_file_t fs_file;
|
||||
uint32_t flash_offset;
|
||||
uint32_t area_offset;
|
||||
uint8_t area_idx;
|
||||
int rc;
|
||||
|
||||
/*** Setup. */
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/mydir");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
nffs_test_util_create_file(NFFS_MNTP"/mydir/a", "aaaa", 4);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/mydir/b", "bbbb", 4);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/mydir/c", "cccc", 4);
|
||||
|
||||
/* Add a second block to the 'b' file. */
|
||||
nffs_test_util_append_file(NFFS_MNTP"/mydir/b", "1234", 4);
|
||||
|
||||
/*
|
||||
* Corrupt the 'b' file; make it look like the second block only got
|
||||
* half written.
|
||||
*/
|
||||
rc = fs_open(&fs_file, NFFS_MNTP"/mydir/b");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
file = fs_file.filep;
|
||||
|
||||
rc = nffs_block_from_hash_entry(&block,
|
||||
file->nf_inode_entry->nie_last_block_entry);
|
||||
zassert_equal(rc, 0, "block from hash entry error");
|
||||
|
||||
nffs_flash_loc_expand(block.nb_hash_entry->nhe_flash_loc, &area_idx,
|
||||
&area_offset);
|
||||
flash_offset = nffs_areas[area_idx].na_offset + area_offset;
|
||||
|
||||
/*
|
||||
* Overwrite block data - the CRC check should pick this up
|
||||
*/
|
||||
nffs_test_util_overwrite_data(corrupt_data, sizeof(corrupt_data),
|
||||
flash_offset +
|
||||
sizeof(struct nffs_disk_block) + 2);
|
||||
|
||||
rc = nffs_misc_reset();
|
||||
zassert_equal(rc, 0, "nffs misc reset error");
|
||||
rc = nffs_restore_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "nffs detect error");
|
||||
|
||||
/*
|
||||
* OLD: The entire second block should be removed; the file should only
|
||||
* contain the first block.
|
||||
* Unless we can salvage the block, the entire file should probably be
|
||||
* removed. This is a contrived example which generates bad data on the
|
||||
* what happens to be the last block, but corruption can actually occur
|
||||
* in any block. Sweep should be updated to search look for blocks that
|
||||
* don't have a correct prev_id and then decide whether to delete the
|
||||
* owning inode. XXX
|
||||
*/
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "mydir",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "a",
|
||||
.contents = "aaaa",
|
||||
.contents_len = 4,
|
||||
}, {
|
||||
.filename = "c",
|
||||
.contents = "cccc",
|
||||
.contents_len = 4,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
extern const struct nffs_test_file_desc *nffs_test_system_01;
|
||||
extern const struct nffs_test_file_desc *nffs_test_system_01_rm_1014_mk10;
|
||||
|
||||
void test_large_system(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* Setup. */
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format");
|
||||
nffs_test_util_create_tree(nffs_test_system_01);
|
||||
|
||||
nffs_test_assert_system(nffs_test_system_01, nffs_current_area_descs);
|
||||
|
||||
rc = fs_unlink(NFFS_MNTP"/lvl1dir-0000");
|
||||
zassert_equal(rc, 0, "cannot delete file");
|
||||
|
||||
rc = fs_unlink(NFFS_MNTP"/lvl1dir-0004");
|
||||
zassert_equal(rc, 0, "cannot delete file");
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/lvl1dir-0000");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
nffs_test_assert_system(nffs_test_system_01_rm_1014_mk10, nffs_current_area_descs);
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
#define TEST_CONTENT_LEN (1024 * 4)
|
||||
|
||||
void test_large_unlink(void)
|
||||
{
|
||||
/* It should not be necessary to initialize this array, but the libgcc
|
||||
* version of strcmp triggers a "Conditional jump or move depends on
|
||||
* uninitialised value(s)" valgrind warning.
|
||||
*/
|
||||
char filename[256] = { 0 };
|
||||
int rc;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
snprintf(filename, sizeof(filename), NFFS_MNTP"/dir0_%d", i);
|
||||
rc = fs_mkdir(filename);
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
for (j = 0; j < 5; j++) {
|
||||
snprintf(filename, sizeof(filename),
|
||||
NFFS_MNTP"/dir0_%d/dir1_%d", i, j);
|
||||
rc = fs_mkdir(filename);
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
for (k = 0; k < 5; k++) {
|
||||
snprintf(filename, sizeof(filename),
|
||||
NFFS_MNTP"/dir0_%d/dir1_%d/file2_%d",
|
||||
i, j, k);
|
||||
nffs_test_util_create_file(filename,
|
||||
nffs_test_buf,
|
||||
TEST_CONTENT_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < 15; j++) {
|
||||
snprintf(filename, sizeof(filename),
|
||||
NFFS_MNTP"/dir0_%d/file1_%d", i, j);
|
||||
nffs_test_util_create_file(filename, nffs_test_buf,
|
||||
TEST_CONTENT_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
snprintf(filename, sizeof(filename), NFFS_MNTP"/dir0_%d", i);
|
||||
rc = fs_unlink(filename);
|
||||
zassert_equal(rc, 0, "cannot unlink file");
|
||||
}
|
||||
|
||||
/* The entire file system should be empty. */
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
|
||||
#define TEST_CONTENT_LEN (NFFS_BLOCK_MAX_DATA_SZ_MAX * 5)
|
||||
|
||||
void test_large_write(void)
|
||||
{
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
static const struct nffs_area_desc area_descs_two[] = {
|
||||
{ 0x00000000 + TEST_FLASH_OFFSET, 128 * 1024 },
|
||||
{ 0x00020000 + TEST_FLASH_OFFSET, 128 * 1024 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
/*** Setup. */
|
||||
rc = nffs_format_full(area_descs_two);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
for (i = 0; i < TEST_CONTENT_LEN; i++) {
|
||||
nffs_test_buf[i] = i;
|
||||
}
|
||||
|
||||
nffs_test_util_create_file(NFFS_MNTP"/myfile.txt", nffs_test_buf,
|
||||
TEST_CONTENT_LEN);
|
||||
|
||||
/*
|
||||
* Ensure large write was split across the appropriate number of data
|
||||
* blocks.
|
||||
*/
|
||||
zassert_equal(nffs_test_util_block_count(NFFS_MNTP"/myfile.txt"),
|
||||
TEST_CONTENT_LEN / NFFS_BLOCK_MAX_DATA_SZ_MAX,
|
||||
"blocks were not split");
|
||||
|
||||
/*
|
||||
* Garbage collect and then ensure the large file is still properly
|
||||
* divided according to max data block size.
|
||||
*/
|
||||
nffs_gc(NULL);
|
||||
zassert_equal(nffs_test_util_block_count(NFFS_MNTP"/myfile.txt"),
|
||||
TEST_CONTENT_LEN / NFFS_BLOCK_MAX_DATA_SZ_MAX,
|
||||
"not properly divided");
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "myfile.txt",
|
||||
.contents = nffs_test_buf,
|
||||
.contents_len = TEST_CONTENT_LEN,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, area_descs_two);
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
|
||||
void test_long_filename(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/*** Setup. */
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
nffs_test_util_create_file(NFFS_MNTP"/12345678901234567890.txt",
|
||||
"contents", 8);
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/longdir12345678901234567890");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
rc = nffs_path_rename("/12345678901234567890.txt",
|
||||
"/longdir12345678901234567890/12345678901234567890.txt");
|
||||
zassert_equal(rc, 0, "cannot rename file");
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "longdir12345678901234567890",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "/12345678901234567890.txt",
|
||||
.contents = "contents",
|
||||
.contents_len = 8,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <nffs/os.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
static u8_t data1[] = {0xaa};
|
||||
|
||||
void test_lost_found(void)
|
||||
{
|
||||
char buf[32];
|
||||
struct nffs_inode_entry *inode_entry;
|
||||
uint32_t flash_offset;
|
||||
uint32_t area_offset;
|
||||
uint8_t area_idx;
|
||||
int rc;
|
||||
struct nffs_disk_inode ndi;
|
||||
u8_t off; /* calculated offset for memset */
|
||||
|
||||
/*** Setup. */
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/mydir");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
rc = fs_mkdir(NFFS_MNTP"/mydir/dir1");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
nffs_test_util_create_file(NFFS_MNTP"/mydir/file1", "aaaa", 4);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/mydir/dir1/file2", "bbbb", 4);
|
||||
|
||||
/* Corrupt the mydir inode. */
|
||||
rc = nffs_path_find_inode_entry("/mydir", &inode_entry);
|
||||
zassert_equal(rc, 0, "path to find inode error");
|
||||
|
||||
snprintf(buf, sizeof(buf), "%lu",
|
||||
(unsigned long)inode_entry->nie_hash_entry.nhe_id);
|
||||
|
||||
nffs_flash_loc_expand(inode_entry->nie_hash_entry.nhe_flash_loc,
|
||||
&area_idx, &area_offset);
|
||||
flash_offset = nffs_areas[area_idx].na_offset + area_offset;
|
||||
|
||||
/*
|
||||
* Overwrite the sequence number - should be detected as CRC corruption
|
||||
*/
|
||||
off = (char *)&ndi.ndi_seq - (char *)&ndi;
|
||||
|
||||
nffs_test_util_overwrite_data(data1, sizeof(data1), flash_offset + off);
|
||||
|
||||
/* Clear cached data and restore from flash (i.e, simulate a reboot). */
|
||||
rc = nffs_misc_reset();
|
||||
zassert_equal(rc, 0, "nffs reset error");
|
||||
rc = nffs_restore_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "nffs detect error");
|
||||
|
||||
/* All contents should now be in the lost+found dir. */
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "lost+found",
|
||||
.is_dir = 1,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} }
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_many_children(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/*** Setup. */
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
nffs_test_util_create_file(NFFS_MNTP"/zasdf", NULL, 0);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/FfD", NULL, 0);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/4Zvv", NULL, 0);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/*(*2fs", NULL, 0);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/pzzd", NULL, 0);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/zasdf0", NULL, 0);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/23132.bin", NULL, 0);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/asldkfjaldskfadsfsdf.txt",
|
||||
NULL, 0);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/sdgaf", NULL, 0);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/939302**", NULL, 0);
|
||||
rc = fs_mkdir(NFFS_MNTP"/dir");
|
||||
nffs_test_util_create_file(NFFS_MNTP"/dir/itw82", NULL, 0);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/dir/124", NULL, 0);
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) {
|
||||
{ "zasdf" },
|
||||
{ "FfD" },
|
||||
{ "4Zvv" },
|
||||
{ "*(*2fs" },
|
||||
{ "pzzd" },
|
||||
{ "zasdf0" },
|
||||
{ "23132.bin" },
|
||||
{ "asldkfjaldskfadsfsdf.txt" },
|
||||
{ "sdgaf" },
|
||||
{ "939302**" },
|
||||
{
|
||||
.filename = "dir",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) {
|
||||
{ "itw82" },
|
||||
{ "124" },
|
||||
{ NULL },
|
||||
},
|
||||
},
|
||||
{ NULL },
|
||||
}
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <fs/fs.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_mkdir(void)
|
||||
{
|
||||
struct fs_file_t file;
|
||||
int rc;
|
||||
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/a/b/c/d");
|
||||
zassert_equal(rc, -ENOENT, "cannot create directory");
|
||||
|
||||
rc = fs_mkdir("asdf");
|
||||
zassert_equal(rc, -EINVAL, "cannot create directory");
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/a");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/a/b");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/a/b/c");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/a/b/c/d");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
rc = fs_open(&file, NFFS_MNTP"/a/b/c/d/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "a",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "b",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "c",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "d",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "myfile.txt",
|
||||
.contents = NULL,
|
||||
.contents_len = 0,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/*
|
||||
* @filesystem
|
||||
* @brief test_filesystem
|
||||
* Demonstrates the ZEPHYR File System APIs
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <device.h>
|
||||
#include <fs/fs.h>
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
#include "nffs_test_utils.h"
|
||||
|
||||
/* NFFS work area strcut */
|
||||
static struct nffs_flash_desc flash_desc;
|
||||
|
||||
/* mounting info */
|
||||
static struct fs_mount_t nffs_mnt = {
|
||||
.type = FS_NFFS,
|
||||
.mnt_point = "/nffs",
|
||||
.fs_data = &flash_desc,
|
||||
};
|
||||
|
||||
static int test_mount(void)
|
||||
{
|
||||
struct device *flash_dev;
|
||||
int res;
|
||||
|
||||
flash_dev = device_get_binding(CONFIG_FS_NFFS_FLASH_DEV_NAME);
|
||||
if (!flash_dev) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* set backend storage dev */
|
||||
nffs_mnt.storage_dev = flash_dev;
|
||||
|
||||
res = fs_mount(&nffs_mnt);
|
||||
if (res < 0) {
|
||||
TC_PRINT("Error mounting nffs [%d]\n", res);
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
return TC_PASS;
|
||||
}
|
||||
|
||||
void test_fs_mount(void)
|
||||
{
|
||||
zassert_true(test_mount() == TC_PASS, NULL);
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Codecoup
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <ztest.h>
|
||||
#include <fs/fs.h>
|
||||
|
||||
void test_fs_mount(void);
|
||||
void test_mkdir(void);
|
||||
void test_gc_on_oom(void);
|
||||
void test_incomplete_block(void);
|
||||
void test_lost_found(void);
|
||||
void test_readdir(void);
|
||||
void test_large_system(void);
|
||||
void test_corrupt_block(void);
|
||||
void test_split_file(void);
|
||||
void test_large_unlink(void);
|
||||
void test_corrupt_scratch(void);
|
||||
void test_unlink(void);
|
||||
void test_append(void);
|
||||
void test_rename(void);
|
||||
void test_truncate(void);
|
||||
void test_open(void);
|
||||
void test_wear_level(void);
|
||||
void test_long_filename(void);
|
||||
void test_overwrite_one(void);
|
||||
void test_many_children(void);
|
||||
void test_gc(void);
|
||||
void test_overwrite_many(void);
|
||||
void test_overwrite_two(void);
|
||||
void test_overwrite_three(void);
|
||||
void test_read(void);
|
||||
void test_cache_large_file(void);
|
||||
void test_large_write(void);
|
||||
void test_performance(void);
|
||||
|
||||
#if CONFIG_BOARD_QEMU_X86
|
||||
static struct nffs_area_desc nffs_selftest_area_descs[] = {
|
||||
{ 0x00000000, 16 * 1024 },
|
||||
{ 0x00004000, 16 * 1024 },
|
||||
{ 0x00008000, 16 * 1024 },
|
||||
{ 0x0000c000, 16 * 1024 },
|
||||
{ 0x00010000, 64 * 1024 },
|
||||
{ 0x00020000, 128 * 1024 },
|
||||
{ 0x00040000, 128 * 1024 },
|
||||
{ 0x00060000, 128 * 1024 },
|
||||
{ 0x00080000, 128 * 1024 },
|
||||
{ 0x000a0000, 128 * 1024 },
|
||||
{ 0x000c0000, 128 * 1024 },
|
||||
{ 0x000e0000, 128 * 1024 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
#else
|
||||
static struct nffs_area_desc nffs_selftest_area_descs[] = {
|
||||
{ 0x00020000, 2 * 4096 },
|
||||
{ 0x00022000, 2 * 4096 },
|
||||
{ 0x00024000, 2 * 4096 },
|
||||
{ 0x00026000, 2 * 4096 },
|
||||
{ 0x00028000, 2 * 4096 },
|
||||
{ 0x0002a000, 2 * 4096 },
|
||||
{ 0x0002c000, 2 * 4096 },
|
||||
{ 0x00030000, 2 * 4096 },
|
||||
{ 0x00032000, 2 * 4096 },
|
||||
{ 0x00034000, 2 * 4096 },
|
||||
{ 0x00036000, 2 * 4096 },
|
||||
{ 0x00038000, 2 * 4096 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
#endif
|
||||
|
||||
static struct nffs_area_desc *save_area_descs;
|
||||
|
||||
static void test_setup(void)
|
||||
{
|
||||
save_area_descs = nffs_current_area_descs;
|
||||
nffs_current_area_descs = nffs_selftest_area_descs;
|
||||
}
|
||||
|
||||
static void test_teardown(void)
|
||||
{
|
||||
nffs_current_area_descs = save_area_descs;
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
|
||||
void test_open(void)
|
||||
{
|
||||
struct fs_file_t file;
|
||||
struct fs_dir_t dir;
|
||||
int rc;
|
||||
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
/*** Fail to open an invalid path (not rooted). */
|
||||
rc = fs_open(&file, "file");
|
||||
zassert_equal(rc, -EINVAL, "failed to detect invalid path");
|
||||
|
||||
/*** Fail to open a directory (root directory). */
|
||||
rc = fs_open(&file, "/");
|
||||
zassert_equal(rc, -EINVAL, "failed to detect invalid directory");
|
||||
|
||||
/*** Fail to open a child of a nonexistent directory. */
|
||||
rc = fs_open(&file, "/dir/myfile.txt");
|
||||
zassert_equal(rc, -ENOENT, "failed to detect nonexistent directory");
|
||||
rc = fs_opendir(&dir, "/dir");
|
||||
zassert_equal(rc, -ENOENT, "failed to detect nonexistent directory");
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/dir");
|
||||
zassert_equal(rc, 0, "failed to open directory");
|
||||
|
||||
/*** Fail to open a directory. */
|
||||
rc = fs_open(&file, NFFS_MNTP"/dir");
|
||||
zassert_equal(rc, -EINVAL, "failed to open a directory");
|
||||
|
||||
/*** Successfully open an existing file for reading. */
|
||||
nffs_test_util_create_file(NFFS_MNTP"/dir/file.txt", "1234567890", 10);
|
||||
rc = fs_open(&file, NFFS_MNTP"/dir/file.txt");
|
||||
zassert_equal(rc, 0, "failed to open a file");
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
/*** Successfully open an nonexistent file for writing. */
|
||||
rc = fs_open(&file, NFFS_MNTP"/dir/file2.txt");
|
||||
zassert_equal(rc, 0, "cannot open nonexistent file for writing");
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
/*** Ensure the file can be reopened. */
|
||||
rc = fs_open(&file, NFFS_MNTP"/dir/file.txt");
|
||||
zassert_equal(rc, 0, "cannot reopen file");
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close reopened file");
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_overwrite_many(void)
|
||||
{
|
||||
struct nffs_test_block_desc *blocks = (struct nffs_test_block_desc[]) { {
|
||||
.data = "abcdefgh",
|
||||
.data_len = 8,
|
||||
}, {
|
||||
.data = "ijklmnop",
|
||||
.data_len = 8,
|
||||
}, {
|
||||
.data = "qrstuvwx",
|
||||
.data_len = 8,
|
||||
} };
|
||||
|
||||
struct fs_file_t file;
|
||||
struct nffs_file *nffs_file;
|
||||
int rc;
|
||||
|
||||
/*** Setup. */
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
/*** Overwrite middle of first block. */
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 3);
|
||||
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
nffs_file = file.filep;
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 24);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid file length");
|
||||
rc = fs_seek(&file, 3, FS_SEEK_SET);
|
||||
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 24);
|
||||
zassert_equal(fs_tell(&file), 3, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "12", 2);
|
||||
nffs_test_util_assert_file_len(nffs_file, 24);
|
||||
zassert_equal(fs_tell(&file), 5, "invalid file length");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"abc12fghijklmnopqrstuvwx", 24);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 3);
|
||||
|
||||
/*** Overwrite end of first block, start of second. */
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 3);
|
||||
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 24);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid file length");
|
||||
|
||||
rc = fs_seek(&file, 6, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 24);
|
||||
zassert_equal(fs_tell(&file), 6, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "1234", 4);
|
||||
nffs_test_util_assert_file_len(nffs_file, 24);
|
||||
zassert_equal(fs_tell(&file), 10, "invalid pos in file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"abcdef1234klmnopqrstuvwx", 24);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 3);
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "myfile.txt",
|
||||
.contents = "abcdef1234klmnopqrstuvwx",
|
||||
.contents_len = 24,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_overwrite_one(void)
|
||||
{
|
||||
struct fs_file_t file;
|
||||
struct nffs_file *nffs_file;
|
||||
int rc;
|
||||
|
||||
/*** Setup. */
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
nffs_test_util_append_file(NFFS_MNTP"/myfile.txt", "abcdefgh", 8);
|
||||
|
||||
/*** Overwrite within one block (middle). */
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
nffs_file = file.filep;
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_seek(&file, 3, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 3, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "12", 2);
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 5, "cannot get pos in file");
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt", "abc12fgh", 8);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 1);
|
||||
|
||||
/*** Overwrite within one block (start). */
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "xy", 2);
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 2, "invalid pos in file");
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt", "xyc12fgh", 8);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 1);
|
||||
|
||||
/*** Overwrite within one block (end). */
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_seek(&file, 6, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 6, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "<>", 2);
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 8, "invalid pos in file");
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt", "xyc12f<>", 8);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 1);
|
||||
|
||||
/*** Overwrite one block middle, extend. */
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_seek(&file, 4, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 8);
|
||||
zassert_equal(fs_tell(&file), 4, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "abcdefgh", 8);
|
||||
nffs_test_util_assert_file_len(nffs_file, 12);
|
||||
zassert_equal(fs_tell(&file), 12, "invalid pos in file");
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"xyc1abcdefgh", 12);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 1);
|
||||
|
||||
/*** Overwrite one block start, extend. */
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 12);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "abcdefghijklmnop", 16);
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 16, "invalid pos in file");
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"abcdefghijklmnop", 16);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 1);
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "myfile.txt",
|
||||
.contents = "abcdefghijklmnop",
|
||||
.contents_len = 16,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,172 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_overwrite_three(void)
|
||||
{
|
||||
struct nffs_test_block_desc *blocks = (struct nffs_test_block_desc[]) {
|
||||
{
|
||||
.data = "abcdefgh",
|
||||
.data_len = 8,
|
||||
}, {
|
||||
.data = "ijklmnop",
|
||||
.data_len = 8,
|
||||
}, {
|
||||
.data = "qrstuvwx",
|
||||
.data_len = 8,
|
||||
}
|
||||
};
|
||||
|
||||
struct fs_file_t file;
|
||||
int rc;
|
||||
|
||||
/*** Setup. */
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
/*** Overwrite three blocks (middle). */
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 3);
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(file.filep, 24);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_seek(&file, 6, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
nffs_test_util_assert_file_len(file.filep, 24);
|
||||
zassert_equal(fs_tell(&file), 6, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "1234567890!@", 12);
|
||||
nffs_test_util_assert_file_len(file.filep, 24);
|
||||
zassert_equal(fs_tell(&file), 18, "invalid pos in file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"abcdef1234567890!@stuvwx", 24);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 3);
|
||||
|
||||
/*** Overwrite three blocks (start). */
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 3);
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(file.filep, 24);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "1234567890!@#$%^&*()", 20);
|
||||
nffs_test_util_assert_file_len(file.filep, 24);
|
||||
zassert_equal(fs_tell(&file), 20, "invalid pos in file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"1234567890!@#$%^&*()uvwx", 24);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 3);
|
||||
|
||||
/*** Overwrite three blocks (end). */
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 3);
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(file.filep, 24);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_seek(&file, 6, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
nffs_test_util_assert_file_len(file.filep, 24);
|
||||
zassert_equal(fs_tell(&file), 6, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "1234567890!@#$%^&*", 18);
|
||||
nffs_test_util_assert_file_len(file.filep, 24);
|
||||
zassert_equal(fs_tell(&file), 24, "invalid pos in file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"abcdef1234567890!@#$%^&*", 24);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 3);
|
||||
|
||||
/*** Overwrite three blocks middle, extend. */
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 3);
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(file.filep, 24);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_seek(&file, 6, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
nffs_test_util_assert_file_len(file.filep, 24);
|
||||
zassert_equal(fs_tell(&file), 6, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "1234567890!@#$%^&*()", 20);
|
||||
nffs_test_util_assert_file_len(file.filep, 26);
|
||||
zassert_equal(fs_tell(&file), 26, "invalid pos in file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"abcdef1234567890!@#$%^&*()", 26);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 3);
|
||||
|
||||
/*** Overwrite three blocks start, extend. */
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 3);
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(file.filep, 24);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_seek(&file, 0, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
rc = fs_write(&file, "1234567890!@#$%^&*()abcdefghij", 30);
|
||||
nffs_test_util_assert_file_len(file.filep, 30);
|
||||
zassert_equal(fs_tell(&file), 30, "invalid pos in file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"1234567890!@#$%^&*()abcdefghij", 30);
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "myfile.txt",
|
||||
.contents = "1234567890!@#$%^&*()abcdefghij",
|
||||
.contents_len = 30,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,169 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_overwrite_two(void)
|
||||
{
|
||||
struct nffs_test_block_desc *blocks = (struct nffs_test_block_desc[]) {
|
||||
{
|
||||
.data = "abcdefgh",
|
||||
.data_len = 8,
|
||||
}, {
|
||||
.data = "ijklmnop",
|
||||
.data_len = 8,
|
||||
}
|
||||
};
|
||||
|
||||
struct fs_file_t file;
|
||||
struct nffs_file *nffs_file;
|
||||
int rc;
|
||||
|
||||
/*** Setup. */
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
/*** Overwrite two blocks (middle). */
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 2);
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
nffs_file = file.filep;
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_seek(&file, 7, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 7, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "123", 3);
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 10, "invalid pos in file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"abcdefg123klmnop", 16);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 2);
|
||||
|
||||
/*** Overwrite two blocks (start). */
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 2);
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "ABCDEFGHIJ", 10);
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 10, "invalid pos in file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"ABCDEFGHIJklmnop", 16);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 2);
|
||||
|
||||
/*** Overwrite two blocks (end). */
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 2);
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_seek(&file, 6, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 6, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "1234567890", 10);
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 16, "invalid pos in file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"abcdef1234567890", 16);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 2);
|
||||
|
||||
/*** Overwrite two blocks middle, extend. */
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 2);
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_seek(&file, 6, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 6, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "1234567890!@#$", 14);
|
||||
nffs_test_util_assert_file_len(nffs_file, 20);
|
||||
zassert_equal(fs_tell(&file), 20, "invalid pos in file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"abcdef1234567890!@#$", 20);
|
||||
nffs_test_util_assert_block_count(NFFS_MNTP"/myfile.txt", 2);
|
||||
|
||||
/*** Overwrite two blocks start, extend. */
|
||||
nffs_test_util_create_file_blocks(NFFS_MNTP"/myfile.txt", blocks, 2);
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(nffs_file, 16);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_write(&file, "1234567890!@#$%^&*()", 20);
|
||||
nffs_test_util_assert_file_len(nffs_file, 20);
|
||||
zassert_equal(fs_tell(&file), 20, "invlid pos in file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile.txt",
|
||||
"1234567890!@#$%^&*()", 20);
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "myfile.txt",
|
||||
.contents = "1234567890!@#$%^&*()",
|
||||
.contents_len = 20,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,170 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Codecoup
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
#include <timestamp.h>
|
||||
#include <sys_clock.h>
|
||||
|
||||
#define TEST_NUM_FILES 500
|
||||
#define RW_DATA_LENGTH (128 * 1024)
|
||||
#define RW_CHUNK_LENGTH 256
|
||||
|
||||
#define TEST_DATA_LEN (1024 * 24)
|
||||
|
||||
static const struct nffs_area_desc area_descs[] = {
|
||||
{ 0x00020000, 16384 },
|
||||
{ 0x00024000, 16384 },
|
||||
{ 0x00028000, 16384 },
|
||||
{ 0x0002c000, 16384 },
|
||||
{ 0x00030000, 16384 },
|
||||
{ 0x00034000, 16384 },
|
||||
{ 0x00038000, 16384 },
|
||||
{ 0x0003c000, 16384 },
|
||||
{ 0x00040000, 16384 },
|
||||
{ 0x00044000, 16384 },
|
||||
{ 0x00048000, 16384 },
|
||||
{ 0x0004c000, 16384 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
void test_performance(void)
|
||||
{
|
||||
char filename[16];
|
||||
struct fs_file_t file;
|
||||
s64_t reftime = k_uptime_get();
|
||||
u32_t delta;
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
/* Format to start on clean flash */
|
||||
rc = nffs_format_full(area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
/* 1. Create files benchmark */
|
||||
printk("1. Creating files...\n");
|
||||
nffs_cache_clear();
|
||||
k_uptime_delta(&reftime);
|
||||
|
||||
for (i = 0; i < TEST_NUM_FILES; i++) {
|
||||
snprintf(filename, sizeof(filename), NFFS_MNTP"/file_%d", i);
|
||||
rc = fs_open(&file, filename);
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
}
|
||||
|
||||
delta = k_uptime_delta_32(&reftime);
|
||||
printk("Created %d files in %d.%03d seconds\n", TEST_NUM_FILES,
|
||||
delta / 1000U, delta % 1000);
|
||||
|
||||
/* 2. Unlink files benchmark */
|
||||
printk("2. Unlinking files...\n");
|
||||
nffs_cache_clear();
|
||||
k_uptime_delta(&reftime);
|
||||
|
||||
for (i = 0; i < TEST_NUM_FILES; i++) {
|
||||
snprintf(filename, sizeof(filename), NFFS_MNTP"/file_%d", i);
|
||||
rc = fs_unlink(filename);
|
||||
zassert_equal(rc, 0, "cannot unlink file");
|
||||
}
|
||||
|
||||
delta = k_uptime_delta_32(&reftime);
|
||||
printk("Unlinked %d files in %d.%03d seconds\n", TEST_NUM_FILES,
|
||||
delta / 1000U, delta % 1000);
|
||||
|
||||
/* Format to start on clean flash */
|
||||
rc = nffs_format_full(area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
/* 3. Write file benchmark */
|
||||
printk("3. Writing file...\n");
|
||||
nffs_cache_clear();
|
||||
k_uptime_delta(&reftime);
|
||||
|
||||
rc = fs_open(&file, NFFS_MNTP"/file");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
(void)memset(nffs_test_buf, 0, RW_CHUNK_LENGTH);
|
||||
for (i = 0; i < RW_DATA_LENGTH; ) {
|
||||
rc = fs_write(&file, nffs_test_buf, RW_CHUNK_LENGTH);
|
||||
zassert_equal(rc, RW_CHUNK_LENGTH, "cannot write file");
|
||||
i += rc;
|
||||
}
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
delta = k_uptime_delta_32(&reftime);
|
||||
printk("Written %d bytes in %d.%03d seconds\n", i, delta / 1000U,
|
||||
delta % 1000);
|
||||
|
||||
/* 4. Read file benchmark */
|
||||
printk("4. Reading file...\n");
|
||||
nffs_cache_clear();
|
||||
k_uptime_delta(&reftime);
|
||||
|
||||
rc = fs_open(&file, NFFS_MNTP"/file");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
for (i = 0; i < RW_DATA_LENGTH; ) {
|
||||
rc = fs_read(&file, nffs_test_buf, RW_CHUNK_LENGTH);
|
||||
zassert_equal(rc, RW_CHUNK_LENGTH, "cannot read file");
|
||||
i += rc;
|
||||
}
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
delta = k_uptime_delta_32(&reftime);
|
||||
printk("Read %d bytes in %d.%03d seconds\n", i, delta / 1000U,
|
||||
delta % 1000);
|
||||
|
||||
/* Format to start on clean flash */
|
||||
rc = nffs_format_full(area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
/* 5. Write file benchmark */
|
||||
printk("5. Writing file (max block size)...\n");
|
||||
nffs_cache_clear();
|
||||
k_uptime_delta(&reftime);
|
||||
|
||||
rc = fs_open(&file, NFFS_MNTP"/file");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
(void)memset(nffs_test_buf, 0, NFFS_BLOCK_MAX_DATA_SZ_MAX);
|
||||
for (i = 0; i < RW_DATA_LENGTH; ) {
|
||||
rc = fs_write(&file, nffs_test_buf, NFFS_BLOCK_MAX_DATA_SZ_MAX);
|
||||
zassert_equal(rc, NFFS_BLOCK_MAX_DATA_SZ_MAX,
|
||||
"cannot write file");
|
||||
i += rc;
|
||||
}
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
delta = k_uptime_delta_32(&reftime);
|
||||
printk("Written %d bytes in %d.%03d seconds\n", i, delta / 1000U,
|
||||
delta % 1000);
|
||||
|
||||
/* 6. Read file benchmark */
|
||||
printk("6. Reading file (max block size)...\n");
|
||||
nffs_cache_clear();
|
||||
k_uptime_delta(&reftime);
|
||||
|
||||
rc = fs_open(&file, NFFS_MNTP"/file");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
for (i = 0; i < RW_DATA_LENGTH; ) {
|
||||
rc = fs_read(&file, nffs_test_buf, NFFS_BLOCK_MAX_DATA_SZ_MAX);
|
||||
zassert_equal(rc, NFFS_BLOCK_MAX_DATA_SZ_MAX,
|
||||
"cannot read file");
|
||||
i += rc;
|
||||
}
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
delta = k_uptime_delta_32(&reftime);
|
||||
printk("Read %d bytes in %d.%03d seconds\n", i, delta / 1000U,
|
||||
delta % 1000);
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_read(void)
|
||||
{
|
||||
u8_t buf[16];
|
||||
struct fs_file_t file;
|
||||
int rc;
|
||||
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
nffs_test_util_create_file(NFFS_MNTP"/myfile.txt", "1234567890", 10);
|
||||
|
||||
rc = fs_open(&file, NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_test_util_assert_file_len(file.filep, 10);
|
||||
zassert_equal(fs_tell(&file), 0, "invalid pos in file");
|
||||
|
||||
rc = fs_read(&file, &buf, 4);
|
||||
zassert_equal(rc, 4, "invalid bytes read");
|
||||
zassert_equal(memcmp(buf, "1234", 4), 0, "invalid buffer size");
|
||||
zassert_equal(fs_tell(&file), 4, "invalid pos in file");
|
||||
|
||||
rc = fs_read(&file, buf + 4, sizeof(buf) - 4);
|
||||
zassert_equal(rc, 6, "invalid bytes read");
|
||||
zassert_equal(memcmp(buf, "1234567890", 10), 0, "invalid buffer size");
|
||||
zassert_equal(fs_tell(&file), 10, "invalid pos in file");
|
||||
|
||||
rc = fs_close(&file);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
|
||||
|
||||
void test_readdir(void)
|
||||
{
|
||||
struct fs_dir_t dir;
|
||||
struct fs_dirent dirent;
|
||||
int rc;
|
||||
|
||||
/* Setup. */
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/mydir");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
nffs_test_util_create_file(NFFS_MNTP"/mydir/b", "bbbb", 4);
|
||||
nffs_test_util_create_file(NFFS_MNTP"/mydir/a", "aaaa", 4);
|
||||
rc = fs_mkdir(NFFS_MNTP"/mydir/c");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
/* Nonexistent directory. */
|
||||
rc = fs_opendir(&dir, NFFS_MNTP"/asdf");
|
||||
zassert_not_equal(rc, 0, "cannot open nonexistent directory");
|
||||
|
||||
/* Fail to opendir a file. */
|
||||
rc = fs_opendir(&dir, NFFS_MNTP"/mydir/a");
|
||||
zassert_not_equal(rc, 0, "cannot open directory");
|
||||
|
||||
/* Real directory (with trailing slash). */
|
||||
rc = fs_opendir(&dir, NFFS_MNTP"/mydir/");
|
||||
zassert_equal(rc, 0, "cannot open dir (trailing slash)");
|
||||
|
||||
rc = fs_readdir(&dir, &dirent);
|
||||
zassert_equal(rc, 0, "cannot read directory");
|
||||
nffs_test_util_assert_ent_name(&dirent, "a");
|
||||
zassert_equal(dirent.type == FS_DIR_ENTRY_DIR, 0,
|
||||
"invalid directory name");
|
||||
|
||||
rc = fs_readdir(&dir, &dirent);
|
||||
zassert_equal(rc, 0, "cannot read directory");
|
||||
nffs_test_util_assert_ent_name(&dirent, "b");
|
||||
zassert_equal(dirent.type == FS_DIR_ENTRY_DIR, 0,
|
||||
"invalid directory name");
|
||||
|
||||
rc = fs_readdir(&dir, &dirent);
|
||||
zassert_equal(rc, 0, "cannot read directory");
|
||||
nffs_test_util_assert_ent_name(&dirent, "c");
|
||||
zassert_equal(dirent.type != FS_DIR_ENTRY_DIR, 0,
|
||||
"invalid directory name");
|
||||
|
||||
rc = fs_readdir(&dir, &dirent);
|
||||
zassert_equal(rc, 0, "cannot read directory");
|
||||
|
||||
rc = fs_closedir(&dir);
|
||||
zassert_equal(rc, 0, "cannot close directory");
|
||||
|
||||
/* Root directory. */
|
||||
rc = fs_opendir(&dir, NFFS_MNTP"/");
|
||||
zassert_equal(rc, 0, "cannot open root directory");
|
||||
rc = fs_readdir(&dir, &dirent);
|
||||
zassert_equal(rc, 0, "cannot read root directory");
|
||||
|
||||
nffs_test_util_assert_ent_name(&dirent, "lost+found");
|
||||
zassert_equal(dirent.type == FS_DIR_ENTRY_DIR, 1, "no lost+found");
|
||||
|
||||
rc = fs_readdir(&dir, &dirent);
|
||||
zassert_equal(rc, 0, "cannot read directory");
|
||||
nffs_test_util_assert_ent_name(&dirent, "mydir");
|
||||
zassert_equal(dirent.type != FS_DIR_ENTRY_DIR, 0,
|
||||
"no mydir directory");
|
||||
|
||||
rc = fs_closedir(&dir);
|
||||
zassert_equal(rc, 0, "cannot close directory");
|
||||
|
||||
/* Delete entries while iterating. */
|
||||
rc = fs_opendir(&dir, NFFS_MNTP"/mydir");
|
||||
zassert_equal(rc, 0, "cannot open directory");
|
||||
|
||||
rc = fs_readdir(&dir, &dirent);
|
||||
zassert_equal(rc, 0, "cannot read directory");
|
||||
|
||||
nffs_test_util_assert_ent_name(&dirent, "a");
|
||||
zassert_equal(dirent.type == FS_DIR_ENTRY_DIR, 0,
|
||||
"invalid directory name");
|
||||
|
||||
rc = fs_unlink(NFFS_MNTP"/mydir/b");
|
||||
zassert_equal(rc, 0, "cannot delete mydir");
|
||||
|
||||
rc = fs_readdir(&dir, &dirent);
|
||||
zassert_equal(rc, 0, "cannot read directory");
|
||||
|
||||
rc = fs_unlink(NFFS_MNTP"/mydir/c");
|
||||
zassert_equal(rc, 0, "cannot delete lower directory");
|
||||
|
||||
rc = fs_unlink(NFFS_MNTP"/mydir");
|
||||
zassert_equal(rc, 0, "cannot delete mydir directory");
|
||||
|
||||
nffs_test_util_assert_ent_name(&dirent, "c");
|
||||
zassert_equal(dirent.type == FS_DIR_ENTRY_DIR, 1,
|
||||
"invalid directory name");
|
||||
|
||||
rc = fs_readdir(&dir, &dirent);
|
||||
zassert_equal(rc, 0, "cannot read directory");
|
||||
|
||||
rc = fs_closedir(&dir);
|
||||
zassert_equal(rc, 0, "cannot close directory");
|
||||
|
||||
/* Ensure directory is gone. */
|
||||
rc = fs_opendir(&dir, NFFS_MNTP"/mydir");
|
||||
zassert_not_equal(rc, 0, "directory is still present");
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_rename(void)
|
||||
{
|
||||
struct fs_dirent file;
|
||||
const char contents[] = "contents";
|
||||
int rc;
|
||||
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
rc = nffs_path_rename("/nonexistent.txt", "/newname.txt");
|
||||
zassert_equal(rc, FS_ENOENT, "cannot rename file");
|
||||
|
||||
/*** Rename file. */
|
||||
nffs_test_util_create_file(NFFS_MNTP"/myfile.txt",
|
||||
contents, sizeof(contents));
|
||||
|
||||
rc = nffs_path_rename("/myfile.txt", "badname");
|
||||
zassert_equal(rc, FS_EINVAL, "cannot rename file");
|
||||
|
||||
rc = nffs_path_rename("/myfile.txt", "/myfile2.txt");
|
||||
zassert_equal(rc, 0, "cannot rename file");
|
||||
|
||||
rc = fs_stat(NFFS_MNTP"/myfile.txt", &file);
|
||||
zassert_not_equal(rc, 0, "cannot open file");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/myfile2.txt", contents,
|
||||
sizeof(contents));
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/mydir");
|
||||
zassert_equal(rc, 0, "cannot create directory");
|
||||
|
||||
rc = fs_mkdir(NFFS_MNTP"/mydir/leafdir");
|
||||
zassert_equal(rc, 0, "cannot create sub-directory");
|
||||
|
||||
rc = nffs_path_rename("/myfile2.txt", "/mydir/myfile2.txt");
|
||||
zassert_equal(rc, 0, "cannot rename file in sub-directory");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/mydir/myfile2.txt", contents,
|
||||
sizeof(contents));
|
||||
|
||||
/*** Rename directory. */
|
||||
rc = nffs_path_rename("/mydir", "badname");
|
||||
zassert_equal(rc, FS_EINVAL, "cannot rename directory");
|
||||
|
||||
/* Don't allow a directory to be moved into a descendent directory. */
|
||||
rc = nffs_path_rename("/mydir", "/mydir/leafdir/a");
|
||||
zassert_equal(rc, FS_EINVAL, "directory moved to descendant dir");
|
||||
|
||||
rc = nffs_path_rename("/mydir", "/mydir2");
|
||||
zassert_equal(rc, 0, "cannot rename directory");
|
||||
|
||||
nffs_test_util_assert_contents(NFFS_MNTP"/mydir2/myfile2.txt", contents,
|
||||
sizeof(contents));
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "mydir2",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "leafdir",
|
||||
.is_dir = 1,
|
||||
}, {
|
||||
.filename = "myfile2.txt",
|
||||
.contents = "contents",
|
||||
.contents_len = 9,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
|
||||
#define TEST_CONTENT_LEN (24 * 1024)
|
||||
|
||||
void test_split_file(void)
|
||||
{
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
/* Setup. */
|
||||
static const struct nffs_area_desc area_descs_two[] = {
|
||||
{ 0x00000000 + TEST_FLASH_OFFSET, 16 * 1024 },
|
||||
{ 0x00004000 + TEST_FLASH_OFFSET, 16 * 1024 },
|
||||
{ 0x00008000 + TEST_FLASH_OFFSET, 16 * 1024 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
rc = nffs_format_full(area_descs_two);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
for (i = 0; i < TEST_CONTENT_LEN; i++) {
|
||||
nffs_test_buf[i] = i;
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
nffs_test_util_create_file(NFFS_MNTP"/myfile.txt",
|
||||
nffs_test_buf, TEST_CONTENT_LEN);
|
||||
rc = fs_unlink(NFFS_MNTP"/myfile.txt");
|
||||
zassert_equal(rc, 0, "cannot unlink file");
|
||||
}
|
||||
|
||||
nffs_test_util_create_file(NFFS_MNTP"/myfile.txt",
|
||||
nffs_test_buf, TEST_CONTENT_LEN);
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
.children = (struct nffs_test_file_desc[]) { {
|
||||
.filename = "myfile.txt",
|
||||
.contents = nffs_test_buf,
|
||||
.contents_len = TEST_CONTENT_LEN,
|
||||
}, {
|
||||
.filename = NULL,
|
||||
} },
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, area_descs_two);
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
/*
|
||||
*Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
|
||||
extern struct k_mem_slab nffs_block_entry_pool;
|
||||
extern struct k_mem_slab nffs_inode_entry_pool;
|
||||
|
||||
void test_unlink(void)
|
||||
{
|
||||
struct fs_dirent file_stats;
|
||||
struct fs_file_t file0, file1;
|
||||
u8_t buf[64];
|
||||
struct nffs_file *nffs_file;
|
||||
u32_t bytes_read;
|
||||
int initial_num_blocks;
|
||||
int initial_num_inodes;
|
||||
int rc;
|
||||
|
||||
rc = nffs_format_full(nffs_current_area_descs);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
initial_num_blocks = k_mem_slab_num_free_get(&nffs_block_entry_pool);
|
||||
initial_num_inodes = k_mem_slab_num_free_get(&nffs_inode_entry_pool);
|
||||
|
||||
nffs_test_util_create_file(NFFS_MNTP"/file0.txt", "0", 1);
|
||||
|
||||
rc = fs_open(&file0, NFFS_MNTP"/file0.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_file = file0.filep;
|
||||
zassert_equal(nffs_file->nf_inode_entry->nie_refcnt, 2, "inode error");
|
||||
|
||||
rc = fs_unlink(NFFS_MNTP"/file0.txt");
|
||||
zassert_equal(rc, 0, "");
|
||||
zassert_equal(nffs_file->nf_inode_entry->nie_refcnt, 1, "inode error");
|
||||
|
||||
rc = fs_stat(NFFS_MNTP"/file0.txt", &file_stats);
|
||||
zassert_not_equal(rc, 0, "no such file");
|
||||
|
||||
rc = fs_write(&file0, "00", 2);
|
||||
|
||||
rc = fs_seek(&file0, 0, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
|
||||
bytes_read = fs_read(&file0, buf, sizeof(buf));
|
||||
zassert_equal(bytes_read, 2, "invalid bytes read");
|
||||
zassert_equal(memcmp(buf, "00", 2), 0, "invalid buffer size");
|
||||
|
||||
rc = fs_close(&file0);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
|
||||
rc = fs_stat(NFFS_MNTP"/file0.txt", &file_stats);
|
||||
zassert_not_equal(rc, 0, "no such file");
|
||||
|
||||
/* Ensure the file was fully removed from RAM. */
|
||||
zassert_equal(k_mem_slab_num_free_get(&nffs_inode_entry_pool),
|
||||
initial_num_inodes, "file not remove entirely");
|
||||
zassert_equal(k_mem_slab_num_free_get(&nffs_block_entry_pool),
|
||||
initial_num_blocks, "file not remove entirely");
|
||||
|
||||
/*** Nested unlink. */
|
||||
rc = fs_mkdir(NFFS_MNTP"/mydir");
|
||||
zassert_equal(rc, 0, "cannot make directory");
|
||||
nffs_test_util_create_file(NFFS_MNTP"/mydir/file1.txt", "1", 2);
|
||||
|
||||
rc = fs_open(&file1, NFFS_MNTP"/mydir/file1.txt");
|
||||
zassert_equal(rc, 0, "cannot open file");
|
||||
nffs_file = file1.filep;
|
||||
zassert_equal(nffs_file->nf_inode_entry->nie_refcnt, 2, "inode error");
|
||||
|
||||
rc = fs_unlink(NFFS_MNTP"/mydir");
|
||||
zassert_equal(rc, 0, "cannot delete directory");
|
||||
zassert_equal(nffs_file->nf_inode_entry->nie_refcnt, 1, "inode error");
|
||||
|
||||
rc = fs_stat(NFFS_MNTP"/mydir/file1.txt", &file_stats);
|
||||
zassert_not_equal(rc, 0, "unlink failed");
|
||||
|
||||
rc = fs_write(&file1, "11", 2);
|
||||
|
||||
rc = fs_seek(&file1, 0, FS_SEEK_SET);
|
||||
zassert_equal(rc, 0, "cannot set pos in file");
|
||||
|
||||
bytes_read = fs_read(&file1, buf, sizeof(buf));
|
||||
zassert_equal(bytes_read, 2, "invalid bytes read");
|
||||
zassert_equal(memcmp(buf, "11", 2), 0, "invalid buffer size");
|
||||
|
||||
rc = fs_close(&file1);
|
||||
zassert_equal(rc, 0, "cannot close file");
|
||||
|
||||
rc = fs_stat(NFFS_MNTP"/mydir/file1.txt", &file_stats);
|
||||
zassert_not_equal(rc, 0, "unlink failed");
|
||||
|
||||
struct nffs_test_file_desc *expected_system =
|
||||
(struct nffs_test_file_desc[]) { {
|
||||
.filename = "",
|
||||
.is_dir = 1,
|
||||
} };
|
||||
|
||||
nffs_test_assert_system(expected_system, nffs_current_area_descs);
|
||||
|
||||
/* Ensure the files and directories were fully removed from RAM. */
|
||||
zassert_equal(k_mem_slab_num_free_get(&nffs_inode_entry_pool),
|
||||
initial_num_inodes, "not all removed from RAM");
|
||||
zassert_equal(k_mem_slab_num_free_get(&nffs_block_entry_pool),
|
||||
initial_num_blocks, "not all removed from RAM");
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <fs/fs.h>
|
||||
#include "nffs_test_utils.h"
|
||||
#include <ztest_assert.h>
|
||||
|
||||
void test_wear_level(void)
|
||||
{
|
||||
int rc;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
static const struct nffs_area_desc area_descs_uniform[] = {
|
||||
{ 0x00000000 + TEST_FLASH_OFFSET, 4 * 1024 },
|
||||
{ 0x00020000 + TEST_FLASH_OFFSET, 4 * 1024 },
|
||||
{ 0x00040000 + TEST_FLASH_OFFSET, 4 * 1024 },
|
||||
{ 0x00060000 + TEST_FLASH_OFFSET, 4 * 1024 },
|
||||
{ 0x00080000 + TEST_FLASH_OFFSET, 4 * 1024 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
/*** Setup. */
|
||||
rc = nffs_format_full(area_descs_uniform);
|
||||
zassert_equal(rc, 0, "cannot format nffs");
|
||||
|
||||
/* Ensure areas rotate properly. */
|
||||
for (i = 0; i < 255; i++) {
|
||||
for (j = 0; j < nffs_num_areas; j++) {
|
||||
nffs_test_assert_area_seqs(i, nffs_num_areas - j, i + 1, j);
|
||||
nffs_gc(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure proper rollover of sequence numbers. */
|
||||
for (j = 0; j < nffs_num_areas; j++) {
|
||||
nffs_test_assert_area_seqs(255, nffs_num_areas - j, 0, j);
|
||||
nffs_gc(NULL);
|
||||
}
|
||||
for (j = 0; j < nffs_num_areas; j++) {
|
||||
nffs_test_assert_area_seqs(0, nffs_num_areas - j, 1, j);
|
||||
nffs_gc(NULL);
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
if(BOARD STREQUAL nrf52840_pca10056)
|
||||
set(CONF_FILE nrf5x.conf)
|
||||
endif()
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(large)
|
||||
|
||||
if(BOARD STREQUAL qemu_x86)
|
||||
zephyr_compile_definitions(
|
||||
-DTEST_FLASH_OFFSET=0
|
||||
)
|
||||
elseif(BOARD STREQUAL nrf52840_pca10056)
|
||||
zephyr_compile_definitions(
|
||||
-DTEST_FLASH_OFFSET=0x20000
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT TEST)
|
||||
target_compile_definitions(app PRIVATE
|
||||
-DTEST_basic
|
||||
)
|
||||
else()
|
||||
target_compile_definitions(app PRIVATE
|
||||
-DTEST_${TEST}
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
zephyr_include_directories(../common)
|
||||
FILE(GLOB app_sources ../common/*.c src/*.c)
|
||||
|
||||
if(CONFIG_QEMU_TARGET)
|
||||
list(APPEND app_sources ../ram_backend/test_ram_backend.c)
|
||||
endif()
|
||||
|
||||
target_sources(app PRIVATE ${app_sources})
|
|
@ -1,22 +0,0 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_MAIN_STACK_SIZE=1024
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_BT=n
|
||||
CONFIG_SOC_FLASH_NRF_RADIO_SYNC=n
|
||||
CONFIG_MPU_ALLOW_FLASH_WRITE=y
|
||||
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_FILE_SYSTEM_NFFS=y
|
||||
CONFIG_FS_NFFS_FLASH_DEV_NAME="NRF_FLASH_DRV_NAME"
|
||||
CONFIG_FS_NFFS_NUM_FILES=4
|
||||
CONFIG_FS_NFFS_NUM_DIRS=4
|
||||
CONFIG_FS_NFFS_NUM_INODES=1024
|
||||
CONFIG_FS_NFFS_NUM_BLOCKS=1024
|
||||
CONFIG_FS_NFFS_NUM_CACHE_INODES=1
|
||||
CONFIG_FS_NFFS_NUM_CACHE_BLOCKS=1
|
||||
CONFIG_FILE_SYSTEM_NFFS=y
|
||||
CONFIG_NFFS_FILESYSTEM_MAX_AREAS=12
|
|
@ -1,18 +0,0 @@
|
|||
CONFIG_TEST_FLASH_DRIVERS=y
|
||||
CONFIG_FILE_SYSTEM_NFFS=y
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FS_NFFS_FLASH_DEV_NAME="ram_flash_test_drv"
|
||||
CONFIG_FS_NFFS_NUM_BLOCKS=1024
|
||||
CONFIG_FS_NFFS_NUM_CACHE_BLOCKS=1
|
||||
CONFIG_FS_NFFS_NUM_CACHE_INODES=1
|
||||
CONFIG_FS_NFFS_NUM_DIRS=4
|
||||
CONFIG_FS_NFFS_NUM_FILES=4
|
||||
CONFIG_FS_NFFS_NUM_INODES=1024
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||
CONFIG_MAIN_STACK_SIZE=1024
|
||||
CONFIG_NFFS_FILESYSTEM_MAX_AREAS=12
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_ZTEST=y
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/delete-node/ &storage_partition;
|
||||
|
||||
&flash_sim0 {
|
||||
/*
|
||||
* For more information, see:
|
||||
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
|
||||
*/
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
storage_partition: partition@0 {
|
||||
label = "storage";
|
||||
reg = <0x00000000 0x100000>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Codecoup
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <nffs/nffs.h>
|
||||
#include "test_nffs.h"
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(nffs_fs_large_test,
|
||||
ztest_unit_test_setup_teardown(test_fs_mount,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_large_unlink,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_large_system,
|
||||
test_setup, test_teardown));
|
||||
ztest_run_test_suite(nffs_fs_large_test);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
common:
|
||||
tags: nffs filesystem
|
||||
tests:
|
||||
filesystem.nffs.large:
|
||||
extra_args: TEST=large
|
||||
platform_whitelist: qemu_x86 nrf52840_pca10056
|
|
@ -1,39 +0,0 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
if(BOARD STREQUAL nrf52840_pca10056)
|
||||
set(CONF_FILE nrf5x.conf)
|
||||
endif()
|
||||
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(performance)
|
||||
|
||||
if(BOARD STREQUAL qemu_x86)
|
||||
zephyr_compile_definitions(
|
||||
-DTEST_FLASH_OFFSET=0
|
||||
)
|
||||
elseif(BOARD STREQUAL nrf52840_pca10056)
|
||||
zephyr_compile_definitions(
|
||||
-DTEST_FLASH_OFFSET=0x20000
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT TEST)
|
||||
target_compile_definitions(app PRIVATE
|
||||
-DTEST_basic
|
||||
)
|
||||
else()
|
||||
target_compile_definitions(app PRIVATE
|
||||
-DTEST_${TEST}
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
zephyr_include_directories(../common)
|
||||
FILE(GLOB app_sources ../common/*.c src/*.c)
|
||||
|
||||
if(CONFIG_QEMU_TARGET)
|
||||
list(APPEND app_sources ../ram_backend/test_ram_backend.c)
|
||||
endif()
|
||||
|
||||
target_sources(app PRIVATE ${app_sources})
|
|
@ -1,21 +0,0 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_MAIN_STACK_SIZE=1024
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_SOC_FLASH_NRF_RADIO_SYNC=y
|
||||
CONFIG_MPU_ALLOW_FLASH_WRITE=y
|
||||
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_FILE_SYSTEM_NFFS=y
|
||||
CONFIG_FS_NFFS_FLASH_DEV_NAME="NRF_FLASH_DRV_NAME"
|
||||
CONFIG_FS_NFFS_NUM_FILES=4
|
||||
CONFIG_FS_NFFS_NUM_DIRS=4
|
||||
CONFIG_FS_NFFS_NUM_INODES=1024
|
||||
CONFIG_FS_NFFS_NUM_BLOCKS=1024
|
||||
CONFIG_FS_NFFS_NUM_CACHE_INODES=1
|
||||
CONFIG_FS_NFFS_NUM_CACHE_BLOCKS=1
|
||||
CONFIG_FILE_SYSTEM_NFFS=y
|
||||
CONFIG_NFFS_FILESYSTEM_MAX_AREAS=12
|
|
@ -1,18 +0,0 @@
|
|||
CONFIG_TEST_FLASH_DRIVERS=y
|
||||
CONFIG_FILE_SYSTEM_NFFS=y
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FS_NFFS_FLASH_DEV_NAME="ram_flash_test_drv"
|
||||
CONFIG_FS_NFFS_NUM_BLOCKS=1024
|
||||
CONFIG_FS_NFFS_NUM_CACHE_BLOCKS=1
|
||||
CONFIG_FS_NFFS_NUM_CACHE_INODES=1
|
||||
CONFIG_FS_NFFS_NUM_DIRS=4
|
||||
CONFIG_FS_NFFS_NUM_FILES=4
|
||||
CONFIG_FS_NFFS_NUM_INODES=1024
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||
CONFIG_MAIN_STACK_SIZE=1024
|
||||
CONFIG_NFFS_FILESYSTEM_MAX_AREAS=12
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_ZTEST=y
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/delete-node/ &storage_partition;
|
||||
|
||||
&flash_sim0 {
|
||||
/*
|
||||
* For more information, see:
|
||||
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
|
||||
*/
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
storage_partition: partition@0 {
|
||||
label = "storage";
|
||||
reg = <0x00000000 0x100000>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Codecoup
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <nffs/nffs.h>
|
||||
#include "test_nffs.h"
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(nffs_fs_performance_test,
|
||||
ztest_unit_test_setup_teardown(test_fs_mount,
|
||||
test_setup, test_teardown),
|
||||
ztest_unit_test_setup_teardown(test_performance,
|
||||
test_setup, test_teardown));
|
||||
ztest_run_test_suite(nffs_fs_performance_test);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
common:
|
||||
tags: nffs filesystem
|
||||
tests:
|
||||
filesystem.nffs.performance:
|
||||
extra_args: TEST=performance
|
||||
platform_whitelist: qemu_x86 nrf52840_pca10056
|
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Codecoup
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <device.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <zephyr/types.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
static u8_t rambuf[DT_FLASH_AREA_STORAGE_SIZE];
|
||||
|
||||
static int test_ram_flash_init(struct device *dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_flash_ram_write_protection(struct device *dev, bool enable)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_flash_ram_erase(struct device *dev, off_t offset, size_t len)
|
||||
{
|
||||
struct flash_pages_info info;
|
||||
off_t end_offset = offset + len;
|
||||
|
||||
zassert_true(offset >= 0, "invalid offset");
|
||||
zassert_true(offset + len <= DT_FLASH_AREA_STORAGE_SIZE,
|
||||
"flash address out of bounds");
|
||||
|
||||
while (offset < end_offset) {
|
||||
flash_get_page_info_by_offs(dev, offset, &info);
|
||||
(void)memset(rambuf + info.start_offset, 0xff, info.size);
|
||||
offset = info.start_offset + info.size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_flash_ram_write(struct device *dev, off_t offset,
|
||||
const void *data, size_t len)
|
||||
{
|
||||
zassert_true(offset >= 0, "invalid offset");
|
||||
zassert_true(offset + len <= DT_FLASH_AREA_STORAGE_SIZE,
|
||||
"flash address out of bounds");
|
||||
|
||||
memcpy(rambuf + offset, data, len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_flash_ram_read(struct device *dev, off_t offset, void *data,
|
||||
size_t len)
|
||||
{
|
||||
zassert_true(offset >= 0, "invalid offset");
|
||||
zassert_true(offset + len <= DT_FLASH_AREA_STORAGE_SIZE,
|
||||
"flash address out of bounds");
|
||||
|
||||
memcpy(data, rambuf + offset, len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_flash_ram_pages_layout(struct device *dev,
|
||||
const struct flash_pages_layout **layout,
|
||||
size_t *layout_size)
|
||||
{
|
||||
/* Same as used in Mynewt native "flash" backend */
|
||||
static struct flash_pages_layout dev_layout[] = {
|
||||
{ 4, 16 * 1024 },
|
||||
{ 1, 64 * 1024 },
|
||||
{ 7, 128 * 1024 },
|
||||
};
|
||||
|
||||
*layout = dev_layout;
|
||||
*layout_size = ARRAY_SIZE(dev_layout);
|
||||
}
|
||||
|
||||
static const struct flash_driver_api flash_ram_api = {
|
||||
.write_protection = test_flash_ram_write_protection,
|
||||
.erase = test_flash_ram_erase,
|
||||
.write = test_flash_ram_write,
|
||||
.read = test_flash_ram_read,
|
||||
.page_layout = test_flash_ram_pages_layout,
|
||||
};
|
||||
|
||||
DEVICE_AND_API_INIT(flash_ram_test, "ram_flash_test_drv", test_ram_flash_init,
|
||||
NULL, NULL, POST_KERNEL,
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
||||
&flash_ram_api);
|
Loading…
Add table
Add a link
Reference in a new issue