summaryrefslogtreecommitdiff
path: root/examples/utest/testcases/tmpfs/tmpfs.c
blob: 647944a714717125c29e0caf5ad8260b9a8b49a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * 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 <errno.h>
#include <fcntl.h>
#include <unistd.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 void run_long_name_reject(void)
{
    static const char long_name[] =
        "/tmp/abcdefghijklmnopqrstuvwxyz1234567890";
    int fd;

    errno = 0;
    fd = open(long_name, O_CREAT | O_RDWR, 0);
    uassert_int_equal(fd, -1);
    uassert_int_equal(errno, -ENAMETOOLONG);
}

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_UNIT_RUN(run_long_name_reject);
}
UTEST_TC_EXPORT(testcase, "testcase.tfs.tmpfs", utest_tc_init, utest_tc_cleanup, 10);