diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-06-02 11:57:42 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-06-02 11:57:42 +0300 |
commit | 685600d72b0c300f94c0c69dc0a16c4ebb230a21 (patch) | |
tree | 3a3ea6f43a8cdc543118e2cf81d29628dc82f61f /tests/to.c | |
parent | cc298a11a131b162f291d6ee27ba1d7598a1b6c4 (diff) | |
download | pies-685600d72b0c300f94c0c69dc0a16c4ebb230a21.tar.gz pies-685600d72b0c300f94c0c69dc0a16c4ebb230a21.tar.bz2 |
Rewrite the testsuite
The aim is to run pies in foreground if possible. Limit execution time
using external wrapper.
* src/pies.c: (_cb_redir): Consistently return 1 on errors.
* tests/aux/sleepexit: New file.
* tests/aux/startcheck: New file.
* tests/aux/touchfile: Change arguments.
* tests/aux/respawn: Rewrite.
* tests/lines.c: New noinst program.
* tests/to.c: New noinst program.
* tests/.gitignore: Add new programs.
* tests/Makefile.am: Update.
* tests/env.at: Use to to avoid hanging forever.
Add missing popdef.
* tests/redirect.at: Use echo as component program.
* tests/respawn.at: Run pies in foreground. Use to to limit execution
time.
* tests/shell.at: Likewise.
* tests/shutdown.at: Likewise.
* tests/startup.at: Likewise.
* tests/ret-exec.at: Use sleepexit as component program.
* tests/ret-notify.at: Likewise.
Diffstat (limited to 'tests/to.c')
-rw-r--r-- | tests/to.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/to.c b/tests/to.c new file mode 100644 index 0000000..6511a54 --- /dev/null +++ b/tests/to.c @@ -0,0 +1,74 @@ +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/wait.h> + +int +main (int argc, char **argv) +{ + char *progname = argv[0]; + unsigned long n; + char *p; + pid_t pid, ret; + int status; + + if (argc < 3) + { + fprintf (stderr, "usage: %s TIMEOUT COMMAND ...\n", progname); + exit (1); + } + errno = 0; + n = strtoul (argv[1], &p, 10); + if (errno || *p || n == 0) + { + fprintf (stderr, "%s: %s is not a valid timeout\n", progname, argv[1]); + exit (1); + } + + argc -= 2; + argv += 2; + + pid = fork (); + if (pid == -1) + { + perror ("fork"); + exit (127); + } + + if (pid == 0) + { + execvp (argv[0], argv); + perror (argv[0]); + exit (127); + } + + alarm (n); + ret = wait (&status); + alarm (0); + + if (ret != pid) + { + perror ("wait"); + exit (127); + } + + if (WIFEXITED (status)) + return WEXITSTATUS (status); + + if (WIFSIGNALED (status)) + fprintf (stderr, "%s: %s terminated on signal %d\n", progname, argv[0], + WTERMSIG (status)); + else if (WIFSTOPPED (status)) + fprintf (stderr, "%s: %s stopped\n", progname, argv[0]); + else + fprintf (stderr, "%s: %s exited with unrecognized status %d\n", + progname, argv[0], status); + return 127; +} + + + + + |