[fix]fix tmpfs bug (#8970)
* first * second * thrid * Update SConscript * tmpfs testcase default n * Update dfs_tmpfs.c * format document --------- Co-authored-by: zhujiale <zhujiale@rt-thread.com>
This commit is contained in:
parent
58e42caea7
commit
1869c543a6
|
@ -294,18 +294,17 @@ find_subpath:
|
||||||
|
|
||||||
static ssize_t dfs_tmpfs_read(struct dfs_file *file, void *buf, size_t count, off_t *pos)
|
static ssize_t dfs_tmpfs_read(struct dfs_file *file, void *buf, size_t count, off_t *pos)
|
||||||
{
|
{
|
||||||
rt_size_t length;
|
ssize_t length;
|
||||||
struct tmpfs_file *d_file;
|
struct tmpfs_file *d_file;
|
||||||
|
|
||||||
d_file = (struct tmpfs_file *)file->vnode->data;
|
d_file = (struct tmpfs_file *)file->vnode->data;
|
||||||
RT_ASSERT(d_file != NULL);
|
RT_ASSERT(d_file != NULL);
|
||||||
|
|
||||||
rt_mutex_take(&file->vnode->lock, RT_WAITING_FOREVER);
|
rt_mutex_take(&file->vnode->lock, RT_WAITING_FOREVER);
|
||||||
|
ssize_t size = (ssize_t)file->vnode->size;
|
||||||
if (count < file->vnode->size - *pos)
|
if ((ssize_t)count < size - *pos)
|
||||||
length = count;
|
length = count;
|
||||||
else
|
else
|
||||||
length = file->vnode->size - *pos;
|
length = size - *pos;
|
||||||
|
|
||||||
if (length > 0)
|
if (length > 0)
|
||||||
memcpy(buf, &(d_file->data[*pos]), length);
|
memcpy(buf, &(d_file->data[*pos]), length);
|
||||||
|
|
|
@ -14,7 +14,7 @@ source "$RTT_DIR/examples/utest/testcases/drivers/serial_v2/Kconfig"
|
||||||
source "$RTT_DIR/examples/utest/testcases/drivers/ipc/Kconfig"
|
source "$RTT_DIR/examples/utest/testcases/drivers/ipc/Kconfig"
|
||||||
source "$RTT_DIR/examples/utest/testcases/posix/Kconfig"
|
source "$RTT_DIR/examples/utest/testcases/posix/Kconfig"
|
||||||
source "$RTT_DIR/examples/utest/testcases/mm/Kconfig"
|
source "$RTT_DIR/examples/utest/testcases/mm/Kconfig"
|
||||||
|
source "$RTT_DIR/examples/utest/testcases/tmpfs/Kconfig"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
menu "Tmpfs Testcase"
|
||||||
|
|
||||||
|
config UTEST_TMPFS_CP
|
||||||
|
bool "tmpfs cp test"
|
||||||
|
default n
|
||||||
|
endmenu
|
|
@ -0,0 +1,13 @@
|
||||||
|
Import('rtconfig')
|
||||||
|
from building import *
|
||||||
|
|
||||||
|
cwd = GetCurrentDir()
|
||||||
|
src = []
|
||||||
|
CPPPATH = [cwd]
|
||||||
|
|
||||||
|
if GetDepend(['RT_USING_SMART','UTEST_TMPFS_CP']):
|
||||||
|
src += ['tmpfs.c']
|
||||||
|
|
||||||
|
group = DefineGroup('utestcases', src, depend = ['RT_USING_UTESTCASES'], CPPPATH = CPPPATH)
|
||||||
|
|
||||||
|
Return('group')
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2019, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2024-5-20 Zhujiale the first version
|
||||||
|
*/
|
||||||
|
#include <rtthread.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <msh.h>
|
||||||
|
#include "utest.h"
|
||||||
|
#include "utest_assert.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
void run_copy()
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
ret = msh_exec("cd /tmp", 7);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
LOG_E("errno=%d, ret=%d\n", errno, ret);
|
||||||
|
LOG_E("cd /tmp error");
|
||||||
|
uassert_false(1);
|
||||||
|
}
|
||||||
|
uassert_true(1);
|
||||||
|
ret = msh_exec("touch test", 10);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
LOG_E("errno=%d, ret=%d\n", errno, ret);
|
||||||
|
LOG_E("touch test error");
|
||||||
|
uassert_false(1);
|
||||||
|
}
|
||||||
|
uassert_true(1);
|
||||||
|
ret = msh_exec("echo this_is_a_test_file test", 29);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
LOG_E("errno=%d, ret=%d\n", errno, ret);
|
||||||
|
LOG_E("echo this_is_a_test_file test error");
|
||||||
|
uassert_false(1);
|
||||||
|
}
|
||||||
|
uassert_true(1);
|
||||||
|
ret = msh_exec("cp test test1", 13);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
LOG_E("errno=%d, ret=%d\n", errno, ret);
|
||||||
|
LOG_E("cp test test1 error");
|
||||||
|
uassert_false(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
uassert_true(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static rt_err_t utest_tc_init(void)
|
||||||
|
{
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static rt_err_t utest_tc_cleanup(void)
|
||||||
|
{
|
||||||
|
return RT_EOK;
|
||||||
|
}
|
||||||
|
static void testcase(void)
|
||||||
|
{
|
||||||
|
UTEST_UNIT_RUN(run_copy);
|
||||||
|
}
|
||||||
|
UTEST_TC_EXPORT(testcase, "testcase.tfs.tmpfs", utest_tc_init, utest_tc_cleanup, 10);
|
Loading…
Reference in New Issue