From 8d1424b776d36879c4311eee20c765579c1eb595 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 27 Jul 2023 21:59:26 -0500 Subject: [PATCH] Feature: Add f_select_signal() and update unit tests. This adds the missing pselect() wrapper, f_select_signal(). --- level_0/f_file/c/file.c | 19 + level_0/f_file/c/file.h | 50 +- level_0/f_file/data/build/settings-mocks | 3 +- level_0/f_file/data/build/settings-tests | 2 +- level_0/f_file/tests/unit/c/mock-file.c | 13 + level_0/f_file/tests/unit/c/mock-file.h | 1 + level_0/f_file/tests/unit/c/test-file-select.c | 32 +- .../f_file/tests/unit/c/test-file-select_signal.c | 531 +++++++++++++++++++++ .../f_file/tests/unit/c/test-file-select_signal.h | 34 ++ level_0/f_file/tests/unit/c/test-file.c | 5 + level_0/f_file/tests/unit/c/test-file.h | 1 + 11 files changed, 676 insertions(+), 15 deletions(-) create mode 100644 level_0/f_file/tests/unit/c/test-file-select_signal.c create mode 100644 level_0/f_file/tests/unit/c/test-file-select_signal.h diff --git a/level_0/f_file/c/file.c b/level_0/f_file/c/file.c index 9157d3a..4434051 100644 --- a/level_0/f_file/c/file.c +++ b/level_0/f_file/c/file.c @@ -1915,6 +1915,25 @@ extern "C" { } #endif // _di_f_file_select_ +#ifndef _di_f_file_select_signal_ + f_status_t f_file_select_signal(const int highest_plus_one, fd_set * const read, fd_set * const write, fd_set * const except, const struct timespec * const timeout, const sigset_t * const signal) { + + if (!highest_plus_one) return F_data_not; + if (!read && !write && !except && !timeout) return F_data_not; + + if (pselect(highest_plus_one, read, write, except, timeout, signal) == -1) { + if (errno == EBADF) return F_status_set_error(F_file_descriptor); + if (errno == EINTR) return F_status_set_error(F_interrupt); + if (errno == EINVAL) return F_status_set_error(F_parameter); + if (errno == ENOMEM) return F_status_set_error(F_memory_not); + + return F_status_set_error(F_failure); + } + + return F_none; + } +#endif // _di_f_file_select_signal_ + #ifndef _di_f_file_size_ f_status_t f_file_size(const f_string_static_t path, const bool dereference, off_t * const size) { #ifndef _di_level_0_parameter_checking_ diff --git a/level_0/f_file/c/file.h b/level_0/f_file/c/file.h index 682824d..250e2fe 100644 --- a/level_0/f_file/c/file.h +++ b/level_0/f_file/c/file.h @@ -1960,8 +1960,6 @@ extern "C" { /** * Monitor one or more file descriptors. * - * @todo Probably should implement a pselect(). - * * Warning: Some libc implementations, such as GLIBC, use an upper limit of 1023 file descriptors. * The linux kernel general does not have such a limit. * To more safely handle more than 1023 file desciptors, instead consider f_file_poll(); @@ -1980,7 +1978,7 @@ extern "C" { * (optional) The set of file descriptors for descriptors that become available for any error conditions. * Set to NULL to not use. * @param timeout - * (optional) + * (optional) The time to wait before returning. * Set to NULL to not use. * * @return @@ -2000,6 +1998,52 @@ extern "C" { #endif // _di_f_file_select_ /** + * Monitor one or more file descriptors in a signal safe manner. + * + * Warning: Some libc implementations, such as GLIBC, use an upper limit of 1023 file descriptors. + * The linux kernel general does not have such a limit. + * To more safely handle more than 1023 file desciptors, instead consider f_file_poll(); + * + * @param highest + * The value of the highest file descriptor between all provided sets (read, write, and except) plus one. + * The caller must remember that one must be added to the highest file descriptor as per requirements by select(). + * This cannot be 0. + * @param read + * (optional) The set of file descriptors for descriptors that become available for reading. + * Set to NULL to not use. + * @param write + * (optional) The set of file descriptors for descriptors that become available for writing. + * Set to NULL to not use. + * @param except + * (optional) The set of file descriptors for descriptors that become available for any error conditions. + * Set to NULL to not use. + * @param timeout + * (optional) The time to wait before returning. + * Set to NULL to not use. + * @param signal + * (optional) The signals to atomically mask while running the pselect() operation. + * This effectively wraps the select call with these two calls: + * - pthread_sigmask(SIG_SETMASK, &sigmask, &origmask); + * - pthread_sigmask(SIG_SETMASK, &origmask, NULL); + * Set to NULL to not use. + * + * @return + * F_none on success. + * F_data_not if all of read, write, except, and timeout are NULL (having at least one is required) or when highest_plus_one is 0. + * + * F_file_descriptor (with error bit) if the file descriptor is invalid. + * F_interrupt (with error bit) when program received an interrupt signal, halting operation. + * F_memory_not (with error bit) if out of memory. + * F_parameter (with error bit) if a parameter is invalid. + * F_failure (with error bit) on any other error. + * + * @see pselect() + */ +#ifndef _di_f_file_select_signal_ + extern f_status_t f_file_select_signal(const int highest_plus_one, fd_set * const read, fd_set * const write, fd_set * const except, const struct timespec * const timeout, const sigset_t * const signal); +#endif // _di_f_file_select_signal_ + +/** * Read the size of file. * * @param path diff --git a/level_0/f_file/data/build/settings-mocks b/level_0/f_file/data/build/settings-mocks index e42f3a4..515134c 100644 --- a/level_0/f_file/data/build/settings-mocks +++ b/level_0/f_file/data/build/settings-mocks @@ -97,9 +97,10 @@ flags -Wl,--wrap=mkfifo flags -Wl,--wrap=mkfifoat flags -Wl,--wrap=mknod flags -Wl,--wrap=mknodat -flags -Wl,--wrap=poll flags -Wl,--wrap=open flags -Wl,--wrap=openat +flags -Wl,--wrap=poll +flags -Wl,--wrap=pselect flags -Wl,--wrap=read flags -Wl,--wrap=readlink flags -Wl,--wrap=readlinkat diff --git a/level_0/f_file/data/build/settings-tests b/level_0/f_file/data/build/settings-tests index 58503af..d93bd70 100644 --- a/level_0/f_file/data/build/settings-tests +++ b/level_0/f_file/data/build/settings-tests @@ -25,7 +25,7 @@ build_language c build_libraries -lc -lcmocka build_libraries-individual -lf_memory -lf_string -lf_file -build_sources_program test-file-access.c test-file-access_at.c test-file-clone.c test-file-close.c test-file-copy.c test-file-create.c test-file-create_at.c test-file-create_device.c test-file-create_device_at.c test-file-create_fifo.c test-file-create_fifo_at.c test-file-create_node.c test-file-create_node_at.c test-file-descriptor.c test-file-exists.c test-file-exists_at.c test-file-flush.c test-file-group_read.c test-file-is.c test-file-is_at.c test-file-is_stat.c test-file-link.c test-file-link_at.c test-file-link_hard.c test-file-link_hard_at.c test-file-link_read.c test-file-link_read_at.c test-file-manipulate.c test-file-mode_determine.c test-file-mode_from_string.c test-file-mode_read.c test-file-mode_read_at.c test-file-mode_set.c test-file-mode_set_at.c test-file-mode_to_mode.c test-file-name_base.c test-file-name_directory.c test-file-open.c test-file-open_at.c test-file-owner_read.c test-file-read.c test-file-read_block.c test-file-read_until.c test-file-remove.c test-file-remove_at.c test-file-rename.c test-file-rename_at.c test-file-role_change.c test-file-role_change_at.c test-file-poll.c test-file-seek.c test-file-select.c test-file-size.c test-file-size_at.c test-file-size_by_id.c test-file-stat.c test-file-stat_at.c test-file-stat_by_id.c test-file-stream_close.c test-file-stream_open_descriptor.c test-file-stream_open.c test-file-stream_read.c test-file-stream_read_block.c test-file-stream_read_until.c test-file-stream_reopen.c test-file-stream_write.c test-file-stream_write_block.c test-file-stream_write_until.c test-file-stream_write_range.c test-file-touch.c test-file-touch_at.c test-file-type.c test-file-type_at.c test-file-umask_get.c test-file-umask_set.c test-file-write.c test-file-write_block.c test-file-write_until.c test-file-write_range.c +build_sources_program test-file-access.c test-file-access_at.c test-file-clone.c test-file-close.c test-file-copy.c test-file-create.c test-file-create_at.c test-file-create_device.c test-file-create_device_at.c test-file-create_fifo.c test-file-create_fifo_at.c test-file-create_node.c test-file-create_node_at.c test-file-descriptor.c test-file-exists.c test-file-exists_at.c test-file-flush.c test-file-group_read.c test-file-is.c test-file-is_at.c test-file-is_stat.c test-file-link.c test-file-link_at.c test-file-link_hard.c test-file-link_hard_at.c test-file-link_read.c test-file-link_read_at.c test-file-manipulate.c test-file-mode_determine.c test-file-mode_from_string.c test-file-mode_read.c test-file-mode_read_at.c test-file-mode_set.c test-file-mode_set_at.c test-file-mode_to_mode.c test-file-name_base.c test-file-name_directory.c test-file-open.c test-file-open_at.c test-file-owner_read.c test-file-read.c test-file-read_block.c test-file-read_until.c test-file-remove.c test-file-remove_at.c test-file-rename.c test-file-rename_at.c test-file-role_change.c test-file-role_change_at.c test-file-poll.c test-file-seek.c test-file-select.c test-file-select_signal.c test-file-size.c test-file-size_at.c test-file-size_by_id.c test-file-stat.c test-file-stat_at.c test-file-stat_by_id.c test-file-stream_close.c test-file-stream_open_descriptor.c test-file-stream_open.c test-file-stream_read.c test-file-stream_read_block.c test-file-stream_read_until.c test-file-stream_reopen.c test-file-stream_write.c test-file-stream_write_block.c test-file-stream_write_until.c test-file-stream_write_range.c test-file-touch.c test-file-touch_at.c test-file-type.c test-file-type_at.c test-file-umask_get.c test-file-umask_set.c test-file-write.c test-file-write_block.c test-file-write_until.c test-file-write_range.c build_sources_program test-file.c build_script no diff --git a/level_0/f_file/tests/unit/c/mock-file.c b/level_0/f_file/tests/unit/c/mock-file.c index 68d18ac..67918de 100644 --- a/level_0/f_file/tests/unit/c/mock-file.c +++ b/level_0/f_file/tests/unit/c/mock-file.c @@ -509,6 +509,19 @@ int __wrap_poll(struct pollfd *fds, nfds_t nfds, int timeout) { return mock_type(int); } +int __wrap_pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask) { + + const bool failure = mock_type(bool); + + if (failure) { + errno = mock_type(int); + + return -1; + } + + return mock_type(int); +} + ssize_t __wrap_read(int fd, void *buf, size_t count) { const bool failure = mock_type(bool); diff --git a/level_0/f_file/tests/unit/c/mock-file.h b/level_0/f_file/tests/unit/c/mock-file.h index dd584f4..9017aee 100644 --- a/level_0/f_file/tests/unit/c/mock-file.h +++ b/level_0/f_file/tests/unit/c/mock-file.h @@ -67,6 +67,7 @@ extern int __wrap_mknodat(int dirfd, const char *pathname, mode_t mode, dev_t de extern int __wrap_open(const char *pathname, int flags, mode_t mode); extern int __wrap_openat(int dirfd, const char *pathname, int flags, mode_t mode); extern int __wrap_poll(struct pollfd *fds, nfds_t nfds, int timeout); +extern int __wrap_pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask); extern ssize_t __wrap_read(int fd, void *buf, size_t count); extern ssize_t __wrap_readlink(const char *pathname, char *buf, size_t bufsiz); extern ssize_t __wrap_readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz); diff --git a/level_0/f_file/tests/unit/c/test-file-select.c b/level_0/f_file/tests/unit/c/test-file-select.c index 2a06690..737c9c4 100644 --- a/level_0/f_file/tests/unit/c/test-file-select.c +++ b/level_0/f_file/tests/unit/c/test-file-select.c @@ -59,6 +59,12 @@ void test__f_file_select__returns_data_not(void **state) { } { + const f_status_t status = f_file_select(0, &read, &write, &except, 0); + + assert_int_equal(status, F_data_not); + } + + { const f_status_t status = f_file_select(0, &read, &write, 0, &timeout); assert_int_equal(status, F_data_not); @@ -77,13 +83,13 @@ void test__f_file_select__returns_data_not(void **state) { } { - const f_status_t status = f_file_select(0, 0, 0, &except, &timeout); + const f_status_t status = f_file_select(0, 0, &read, &except, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_select(0, 0, &write, 0, &timeout); + const f_status_t status = f_file_select(0, 0, &read, 0, &timeout); assert_int_equal(status, F_data_not); } @@ -95,49 +101,55 @@ void test__f_file_select__returns_data_not(void **state) { } { - const f_status_t status = f_file_select(0, &read, &write, &except, 0); + const f_status_t status = f_file_select(0, 0, &write, 0, &timeout); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_select(0, &read, &write, 0, 0); + const f_status_t status = f_file_select(0, 0, &write, &except, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_select(0, &read, 0, &except, 0); + const f_status_t status = f_file_select(0, 0, 0, 0, &timeout); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_select(0, 0, &write, &except, 0); + const f_status_t status = f_file_select(0, 0, 0, &except, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_select(0, 0, 0, &except, 0); + const f_status_t status = f_file_select(0, 0, &write, 0, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_select(0, 0, &write, 0, 0); + const f_status_t status = f_file_select(0, &read, 0, 0, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_select(0, 0, 0, &except, 0); + const f_status_t status = f_file_select(0, &read, &write, 0, 0); assert_int_equal(status, F_data_not); } { - const f_status_t status = f_file_select(0, 0, 0, 0, &timeout); + const f_status_t status = f_file_select(0, &read, 0, &except, 0); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select(0, &read, 0, 0, &timeout); assert_int_equal(status, F_data_not); } diff --git a/level_0/f_file/tests/unit/c/test-file-select_signal.c b/level_0/f_file/tests/unit/c/test-file-select_signal.c new file mode 100644 index 0000000..bd5da91 --- /dev/null +++ b/level_0/f_file/tests/unit/c/test-file-select_signal.c @@ -0,0 +1,531 @@ +#include "test-file.h" +#include "test-file-select_signal.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_file_select_signal__fails(void **state) { + + { + fd_set read; + + memset(&read, 0, sizeof(fd_set)); + + int errnos[] = { + EBADF, + EINTR, + EINVAL, + ENOMEM, + mock_errno_generic, + }; + + f_status_t statuss[] = { + F_file_descriptor, + F_interrupt, + F_parameter, + F_memory_not, + F_failure, + }; + + for (int i = 0; i < 5; ++i) { + + will_return(__wrap_pselect, true); + will_return(__wrap_pselect, errnos[i]); + + const f_status_t status = f_file_select_signal(1, &read, 0, 0, 0, 0); + + assert_int_equal(status, F_status_set_error(statuss[i])); + } // for + } +} + +void test__f_file_select_signal__returns_data_not(void **state) { + + fd_set read; + fd_set write; + fd_set except; + struct timespec timeout; + sigset_t signal; + + memset(&read, 0, sizeof(fd_set)); + memset(&write, 0, sizeof(fd_set)); + memset(&except, 0, sizeof(fd_set)); + memset(&timeout, 0, sizeof(struct timespec)); + memset(&signal, 0, sizeof(sigset_t)); + + { + const f_status_t status = f_file_select_signal(0, &read, &write, &except, &timeout, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, &read, &write, &except, &timeout, 0); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, &read, &write, &except, 0, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, &read, &write, 0, &timeout, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, &read, 0, &except, &timeout, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, &write, &except, &timeout, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, 0, &except, &timeout, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, &write, 0, &timeout, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, &write, &except, 0, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, &write, &except, &timeout, 0); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, &read, &except, &timeout, 0); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, &read, &except, 0, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, &read, 0, &timeout, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, 0, &except, &timeout, 0); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, 0, &except, 0, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, 0, 0, &timeout, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, 0, 0, 0, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, 0, 0, &timeout, 0); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, 0, &except, 0, 0); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, &write, 0, 0, 0); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, &read, 0, 0, 0, 0); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, 0, &write, 0, 0, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, &read, 0, 0, 0, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, &read, &write, 0, 0, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, &read, 0, &except, 0, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(0, &read, 0, 0, &timeout, &signal); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(1, 0, 0, 0, 0, 0); + + assert_int_equal(status, F_data_not); + } + + { + const f_status_t status = f_file_select_signal(1, 0, 0, 0, 0, &signal); + + assert_int_equal(status, F_data_not); + } +} + +void test__f_file_select_signal__works(void **state) { + + fd_set read; + fd_set write; + fd_set except; + struct timespec timeout; + sigset_t signal; + + memset(&read, 0, sizeof(fd_set)); + memset(&write, 0, sizeof(fd_set)); + memset(&except, 0, sizeof(fd_set)); + memset(&timeout, 0, sizeof(struct timespec)); + memset(&signal, 0, sizeof(sigset_t)); + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, &read, &write, &except, &timeout, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, &read, &write, &except, &timeout, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, &read, &write, &except, 0, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, &read, &write, 0, &timeout, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, &read, 0, &except, &timeout, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, 0, &write, &except, &timeout, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, &read, 0, 0, &timeout, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, &read, 0, &except, 0, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, &read, 0, &except, &timeout, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, 0, &write, 0, &timeout, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, 0, &write, &except, 0, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, 0, &write, &except, &timeout, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, 0, 0, &except, &timeout, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, 0, &read, &except, 0, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, &timeout); + + const f_status_t status = f_file_select_signal(1, 0, &read, &except, &timeout, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, &read, &write, 0, 0, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, &read, &write, 0, &timeout, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, &read, 0, &except, 0, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, &read, 0, &except, &timeout, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, 0, &write, &except, 0, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, 0, &write, &except, &timeout, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, &read, 0, 0, 0, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, 0, &write, 0, 0, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, 0, 0, &except, 0, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, 0, 0, 0, &timeout, &signal); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, &read, 0, 0, &timeout, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, 0, &write, 0, &timeout, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, 0, 0, &except, &timeout, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, 0, 0, 0, &timeout, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, 0, 0, &except, 0, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, 0, &write, 0, 0, 0); + + assert_int_equal(status, F_none); + } + + { + will_return(__wrap_pselect, false); + will_return(__wrap_pselect, 0); + + const f_status_t status = f_file_select_signal(1, &read, 0, 0, 0, 0); + + assert_int_equal(status, F_none); + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_file/tests/unit/c/test-file-select_signal.h b/level_0/f_file/tests/unit/c/test-file-select_signal.h new file mode 100644 index 0000000..66bf609 --- /dev/null +++ b/level_0/f_file/tests/unit/c/test-file-select_signal.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: File + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the file project. + */ +#ifndef _TEST__F_file_select_signal_h +#define _TEST__F_file_select_signal_h + +/** + * Test that function fails. + * + * @see f_file_select_signal() + */ +extern void test__f_file_select_signal__fails(void **state); + +/** + * Test that function works but the path is empty. + * + * @see f_file_select_signal() + */ +extern void test__f_file_select_signal__returns_data_not(void **state); + +/** + * Test that function works. + * + * @see f_file_select_signal() + */ +extern void test__f_file_select_signal__works(void **state); + +#endif // _TEST__F_file_select_h diff --git a/level_0/f_file/tests/unit/c/test-file.c b/level_0/f_file/tests/unit/c/test-file.c index 947ab32..ed8c3bd 100644 --- a/level_0/f_file/tests/unit/c/test-file.c +++ b/level_0/f_file/tests/unit/c/test-file.c @@ -265,6 +265,10 @@ int main(void) { cmocka_unit_test(test__f_file_select__returns_data_not), cmocka_unit_test(test__f_file_select__works), + cmocka_unit_test(test__f_file_select_signal__fails), + cmocka_unit_test(test__f_file_select_signal__returns_data_not), + cmocka_unit_test(test__f_file_select_signal__works), + cmocka_unit_test(test__f_file_size__fails), cmocka_unit_test(test__f_file_size__returns_data_not), cmocka_unit_test(test__f_file_size__works), @@ -434,6 +438,7 @@ int main(void) { // f_file_role_change_at() doesn't use parameter checking. cmocka_unit_test(test__f_file_seek__parameter_checking), // f_file_select() doesn't use parameter checking. + // f_file_select_signal() doesn't use parameter checking. cmocka_unit_test(test__f_file_size__parameter_checking), cmocka_unit_test(test__f_file_size_at__parameter_checking), cmocka_unit_test(test__f_file_size_by_id__parameter_checking), diff --git a/level_0/f_file/tests/unit/c/test-file.h b/level_0/f_file/tests/unit/c/test-file.h index df14c5a..c7abc55 100644 --- a/level_0/f_file/tests/unit/c/test-file.h +++ b/level_0/f_file/tests/unit/c/test-file.h @@ -78,6 +78,7 @@ #include "test-file-role_change_at.h" #include "test-file-seek.h" #include "test-file-select.h" +#include "test-file-select_signal.h" #include "test-file-size.h" #include "test-file-size_at.h" #include "test-file-size_by_id.h" -- 1.8.3.1