Skip to content

Commit c044f0c

Browse files
karthi012nashif
authored andcommitted
tests: lib: c_lib: add test suite for remove api
Add test suite for remove of zephyr native libc Signed-off-by: Chris Friedt <[email protected]> Signed-off-by: Karthikeyan Krishnasamy <[email protected]>
1 parent abf6269 commit c044f0c

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(stdio)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
target_sources(app PRIVATE ${app_sources})

tests/lib/c_lib/stdio/app.overlay

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2024 Linumiz
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
ramdisk0 {
9+
compatible = "zephyr,ram-disk";
10+
disk-name = "RAM";
11+
sector-size = <512>;
12+
sector-count = <160>;
13+
};
14+
};

tests/lib/c_lib/stdio/prj.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_TEST_USERSPACE=y
3+
CONFIG_ZTEST_FATAL_HOOK=y
4+
CONFIG_MINIMAL_LIBC=y
5+
CONFIG_FILE_SYSTEM=y
6+
CONFIG_FAT_FILESYSTEM_ELM=y

tests/lib/c_lib/stdio/src/main.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2024 Linumiz
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <errno.h>
8+
#include <stdio.h>
9+
#include <zephyr/kernel.h>
10+
#include <zephyr/sys/__assert.h>
11+
#include <zephyr/ztest.h>
12+
#include <zephyr/ztest_error_hook.h>
13+
#include <ff.h>
14+
#include <zephyr/fs/fs.h>
15+
16+
#define FATFS_MNTP "/RAM:"
17+
#define TEST_FILE FATFS_MNTP"/testfile.txt"
18+
19+
static FATFS fat_fs;
20+
21+
static struct fs_mount_t fatfs_mnt = {
22+
.type = FS_FATFS,
23+
.mnt_point = FATFS_MNTP,
24+
.fs_data = &fat_fs,
25+
};
26+
27+
ZTEST_SUITE(libc_stdio, NULL, NULL, NULL, NULL, NULL);
28+
29+
/**
30+
* @brief Test for remove API
31+
*
32+
* @details Test deletes a file through remove API.
33+
*/
34+
ZTEST(libc_stdio, test_remove)
35+
{
36+
struct fs_file_t file;
37+
38+
fs_file_t_init(&file);
39+
40+
zassert_ok(fs_mount(&fatfs_mnt), "Error in mount file system\n");
41+
zassert_equal(fs_open(&file, TEST_FILE, FS_O_CREATE), 0,
42+
"Error creating file\n");
43+
zassert_ok(fs_close(&file), "Error closing file\n");
44+
zassert_ok(remove(TEST_FILE), "Error removing file: %d\n", errno);
45+
zassert_equal(remove(""), -1, "Error Invalid path removed\n");
46+
zassert_equal(remove(NULL), -1, "Error Invalid path removed\n");
47+
zassert_ok(fs_unmount(&fatfs_mnt), "Error while unmount file system\n");
48+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
common:
2+
tags:
3+
- clib
4+
min_ram: 128
5+
filter: not CONFIG_NATIVE_LIBC
6+
tests:
7+
libraries.libc.common.stdio.minimal:
8+
tags: minimal_libc
9+
filter: CONFIG_MINIMAL_LIBC_SUPPORTED
10+
extra_configs:
11+
- CONFIG_MINIMAL_LIBC=y
12+
libraries.libc.common.stdio.picolibc:
13+
tags: picolibc
14+
filter: CONFIG_PICOLIBC_SUPPORTED
15+
extra_configs:
16+
- CONFIG_PICOLIBC=y
17+
libraries.libc.common.stdio.newlib:
18+
tags: newlib
19+
filter: TOOLCHAIN_HAS_NEWLIB == 1
20+
extra_configs:
21+
- CONFIG_NEWLIB_LIBC=y

0 commit comments

Comments
 (0)