Changeset 134ac5d in mainline for uspace/lib/pcut/src/os/unix.c


Ignore:
Timestamp:
2014-06-06T07:54:24Z (10 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8db09e4
Parents:
eeb23f2d
Message:

Update PCUT to newest version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/pcut/src/os/unix.c

    reeb23f2d r134ac5d  
    3232 */
    3333
     34/** We need _POSX_SOURCE because of kill(). */
     35#define _POSIX_SOURCE
    3436#include <stdlib.h>
    3537#include <unistd.h>
    3638#include <sys/types.h>
     39#include <signal.h>
    3740#include <errno.h>
    3841#include <assert.h>
     
    5154static char extra_output_buffer[OUTPUT_BUFFER_SIZE];
    5255
    53 /** Prepare for a new test. */
     56/** Prepare for a new test.
     57 *
     58 * @param test Test that is about to be run.
     59 */
    5460static void before_test_start(pcut_item_t *test) {
    5561        pcut_report_test_start(test);
     
    5763        memset(error_message_buffer, 0, OUTPUT_BUFFER_SIZE);
    5864        memset(extra_output_buffer, 0, OUTPUT_BUFFER_SIZE);
     65}
     66
     67/** PID of the forked process running the actual test. */
     68static pid_t child_pid;
     69
     70/** Signal handler that kills the child.
     71 *
     72 * @param sig Signal number.
     73 */
     74static void kill_child_on_alarm(int sig) {
     75        PCUT_UNUSED(sig);
     76        kill(child_pid, SIGKILL);
    5977}
    6078
     
    124142
    125143        int link_stdout[2], link_stderr[2];
    126         pid_t pid;
    127144
    128145        int rc = pipe(link_stdout);
     
    141158        }
    142159
    143         pid = fork();
    144         if (pid == (pid_t)-1) {
     160        child_pid = fork();
     161        if (child_pid == (pid_t)-1) {
    145162                snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
    146163                        "fork() failed: %s.", strerror(rc));
     
    149166        }
    150167
    151         if (pid == 0) {
     168        if (child_pid == 0) {
    152169                /* We are the child. */
    153170                dup2(link_stdout[1], STDOUT_FILENO);
     
    164181        close(link_stderr[1]);
    165182
     183        signal(SIGALRM, kill_child_on_alarm);
     184        alarm(pcut_get_test_timeout(test));
     185
    166186        size_t stderr_size = read_all(link_stderr[0], extra_output_buffer, OUTPUT_BUFFER_SIZE - 1);
    167187        read_all(link_stdout[0], extra_output_buffer, OUTPUT_BUFFER_SIZE - 1 - stderr_size);
     
    169189        int status;
    170190        wait(&status);
     191        alarm(0);
    171192
    172193        rc = convert_wait_status_to_outcome(status);
Note: See TracChangeset for help on using the changeset viewer.