65 #include <amxc/amxc_variant.h>
66 #include <amxc/amxc_lqueue.h>
74 #include <amxc/amxc_macros.h>
78 UNUSED const amxc_var_t*
const data,
85 printf(
"Handling events ");
99 assert_ptr_not_equal(subproc, NULL);
105 assert_int_equal(subproc->
pid, 0);
108 for(
int i = 0; i < 3; i++) {
109 for(
int j = 0; j < 2; j++) {
110 assert_int_equal(subproc->
fd[i][j], -1);
115 assert_ptr_equal(subproc, NULL);
123 assert_ptr_not_equal(subproc, NULL);
128 assert_int_not_equal(fd, -1);
136 assert_ptr_equal(subproc, NULL);
141 char* cmd[] = {
"ls",
"-la", NULL };
142 char* cmd2[] = { NULL };
145 assert_ptr_not_equal(subproc, NULL);
154 printf(
"Waiting for sigchld");
168 assert_ptr_equal(subproc, NULL);
175 amxc_array_init(&cmd, 2);
176 amxc_array_append_data(&cmd,
"ls");
177 amxc_array_append_data(&cmd,
"-la");
180 assert_ptr_not_equal(subproc, NULL);
189 printf(
"Waiting for sigchld");
201 amxc_array_clean(&cmd, NULL);
205 assert_ptr_equal(subproc, NULL);
210 char buffer[1024] =
"";
212 char* cmd[] = {
"ls",
"-la", NULL };
215 assert_ptr_not_equal(subproc, NULL);
218 assert_int_not_equal(fd, -1);
221 for(
int i = 0; i < 2; i++) {
227 while(read(fd, buffer, 1023) > 0) {
228 printf(
"%s", buffer);
239 assert_ptr_equal(subproc, NULL);
244 char buffer[1024] =
"";
248 assert_ptr_not_equal(subproc, NULL);
251 assert_int_not_equal(fd, -1);
256 for(
int i = 0; i < 2; i++) {
262 while(read(fd, buffer, 1023) > 0) {
263 printf(
"%s", buffer);
274 assert_ptr_equal(subproc, NULL);
281 assert_ptr_not_equal(subproc, NULL);
299 assert_ptr_equal(subproc, NULL);
306 assert_ptr_not_equal(subproc, NULL);
325 assert_ptr_equal(subproc, NULL);
332 char* cmd_sleep_10[] = {
"sleep",
"10", NULL};
335 char* cmd_sleep_2[] = {
"sleep",
"2", NULL};
338 assert_ptr_not_equal(subproc_sleep_10, NULL);
341 assert_ptr_not_equal(subproc_sleep_2, NULL);
345 assert_int_equal(err, 0);
350 assert_int_equal(err, 1);
355 assert_int_equal(err, 0);
361 assert_int_equal(err, 0);
366 assert_int_equal(err, 0);
373 assert_int_equal(err, 0);
378 assert_int_equal(err, 0);
385 assert_int_equal(err, 0);
390 assert_int_equal(err, 1);
396 assert_int_equal(err, 0);
401 assert_int_not_equal(err, 0);
404 assert_int_not_equal(err, 0);
408 assert_int_equal(err, 0);
413 assert_int_not_equal(err, 0);
417 assert_int_equal(err, 0);
421 assert_ptr_equal(subproc_sleep_10, NULL);
424 assert_ptr_equal(subproc_sleep_2, NULL);
431 char* cmd_sleep_1[] = {
"sleep",
"2", NULL};
435 assert_int_equal(result, -1);
438 assert_int_equal(result, -1);
441 assert_int_equal(result, -1);
444 assert_int_equal(result, -1);
447 assert_ptr_not_equal(subproc, NULL);
450 assert_int_equal(err, 0);
454 assert_int_equal(err, 0);
458 assert_int_equal(result, 1);
461 assert_int_equal(result, 0);
470 assert_int_equal(err, 0);
474 assert_int_equal(result, 0);
485 assert_int_equal(err, 0);
489 assert_int_equal(result, 0);
492 assert_int_equal(result, 1);
495 assert_int_equal(result, SIGTERM);
498 assert_ptr_equal(subproc, NULL);
Ambiorix slot API header file.
Ambiorix sub-proccess API header file.
Ambiorix Linux Signal Handling.
int amxp_signal_read(void)
Reads from the amxp signal file descriptor.
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.
amxp_subproc_t * amxp_subproc_find(const int pid)
Retrieve a amxp_subproc_t for a child process using it's process identifier.
int amxp_subproc_open_fd(amxp_subproc_t *subproc, int requested)
Opens standard file descriptor to the child process.
bool amxp_subproc_is_running(const amxp_subproc_t *const subproc)
Checks if the child process is running.
int amxp_subproc_new(amxp_subproc_t **subproc)
Constructor function, creates a new child process data structure.
int amxp_subproc_get_exitstatus(amxp_subproc_t *subproc)
Gets the exit code of the child process.
int amxp_subproc_start(amxp_subproc_t *const subproc, char *cmd,...)
Start a child process.
int amxp_subproc_kill(const amxp_subproc_t *const subproc, const int sig)
Sends a Linux signal to the child process.
int amxp_subproc_ifexited(amxp_subproc_t *subproc)
Checks if the child process terminated normally.
int amxp_subproc_start_wait(amxp_subproc_t *subproc, int timeout_msec, char *cmd,...)
Starts a child process and waits until it exits.
int amxp_subproc_wait(amxp_subproc_t *subproc, int timeout_msec)
Waits until the child process has stopped.
int amxp_subproc_vstart(amxp_subproc_t *const subproc, char **argv)
Start a child process.
int amxp_subproc_vstart_wait(amxp_subproc_t *subproc, int timeout_msec, char **cmd)
Starts a child process and waits until it exits.
int amxp_subproc_astart(amxp_subproc_t *const subproc, amxc_array_t *cmd)
Start a child process.
int amxp_subproc_ifsignaled(amxp_subproc_t *subproc)
Checks if the child process was stopped because of an uncaught Linux signal.
amxp_signal_mngr_t * amxp_subproc_get_sigmngr(const amxp_subproc_t *const subproc)
Get the Signal managers of the child process.
int amxp_subproc_get_termsig(amxp_subproc_t *subproc)
Gets the Linux signal id that caused the child process to stop.
int amxp_subproc_delete(amxp_subproc_t **subproc)
Destructor function, deletes a child process data structure.
pid_t amxp_subproc_get_pid(const amxp_subproc_t *const subproc)
Get the PID of a child process.
int amxp_syssig_read(void)
Reads from the file descriptor.
Child process information structure.
void test_subproc_vstart_read_stdout(UNUSED void **state)
void test_subproc_astart(UNUSED void **state)
void test_subproc_start_crashing_app(UNUSED void **state)
static void slot_test_subproc_stop(UNUSED const char *const sig_name, UNUSED const amxc_var_t *const data, UNUSED void *const priv)
void test_subproc_helper_functions(UNUSED void **state)
void test_subproc_new_delete(UNUSED void **state)
static bool subproc_is_running
void test_subproc_wait(UNUSED void **state)
void test_subproc_start_read_stdout(UNUSED void **state)
void test_subproc_vstart(UNUSED void **state)
void test_subproc_kill(UNUSED void **state)
void test_subproc_open_fd(UNUSED void **state)
static void handle_events(void)