From 1a920d9c26bc2794a22604e94a988f27f8b556f8 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Mon, 24 Apr 2017 15:48:01 -0300 Subject: posix: Adapt tst-spawn{2,3} to use libsupport. Checked on x86_64-linux-gnu. * posix/tst-spawn2.c (do_test): Use libsupport. * posix/tst-spawn3.c (do_test): Likewise. --- posix/tst-spawn2.c | 26 +++++++++------- posix/tst-spawn3.c | 88 ++++++++++++++++-------------------------------------- 2 files changed, 41 insertions(+), 73 deletions(-) (limited to 'posix') diff --git a/posix/tst-spawn2.c b/posix/tst-spawn2.c index 73a37b6c01..3a2e0415f7 100644 --- a/posix/tst-spawn2.c +++ b/posix/tst-spawn2.c @@ -23,11 +23,12 @@ #include #include #include - #include +#include + int -posix_spawn_test (void) +do_test (void) { /* Check if posix_spawn correctly returns an error and an invalid pid by trying to spawn an invalid binary. */ @@ -38,35 +39,40 @@ posix_spawn_test (void) int ret = posix_spawn (&pid, program, 0, 0, args, environ); if (ret != ENOENT) - error (EXIT_FAILURE, errno, "posix_spawn"); + { + errno = ret; + FAIL_EXIT1 ("posix_spawn: %m"); + } /* POSIX states the value returned on pid variable in case of an error is not specified. GLIBC will update the value iff the child execution is successful. */ if (pid != -1) - error (EXIT_FAILURE, errno, "posix_spawn returned pid != -1"); + FAIL_EXIT1 ("posix_spawn returned pid != -1 (%i)", (int) pid); /* Check if no child is actually created. */ ret = waitpid (-1, NULL, 0); if (ret != -1 || errno != ECHILD) - error (EXIT_FAILURE, errno, "waitpid"); + FAIL_EXIT1 ("waitpid: %m)"); /* Same as before, but with posix_spawnp. */ char *args2[] = { (char*) program, 0 }; ret = posix_spawnp (&pid, args2[0], 0, 0, args2, environ); if (ret != ENOENT) - error (EXIT_FAILURE, errno, "posix_spawnp"); + { + errno = ret; + FAIL_EXIT1 ("posix_spawnp: %m"); + } if (pid != -1) - error (EXIT_FAILURE, errno, "posix_spawnp returned pid != -1"); + FAIL_EXIT1 ("posix_spawnp returned pid != -1 (%i)", (int) pid); ret = waitpid (-1, NULL, 0); if (ret != -1 || errno != ECHILD) - error (EXIT_FAILURE, errno, "waitpid"); + FAIL_EXIT1 ("waitpid: %m)"); return 0; } -#define TEST_FUNCTION posix_spawn_test () -#include "../test-skeleton.c" +#include diff --git a/posix/tst-spawn3.c b/posix/tst-spawn3.c index 8577b03d01..28a487293f 100644 --- a/posix/tst-spawn3.c +++ b/posix/tst-spawn3.c @@ -25,10 +25,11 @@ #include #include #include +#include +#include -static int do_test (void); -#define TEST_FUNCTION do_test () -#include +#include +#include static int do_test (void) @@ -47,25 +48,20 @@ do_test (void) struct rlimit rl; int max_fd = 24; + int ret; /* Set maximum number of file descriptor to a low value to avoid open too many files in environments where RLIMIT_NOFILE is large and to limit the array size to track the opened file descriptors. */ if (getrlimit (RLIMIT_NOFILE, &rl) == -1) - { - printf ("error: getrlimit RLIMIT_NOFILE failed"); - exit (EXIT_FAILURE); - } + FAIL_EXIT1 ("getrlimit (RLIMIT_NOFILE): %m"); max_fd = (rl.rlim_cur < max_fd ? rl.rlim_cur : max_fd); rl.rlim_cur = max_fd; if (setrlimit (RLIMIT_NOFILE, &rl) == 1) - { - printf ("error: setrlimit RLIMIT_NOFILE to %u failed", max_fd); - exit (EXIT_FAILURE); - } + FAIL_EXIT1 ("setrlimit (RLIMIT_NOFILE): %m"); /* Exhauste the file descriptor limit with temporary files. */ int files[max_fd]; @@ -76,11 +72,7 @@ do_test (void) if (fd == -1) { if (errno != EMFILE) - { - printf ("error: create_temp_file returned -1 with " - "errno != EMFILE\n"); - exit (EXIT_FAILURE); - } + FAIL_EXIT1 ("create_temp_file: %m"); break; } files[nfiles++] = fd; @@ -88,25 +80,16 @@ do_test (void) posix_spawn_file_actions_t a; if (posix_spawn_file_actions_init (&a) != 0) - { - puts ("error: spawn_file_actions_init failed"); - exit (EXIT_FAILURE); - } + FAIL_EXIT1 ("posix_spawn_file_actions_init"); /* Executes a /bin/sh echo $$ 2>&1 > /tmp/tst-spawn3.pid . */ const char pidfile[] = "/tmp/tst-spawn3.pid"; if (posix_spawn_file_actions_addopen (&a, STDOUT_FILENO, pidfile, O_WRONLY | O_CREAT | O_TRUNC, 0644) != 0) - { - puts ("error: spawn_file_actions_addopen failed"); - exit (EXIT_FAILURE); - } + FAIL_EXIT1 ("posix_spawn_file_actions_addopen"); if (posix_spawn_file_actions_adddup2 (&a, STDOUT_FILENO, STDERR_FILENO) != 0) - { - puts ("error: spawn_file_actions_addclose"); - exit (EXIT_FAILURE); - } + FAIL_EXIT1 ("posix_spawn_file_actions_adddup2"); /* Since execve (called by posix_spawn) might require to open files to actually execute the shell script, setup to close the temporary file @@ -114,54 +97,40 @@ do_test (void) for (int i=0; i -- cgit 1.4.1