]> Kevux Git Server - fll/commitdiff
Feature: Add f_select_signal() and update unit tests.
authorKevin Day <kevin@kevux.org>
Fri, 28 Jul 2023 02:59:26 +0000 (21:59 -0500)
committerKevin Day <kevin@kevux.org>
Fri, 28 Jul 2023 02:59:26 +0000 (21:59 -0500)
This adds the missing pselect() wrapper, f_select_signal().

level_0/f_file/c/file.c
level_0/f_file/c/file.h
level_0/f_file/data/build/settings-mocks
level_0/f_file/data/build/settings-tests
level_0/f_file/tests/unit/c/mock-file.c
level_0/f_file/tests/unit/c/mock-file.h
level_0/f_file/tests/unit/c/test-file-select.c
level_0/f_file/tests/unit/c/test-file-select_signal.c [new file with mode: 0644]
level_0/f_file/tests/unit/c/test-file-select_signal.h [new file with mode: 0644]
level_0/f_file/tests/unit/c/test-file.c
level_0/f_file/tests/unit/c/test-file.h

index 9157d3a7eb0bf8f00e35f26bdae3e664a03797a7..4434051627652af2aac046012be4b020092dea3b 100644 (file)
@@ -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_
index 682824dd508b1df7ad27ec45fb2b963ece65d514..250e2fe1b407f03ccd3f02cf4e6e004f6a28e71f 100644 (file)
@@ -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
index e42f3a46ea59e0a1e34e617a61cbcd97812ba0ce..515134c626581f2e455d1d1d03508a7e8f6ec029 100644 (file)
@@ -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
index 58503af0cde01745975b3917ca7d8f6823cd1183..d93bd70ed683cfb4c6d4c62d300071a1e7197429 100644 (file)
@@ -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
index 68d18ac92366564d2998970e64be3dd6b989333f..67918deb24b43fe46a2cb39449c42616b0b94a67 100644 (file)
@@ -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);
index dd584f492f40422d6b178f0e3fba5c0756473c38..9017aee7a508b5f4a3ab24b52b5ddca8577153cf 100644 (file)
@@ -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);
index 2a06690bfd96849cf410f148deeaceb3771576e1..737c9c4a59f2e3a15f8f1b349ece0a5aaec7067a 100644 (file)
@@ -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 (file)
index 0000000..bd5da91
--- /dev/null
@@ -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 (file)
index 0000000..66bf609
--- /dev/null
@@ -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
index 947ab321d7840e3f046c0abc7fab1a997e0060df..ed8c3bdcba2e4851ed2c06d4e8cdcef62f8bb1e2 100644 (file)
@@ -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),
index df14c5ac4ae37b39738e13e5b2d15b73fee5d8dd..c7abc55110d9bad94ad56df1e003d95ea4cfd3f1 100644 (file)
@@ -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"