From 08bb4eebca7b5ff3bfadadf70ae320362184ed18 Mon Sep 17 00:00:00 2001 From: Abhinav Srivastava Date: Wed, 31 Jan 2024 19:18:00 -0500 Subject: [PATCH 1/3] posix: add header entry for putpmsg Add the header entry for putpmsg to the stropts.h file. Signed-off-by: Abhinav Srivastava --- include/zephyr/posix/stropts.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/zephyr/posix/stropts.h b/include/zephyr/posix/stropts.h index 9474c36edb2c03..8c20dfc46c3cb5 100644 --- a/include/zephyr/posix/stropts.h +++ b/include/zephyr/posix/stropts.h @@ -19,6 +19,8 @@ struct strbuf { int putmsg(int fildes, const struct strbuf *ctlptr, const struct strbuf *dataptr, int flags); +int putpmsg(int fildes, const struct strbuf *ctlptr, const struct strbuf *dataptr, int band, int flags); + #ifdef __cplusplus } #endif From c21b19ce071ae440f13a22baac5ea22fe8f076a8 Mon Sep 17 00:00:00 2001 From: Abhinav Srivastava Date: Wed, 31 Jan 2024 21:00:23 -0500 Subject: [PATCH 2/3] posix: Add implementation for putpmsg This adds an implementation for putpmsg, which is a stub. Signed-off-by: Abhinav Srivastava --- lib/posix/options/stropts.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/posix/options/stropts.c b/lib/posix/options/stropts.c index 54fca00cc9ff44..3dad6970830420 100644 --- a/lib/posix/options/stropts.c +++ b/lib/posix/options/stropts.c @@ -18,3 +18,16 @@ int putmsg(int fildes, const struct strbuf *ctlptr, const struct strbuf *dataptr errno = ENOSYS; return -1; } + +int putpmsg(int fildes, const struct strbuf *ctlptr, + const struct strbuf *dataptr, int band, int flags) +{ + ARG_UNUSED(fildes); + ARG_UNUSED(ctlptr); + ARG_UNUSED(dataptr); + ARG_UNUSED(band); + ARG_UNUSED(flags); + + errno = ENOSYS; + return -1; +} From 8df6648b0c90f5a9a8d5f06e94208e3fa7c9af74 Mon Sep 17 00:00:00 2001 From: Abhinav Srivastava Date: Thu, 1 Feb 2024 15:31:53 -0500 Subject: [PATCH 3/3] posix: Add putpmsg tests and configs Add tests for putpmsg and getpmsg. Also add the necessary Kconfig. Signed-off-by: Abhinav Srivastava --- .../portability/posix/option_groups/index.rst | 1 + lib/posix/CMakeLists.txt | 67 +++++++++++++++++++ lib/posix/options/Kconfig.stropts | 6 ++ tests/posix/common/src/stropts.c | 12 ++++ tests/posix/headers/src/stropts_h.c | 7 ++ 5 files changed, 93 insertions(+) diff --git a/doc/services/portability/posix/option_groups/index.rst b/doc/services/portability/posix/option_groups/index.rst index 7dd47616abb2ba..ebb9fb2e550b99 100644 --- a/doc/services/portability/posix/option_groups/index.rst +++ b/doc/services/portability/posix/option_groups/index.rst @@ -511,6 +511,7 @@ _XOPEN_STREAMS isastream(), putmsg(), putpmsg(), + putpmsg(), .. _Subprofiling Considerations: diff --git a/lib/posix/CMakeLists.txt b/lib/posix/CMakeLists.txt index fed728c17ba453..3cb6893554b119 100644 --- a/lib/posix/CMakeLists.txt +++ b/lib/posix/CMakeLists.txt @@ -2,3 +2,70 @@ add_subdirectory(options) add_subdirectory(shell) + +zephyr_syscall_header( + posix_clock.h +) + +zephyr_interface_library_named(posix_subsys) + +if(CONFIG_POSIX_API) + zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/posix) +endif() + +if(CONFIG_POSIX_SIGNAL) + set(STRSIGNAL_TABLE_H ${GEN_DIR}/posix/strsignal_table.h) + + add_custom_command( + OUTPUT ${STRSIGNAL_TABLE_H} + COMMAND + ${PYTHON_EXECUTABLE} + ${ZEPHYR_BASE}/scripts/build/gen_strsignal_table.py + -i ${ZEPHYR_BASE}/include/zephyr/posix/signal.h + -o ${STRSIGNAL_TABLE_H} + DEPENDS ${ZEPHYR_BASE}/include/zephyr/posix/signal.h + ) +endif() + +if(CONFIG_POSIX_API OR CONFIG_PTHREAD_IPC OR CONFIG_POSIX_CLOCK OR + CONFIG_POSIX_MQUEUE OR CONFIG_POSIX_FS OR CONFIG_EVENTFD OR CONFIG_GETOPT) + # This is a temporary workaround so that Newlib declares the appropriate + # types for us. POSIX features to be formalized as part of #51211 + zephyr_compile_options($<$:-D_POSIX_THREADS>) + zephyr_compile_options($<$:-D_POSIX_THREADS>) +endif() + +zephyr_library() +add_subdirectory_ifdef(CONFIG_GETOPT getopt) +add_subdirectory_ifdef(CONFIG_SHELL shell) +zephyr_library_sources_ifdef(CONFIG_EVENTFD eventfd.c) +zephyr_library_sources_ifdef(CONFIG_FNMATCH fnmatch.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_API perror.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK clock.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK nanosleep.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK sleep.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_FS fs.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_MQUEUE mqueue.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_SIGNAL signal.c ${STRSIGNAL_TABLE_H}) +zephyr_library_sources_ifdef(CONFIG_POSIX_UNAME uname.c) +zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC _common.c) +zephyr_library_sources_ifdef(CONFIG_PTHREAD_BARRIER barrier.c) +zephyr_library_sources_ifdef(CONFIG_PTHREAD_COND cond.c) +zephyr_library_sources_ifdef(CONFIG_PTHREAD_KEY key.c) +zephyr_library_sources_ifdef(CONFIG_PTHREAD_MUTEX mutex.c) +zephyr_library_sources_ifdef(CONFIG_PTHREAD pthread.c) +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_source_ifdef(CONFIG_POSIX_PUTPMSG stropts.c) + +zephyr_library_include_directories( + ${ZEPHYR_BASE}/kernel/include + ${ARCH_DIR}/${ARCH}/include +) + +zephyr_library_link_libraries(posix_subsys) +zephyr_library_property(ALLOW_EMPTY TRUE) diff --git a/lib/posix/options/Kconfig.stropts b/lib/posix/options/Kconfig.stropts index 347f0f33c150af..6d1d267db3efe8 100644 --- a/lib/posix/options/Kconfig.stropts +++ b/lib/posix/options/Kconfig.stropts @@ -7,3 +7,9 @@ config POSIX_PUTMSG default y if POSIX_API help This option provides support for the putmsg function used in message passing. + +config POSIX_PUTPMSG + bool "Support for putpmsg function" + default y if POSIX_API + help + This option provides support for the putpmsg function used in message passing. diff --git a/tests/posix/common/src/stropts.c b/tests/posix/common/src/stropts.c index 4c9221a398ca66..20bf27d569cc3a 100644 --- a/tests/posix/common/src/stropts.c +++ b/tests/posix/common/src/stropts.c @@ -18,4 +18,16 @@ ZTEST(stropts, test_putmsg) zassert_equal(errno, ENOSYS, "Expected errno ENOSYS, got %d", errno); } +ZTEST(stropts, test_putpmsg) +{ + const struct strbuf *ctrl = NULL; + const struct strbuf *data = NULL; + int fd = -1; + int band = 0; + int ret = putpmsg(fd, ctrl, data, band, 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 index a095c83c98ccf3..43585c87391194 100644 --- a/tests/posix/headers/src/stropts_h.c +++ b/tests/posix/headers/src/stropts_h.c @@ -26,3 +26,10 @@ ZTEST(posix_headers, test_stropts_h) zassert_not_equal(RS_HIPRI, ~RS_HIPRI); #endif } + +ZTEST(posix_headers, test_stropts_h_putpmsg) +{ + #ifdef CONFIG_POSIX_API + zassert_not_null((void *)putpmsg, "putpmsg is null"); + #endif +}