libamxp  1.4.0
Patterns C Implementation
test_syssig.c File Reference
#include <sys/time.h>
#include <sys/resource.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <inttypes.h>
#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#include <cmocka.h>
#include <amxc/amxc_variant_type.h>
#include <amxc/amxc_variant.h>
#include <amxp/amxp_syssig.h>
#include <amxp/variant_siginfo.h>
#include <amxp_signal_priv.h>
#include "test_syssig.h"
#include <amxc/amxc_macros.h>

Go to the source code of this file.

Functions

int __wrap_signalfd (int fd, const sigset_t *mask, int flags)
 
static void test_slot_sigchld (const char *const sig_name, const amxc_var_t *const data, UNUSED void *const priv)
 
int __wrap_signalfd (int fd, UNUSED const sigset_t *mask, UNUSED int flags)
 
void test_syssig_get_fd (UNUSED void **state)
 
void test_syssig_enable (UNUSED void **state)
 
void test_syssig_read (UNUSED void **state)
 

Variables

int sig_pipe [20] = { -1, -1 }
 
int count = 0
 

Function Documentation

◆ __wrap_signalfd() [1/2]

int __wrap_signalfd ( int  fd,
const sigset_t *  mask,
int  flags 
)

◆ __wrap_signalfd() [2/2]

int __wrap_signalfd ( int  fd,
UNUSED const sigset_t *  mask,
UNUSED int  flags 
)

Definition at line 97 of file test_syssig.c.

97  {
98  if(fd == -1) {
99  assert_int_equal(pipe(sig_pipe), 0);
100  } else {
101  assert_int_equal(fd, sig_pipe[0]);
102  }
103 
104  return sig_pipe[0];
105 }
int sig_pipe[20]
Definition: test_syssig.c:79

◆ test_slot_sigchld()

static void test_slot_sigchld ( const char *const  sig_name,
const amxc_var_t *const  data,
UNUSED void *const  priv 
)
static

Definition at line 84 of file test_syssig.c.

86  {
87  const amxp_siginfo_t* siginfo = amxc_var_constcast(amxp_siginfo_t, data);
88 
89  assert_ptr_not_equal(siginfo, NULL);
90  assert_string_equal(sig_name, strsignal(SIGCHLD));
91  assert_int_equal(siginfo->ssi_signo, SIGCHLD);
92  assert_int_equal(siginfo->ssi_pid, 5012);
93 
94  count++;
95 }
int count
Definition: test_syssig.c:80
struct signalfd_siginfo amxp_siginfo_t

◆ test_syssig_enable()

void test_syssig_enable ( UNUSED void **  state)

Definition at line 113 of file test_syssig.c.

113  {
114  sigset_t mask;
115  assert_int_not_equal(amxp_syssig_enable(AMXP_SYSSIG_MAX + 1, true), 0);
116 
117  assert_int_equal(amxp_syssig_enable(SIGINT, true), 0);
118  assert_int_equal(amxp_syssig_enable(SIGTERM, true), 0);
119  assert_int_equal(amxp_syssig_enable(SIGTERM, true), 0);
120  assert_int_not_equal(amxp_syssig_enable(SIGKILL, true), 0);
121  assert_int_not_equal(amxp_syssig_enable(SIGSTOP, true), 0);
122 
123  assert_true(amxp_syssig_is_enabled(SIGINT));
124  assert_true(amxp_syssig_is_enabled(SIGTERM));
125  assert_false(amxp_syssig_is_enabled(SIGKILL));
126  assert_false(amxp_syssig_is_enabled(SIGSTOP));
127 
128  sigprocmask(SIG_BLOCK, NULL, &mask);
129  assert_int_equal(sigismember(&mask, SIGINT), 1);
130  assert_int_equal(sigismember(&mask, SIGTERM), 1);
131 
132  assert_false(amxp_syssig_is_enabled(AMXP_SYSSIG_MAX + 1));
133 
134  assert_int_equal(amxp_syssig_enable(SIGINT, false), 0);
135  assert_int_equal(amxp_syssig_enable(SIGTERM, false), 0);
136  assert_int_equal(amxp_syssig_enable(SIGTERM, false), 0);
137 
138  assert_false(amxp_syssig_is_enabled(SIGINT));
139  assert_false(amxp_syssig_is_enabled(SIGTERM));
140 
141  sigprocmask(SIG_BLOCK, NULL, &mask);
142  assert_int_equal(sigismember(&mask, SIGINT), 0);
143  assert_int_equal(sigismember(&mask, SIGTERM), 0);
144 }
static sigset_t mask
Definition: amxp_syssig.c:68
bool amxp_syssig_is_enabled(const int sigid)
Checks if a system signal is being monitored.
Definition: amxp_syssig.c:97
#define AMXP_SYSSIG_MAX
Defines highest possible system signal.
Definition: amxp_syssig.h:95
int amxp_syssig_enable(const int sigid, const bool enable)
Enables or disables monitoring of a system signal.
Definition: amxp_syssig.c:70

◆ test_syssig_get_fd()

void test_syssig_get_fd ( UNUSED void **  state)

Definition at line 107 of file test_syssig.c.

107  {
108  int fd = amxp_syssig_get_fd();
109 
110  assert_int_equal(fd, sig_pipe[0]);
111 }
int amxp_syssig_get_fd(void)
Returns a file descriptor that can be used in an eventloop.
Definition: amxp_syssig.c:110

◆ test_syssig_read()

void test_syssig_read ( UNUSED void **  state)

Definition at line 146 of file test_syssig.c.

146  {
147  amxp_siginfo_t siginfo = {
148  .ssi_signo = SIGCHLD,
149  .ssi_errno = 0,
150  .ssi_code = 123,
151  .ssi_pid = 5012,
152  .ssi_uid = 100
153  };
154 
155  count = 0;
156  assert_int_equal(amxp_syssig_enable(SIGCHLD, true), 0);
157  assert_int_equal(amxp_slot_connect(NULL, strsignal(SIGCHLD), NULL, test_slot_sigchld, NULL), 0);
158  assert_int_equal(write(sig_pipe[1], &siginfo, sizeof(amxp_siginfo_t)), sizeof(amxp_siginfo_t));
159  assert_int_equal(amxp_syssig_read(), 0);
160  assert_int_equal(count, 1);
161 }
int amxp_slot_connect(amxp_signal_mngr_t *const sig_mngr, const char *const sig_name, const char *const expression, amxp_slot_fn_t fn, void *const priv)
Connects a slot (function) to a named signal of a signal manager.
Definition: amxp_slot.c:300
int amxp_syssig_read(void)
Reads from the file descriptor.
Definition: amxp_syssig.c:114
static void test_slot_sigchld(const char *const sig_name, const amxc_var_t *const data, UNUSED void *const priv)
Definition: test_syssig.c:84

Variable Documentation

◆ count

int count = 0

Definition at line 80 of file test_syssig.c.

◆ sig_pipe

int sig_pipe[20] = { -1, -1 }

Definition at line 79 of file test_syssig.c.