#include <stdlib.h>
#include <stdio.h>
#include <setjmp.h>
#include <stdarg.h>
#include <cmocka.h>
#include <string.h>
#include <amxc/amxc.h>
#include <amxp/amxp.h>
#include "test_proc_ctrl.h"
#include <amxc/amxc_macros.h>
Go to the source code of this file.
|
static amxc_string_t | path |
|
◆ _GNU_SOURCE
◆ __real_amxc_var_init()
int __real_amxc_var_init |
( |
amxc_var_t *const |
var | ) |
|
◆ __real_fopen()
FILE* __real_fopen |
( |
const char * |
pathname, |
|
|
const char * |
mode |
|
) |
| |
◆ __real_getline()
ssize_t __real_getline |
( |
char ** |
lineptr, |
|
|
size_t * |
n, |
|
|
FILE * |
stream |
|
) |
| |
◆ __wrap_amxc_var_init()
int __wrap_amxc_var_init |
( |
amxc_var_t *const |
var | ) |
|
Definition at line 142 of file test_proc_ctrl.c.
int __real_amxc_var_init(amxc_var_t *const var)
◆ __wrap_fopen()
FILE * __wrap_fopen |
( |
const char * |
pathname, |
|
|
const char * |
mode |
|
) |
| |
Definition at line 129 of file test_proc_ctrl.c.
130 const char* f = amxc_string_get(&
path, 0);
132 if(strcmp(pathname, f) == 0) {
FILE * __real_fopen(const char *pathname, const char *mode)
static amxc_string_t path
◆ __wrap_getline()
ssize_t __wrap_getline |
( |
char ** |
lineptr, |
|
|
size_t * |
n, |
|
|
FILE * |
stream |
|
) |
| |
Definition at line 152 of file test_proc_ctrl.c.
ssize_t __real_getline(char **lineptr, size_t *n, FILE *stream)
◆ __wrap_kill() [1/2]
int __wrap_kill |
( |
pid_t |
pid, |
|
|
int |
sig |
|
) |
| |
◆ __wrap_kill() [2/2]
◆ handle_events()
static void handle_events |
( |
void |
| ) |
|
|
static |
Definition at line 106 of file test_proc_ctrl.c.
107 printf(
"Handling events ");
int amxp_signal_read(void)
Reads from the amxp signal file descriptor.
◆ read_sigalrm()
static void read_sigalrm |
( |
void |
| ) |
|
|
static |
Definition at line 85 of file test_proc_ctrl.c.
88 struct signalfd_siginfo fdsi;
92 sigaddset(&
mask, SIGALRM);
94 sigprocmask(SIG_BLOCK, &
mask, NULL);
96 sfd = signalfd(-1, &
mask, 0);
97 s = read(sfd, &fdsi,
sizeof(
struct signalfd_siginfo));
98 assert_int_equal(s,
sizeof(
struct signalfd_siginfo));
99 if(fdsi.ssi_signo == SIGALRM) {
100 printf(
"Got SIGALRM\n");
102 printf(
"Read unexpected signal\n");
◆ test_cmd_builder()
static int test_cmd_builder |
( |
amxc_array_t * |
cmd, |
|
|
UNUSED amxc_var_t * |
settings |
|
) |
| |
|
static |
Definition at line 114 of file test_proc_ctrl.c.
118 amxc_array_append_data(cmd, strdup(
"sleep "));
119 amxc_array_append_data(cmd, strdup(
"10m"));
◆ test_proc_can_stop_children()
void test_proc_can_stop_children |
( |
UNUSED void ** |
state | ) |
|
Definition at line 302 of file test_proc_ctrl.c.
306 amxc_string_init(&
path, 0);
311 amxc_var_init(&settings);
316 amxc_string_setf(&
path,
"/proc/%d/task/%d/children", ctrl->
proc->
pid, ctrl->
proc->
pid);
321 amxc_string_clean(&
path);
322 amxc_var_clean(&settings);
int amxp_proc_ctrl_new(amxp_proc_ctrl_t **proc, amxp_proc_ctrl_cmd_t cmd_build_fn)
Allocates and initializes an amxp_proc_ctrl_t.
int amxp_proc_ctrl_start(amxp_proc_ctrl_t *proc, uint32_t minutes, amxc_var_t *settings)
Launches the child process.
void amxp_proc_ctrl_delete(amxp_proc_ctrl_t **proc)
Clean-up and frees previously allocated memory.
void amxp_proc_ctrl_stop_childs(amxp_proc_ctrl_t *proc)
Stop all child processes of the child process.
int amxp_proc_ctrl_get_child_pids(amxp_proc_ctrl_t *proc)
Fetches the process ids of the children of the launched child process.
Structure containing the child process control.
static int test_cmd_builder(amxc_array_t *cmd, UNUSED amxc_var_t *settings)
int __wrap_amxc_var_init(amxc_var_t *const var)
ssize_t __wrap_getline(char **lineptr, size_t *n, FILE *stream)
◆ test_proc_can_stop_timer()
void test_proc_can_stop_timer |
( |
UNUSED void ** |
state | ) |
|
Definition at line 276 of file test_proc_ctrl.c.
283 amxc_var_init(&settings);
299 amxc_var_clean(&settings);
void amxp_proc_ctrl_set_active_duration(amxp_proc_ctrl_t *proc, uint32_t minutes)
Sets the active time durations.
amxp_timer_state_t amxp_timer_get_state(amxp_timer_t *timer)
Get the timer's state.
void amxp_timers_check(void)
Check all timers and call the callback function when the timer is in Timer expired state.
void amxp_timers_calculate(void)
Caclulates the remaining time of all timers.
◆ test_proc_ctrl_new_delete()
void test_proc_ctrl_new_delete |
( |
UNUSED void ** |
state | ) |
|
Definition at line 162 of file test_proc_ctrl.c.
167 assert_non_null(ctrl);
168 assert_non_null(ctrl->
proc);
169 assert_non_null(ctrl->
timer);
170 assert_int_equal(amxc_var_type_of(&ctrl->
child_proc_pids), AMXC_VAR_ID_NULL);
amxc_var_t child_proc_pids
◆ test_proc_ctrl_start_stop()
void test_proc_ctrl_start_stop |
( |
UNUSED void ** |
state | ) |
|
Definition at line 185 of file test_proc_ctrl.c.
192 amxc_var_init(&settings);
219 amxc_var_clean(&settings);
int amxp_proc_ctrl_stop(amxp_proc_ctrl_t *proc)
Stops the child process.
static void handle_events(void)
◆ test_proc_is_stopped_when_timer_expires()
void test_proc_is_stopped_when_timer_expires |
( |
UNUSED void ** |
state | ) |
|
Definition at line 222 of file test_proc_ctrl.c.
229 amxc_var_init(&settings);
245 amxc_var_clean(&settings);
bool amxp_subproc_is_running(const amxp_subproc_t *const subproc)
Checks if the child process is running.
static void read_sigalrm(void)
◆ test_proc_is_stopped_when_timer_is_set_after_start()
void test_proc_is_stopped_when_timer_is_set_after_start |
( |
UNUSED void ** |
state | ) |
|
Definition at line 248 of file test_proc_ctrl.c.
255 amxc_var_init(&settings);
273 amxc_var_clean(&settings);
◆ path