From 601c4343f1ec4e3aa0fc8f99bfd9a374a6ede98d Mon Sep 17 00:00:00 2001 From: Abhinav Srivastava Date: Fri, 26 Jan 2024 03:37:36 -0500 Subject: [PATCH 1/3] posix: add headers for stropts Minimal header for stropts Signed-off-by: Abhinav Srivastava --- include/zephyr/posix/stropts.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 include/zephyr/posix/stropts.h diff --git a/include/zephyr/posix/stropts.h b/include/zephyr/posix/stropts.h new file mode 100644 index 000000000000..dd8988f9a729 --- /dev/null +++ b/include/zephyr/posix/stropts.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 Abhinav Srivastava + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef ZEPHYR_INCLUDE_POSIX_STROPTS_H_ +#define ZEPHYR_INCLUDE_POSIX_STROPTS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct strbuf { + int maxlen; + int len; + char *buf; +}; + +int putmsg(int fildes, const struct strbuf *ctlptr, const struct strbuf *dataptr, int flags); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_POSIX_STROPTS_H_ */ From 1e92152ec2b9e5c7990ccc627d0fb8308ddfc036 Mon Sep 17 00:00:00 2001 From: Abhinav Srivastava Date: Fri, 26 Jan 2024 03:42:58 -0500 Subject: [PATCH 2/3] posix: putmsg implementation and configurations Add needed KConfig, CMakeList and Stropts.c Signed-off-by: Abhinav Srivastava --- lib/posix/CMakeLists.txt | 2 +- lib/posix/Kconfig | 1 + lib/posix/Kconfig.stropts | 9 +++++++++ lib/posix/stropts.c | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 lib/posix/Kconfig.stropts create mode 100644 lib/posix/stropts.c diff --git a/lib/posix/CMakeLists.txt b/lib/posix/CMakeLists.txt index 5477e27b3868..5d822bd375a4 100644 --- a/lib/posix/CMakeLists.txt +++ b/lib/posix/CMakeLists.txt @@ -57,7 +57,7 @@ zephyr_library_sources_ifdef(CONFIG_PTHREAD_RWLOCK rwlock.c) zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC semaphore.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_SPINLOCK spinlock.c) -zephyr_library_sources_ifdef(CONFIG_TIMER timer.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_PUTMSG stropts.c) zephyr_library_include_directories( ${ZEPHYR_BASE}/kernel/include diff --git a/lib/posix/Kconfig b/lib/posix/Kconfig index b1443a5ab715..6547b1bea1f9 100644 --- a/lib/posix/Kconfig +++ b/lib/posix/Kconfig @@ -58,6 +58,7 @@ source "lib/posix/Kconfig.signal" source "lib/posix/Kconfig.spinlock" source "lib/posix/Kconfig.timer" source "lib/posix/Kconfig.uname" +source "lib/posix/Kconfig.stropts" rsource "shell/Kconfig" diff --git a/lib/posix/Kconfig.stropts b/lib/posix/Kconfig.stropts new file mode 100644 index 000000000000..347f0f33c150 --- /dev/null +++ b/lib/posix/Kconfig.stropts @@ -0,0 +1,9 @@ +# copyright (c) 2024 Abhinav Srivastava +# +# SPDX-License-Identifier: Apache-2.0 + +config POSIX_PUTMSG + bool "Support for putmsg function" + default y if POSIX_API + help + This option provides support for the putmsg function used in message passing. diff --git a/lib/posix/stropts.c b/lib/posix/stropts.c new file mode 100644 index 000000000000..54fca00cc9ff --- /dev/null +++ b/lib/posix/stropts.c @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Abhinav Srivastava + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +int putmsg(int fildes, const struct strbuf *ctlptr, const struct strbuf *dataptr, int flags) +{ + ARG_UNUSED(fildes); + ARG_UNUSED(ctlptr); + ARG_UNUSED(dataptr); + ARG_UNUSED(flags); + + errno = ENOSYS; + return -1; +} From 17ac740729b747dd1a633b06790e040fa6b97948 Mon Sep 17 00:00:00 2001 From: Abhinav Srivastava Date: Sun, 28 Jan 2024 23:49:24 -0500 Subject: [PATCH 3/3] posix: Add tests for stropts Add tests, Fix config issues, Re-add Timer Signed-off-by: Abhinav Srivastava --- include/zephyr/posix/stropts.h | 1 + lib/posix/CMakeLists.txt | 1 + tests/posix/common/src/stropts.c | 21 +++++++++++++++++++++ tests/posix/headers/src/stropts_h.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 tests/posix/common/src/stropts.c create mode 100644 tests/posix/headers/src/stropts_h.c diff --git a/include/zephyr/posix/stropts.h b/include/zephyr/posix/stropts.h index dd8988f9a729..9474c36edb2c 100644 --- a/include/zephyr/posix/stropts.h +++ b/include/zephyr/posix/stropts.h @@ -5,6 +5,7 @@ */ #ifndef ZEPHYR_INCLUDE_POSIX_STROPTS_H_ #define ZEPHYR_INCLUDE_POSIX_STROPTS_H_ +#define RS_HIPRI BIT(0) #ifdef __cplusplus extern "C" { diff --git a/lib/posix/CMakeLists.txt b/lib/posix/CMakeLists.txt index 5d822bd375a4..c8d836f58464 100644 --- a/lib/posix/CMakeLists.txt +++ b/lib/posix/CMakeLists.txt @@ -57,6 +57,7 @@ zephyr_library_sources_ifdef(CONFIG_PTHREAD_RWLOCK rwlock.c) zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC semaphore.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_SPINLOCK spinlock.c) +zephyr_library_sources_ifdef(CONFIG_TIMER timer.c) zephyr_library_sources_ifdef(CONFIG_POSIX_PUTMSG stropts.c) zephyr_library_include_directories( diff --git a/tests/posix/common/src/stropts.c b/tests/posix/common/src/stropts.c new file mode 100644 index 000000000000..4c9221a398ca --- /dev/null +++ b/tests/posix/common/src/stropts.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Abhinav Srivastava + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include + +ZTEST(stropts, test_putmsg) +{ + const struct strbuf *ctrl = NULL; + const struct strbuf *data = NULL; + int fd = -1; + int ret = putmsg(fd, ctrl, data, 0); + + zassert_equal(ret, -1, "Expected return value -1, got %d", ret); + zassert_equal(errno, ENOSYS, "Expected errno ENOSYS, got %d", errno); +} + +ZTEST_SUITE(stropts, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/posix/headers/src/stropts_h.c b/tests/posix/headers/src/stropts_h.c new file mode 100644 index 000000000000..a095c83c98cc --- /dev/null +++ b/tests/posix/headers/src/stropts_h.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 Abhinav Srivastava + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "_common.h" +#ifdef CONFIG_POSIX_API +#include +#else +#include +#endif + +/** + * @brief Test existence and basic functionality of stropts.h + * + * @see stropts.h + */ +ZTEST(posix_headers, test_stropts_h) +{ + #ifdef CONFIG_POSIX_API + zassert_not_null((void *)putmsg, "putmsg is null"); + + zassert_true(sizeof(((struct strbuf *)0)->maxlen) > 0, "maxlen size is 0"); + zassert_true(sizeof(((struct strbuf *)0)->len) > 0, "len size is 0"); + zassert_true(sizeof(((struct strbuf *)0)->buf) > 0, "buf size is 0"); + zassert_not_equal(RS_HIPRI, ~RS_HIPRI); + #endif +}