diff --git a/tests/lib/c_lib/stdio/CMakeLists.txt b/tests/lib/c_lib/stdio/CMakeLists.txt new file mode 100644 index 00000000000..c2b9d4cc31e --- /dev/null +++ b/tests/lib/c_lib/stdio/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(stdio) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/lib/c_lib/stdio/app.overlay b/tests/lib/c_lib/stdio/app.overlay new file mode 100644 index 00000000000..80f9a8b01d3 --- /dev/null +++ b/tests/lib/c_lib/stdio/app.overlay @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2024 Linumiz + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + ramdisk0 { + compatible = "zephyr,ram-disk"; + disk-name = "RAM"; + sector-size = <512>; + sector-count = <160>; + }; +}; diff --git a/tests/lib/c_lib/stdio/prj.conf b/tests/lib/c_lib/stdio/prj.conf new file mode 100644 index 00000000000..10eb46e3e27 --- /dev/null +++ b/tests/lib/c_lib/stdio/prj.conf @@ -0,0 +1,6 @@ +CONFIG_ZTEST=y +CONFIG_TEST_USERSPACE=y +CONFIG_ZTEST_FATAL_HOOK=y +CONFIG_MINIMAL_LIBC=y +CONFIG_FILE_SYSTEM=y +CONFIG_FAT_FILESYSTEM_ELM=y diff --git a/tests/lib/c_lib/stdio/src/main.c b/tests/lib/c_lib/stdio/src/main.c new file mode 100644 index 00000000000..2bafdd20aad --- /dev/null +++ b/tests/lib/c_lib/stdio/src/main.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 Linumiz + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define FATFS_MNTP "/RAM:" +#define TEST_FILE FATFS_MNTP"/testfile.txt" + +static FATFS fat_fs; + +static struct fs_mount_t fatfs_mnt = { + .type = FS_FATFS, + .mnt_point = FATFS_MNTP, + .fs_data = &fat_fs, +}; + +ZTEST_SUITE(libc_stdio, NULL, NULL, NULL, NULL, NULL); + +/** + * @brief Test for remove API + * + * @details Test deletes a file through remove API. + */ +ZTEST(libc_stdio, test_remove) +{ + struct fs_file_t file; + + fs_file_t_init(&file); + + zassert_ok(fs_mount(&fatfs_mnt), "Error in mount file system\n"); + zassert_equal(fs_open(&file, TEST_FILE, FS_O_CREATE), 0, + "Error creating file\n"); + zassert_ok(fs_close(&file), "Error closing file\n"); + zassert_ok(remove(TEST_FILE), "Error removing file: %d\n", errno); + zassert_equal(remove(""), -1, "Error Invalid path removed\n"); + zassert_equal(remove(NULL), -1, "Error Invalid path removed\n"); + zassert_ok(fs_unmount(&fatfs_mnt), "Error while unmount file system\n"); +} diff --git a/tests/lib/c_lib/stdio/testcase.yaml b/tests/lib/c_lib/stdio/testcase.yaml new file mode 100644 index 00000000000..e5872fdf845 --- /dev/null +++ b/tests/lib/c_lib/stdio/testcase.yaml @@ -0,0 +1,21 @@ +common: + tags: + - clib + min_ram: 128 + filter: not CONFIG_NATIVE_LIBC +tests: + libraries.libc.common.stdio.minimal: + tags: minimal_libc + filter: CONFIG_MINIMAL_LIBC_SUPPORTED + extra_configs: + - CONFIG_MINIMAL_LIBC=y + libraries.libc.common.stdio.picolibc: + tags: picolibc + filter: CONFIG_PICOLIBC_SUPPORTED + extra_configs: + - CONFIG_PICOLIBC=y + libraries.libc.common.stdio.newlib: + tags: newlib + filter: TOOLCHAIN_HAS_NEWLIB == 1 + extra_configs: + - CONFIG_NEWLIB_LIBC=y