From patchwork Mon May 15 19:36:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 20448 Received: (qmail 60974 invoked by alias); 15 May 2017 19:36:34 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 60916 invoked by uid 89); 15 May 2017 19:36:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=4725, environ, states X-HELO: mail-qk0-f182.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=7+dZvQgaE4i2oBiNT/ppv8foYLk//AkkE4Y+xEUlxko=; b=MFLeZwvXziD3rboe/7JCMS0E/vRLarIlYoNv7ivn+iB9vvfaVzOoE1idesZZD35o1p QIP/HoYEbtWy3g+fhQPFzdNDK9LgxzvTiK56NZdGtf46CIgMuYB5RPIsFTJdU1Xp/1a5 tQqQHyw/vy/Yu7UYiMiJOtY+/39foT7a81FZFUlITME9U2fXY8pnyqfPCg5c2c/im3w0 +vd/QZ8ivcxyyBChfuapIsUDEexS3d/HhTj7uv7TYgXekApfe41Taozzor5K+bxaBj+Q KrXE45WDcpygjuK0kermn9n0AJf91fCQ6DxA1ug1VPMZKYiUlZL3ARqVaQWRWjxyc0Pv SeTg== X-Gm-Message-State: AODbwcAjLopbGRuj2ycMG/VGm8zgvfj/XOQFbATi2+X3uMQpqiEMPprm TJqmPvKVH8ASYqqkenm8WQ== X-Received: by 10.55.212.211 with SMTP id s80mr7333794qks.6.1494876992377; Mon, 15 May 2017 12:36:32 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 1/3] posix: Adapt tst-spawn{2,3} to use libsupport. Date: Mon, 15 May 2017 16:36:23 -0300 Message-Id: <1494876985-21990-1-git-send-email-adhemerval.zanella@linaro.org> Checked on x86_64-linux-gnu. * posix/tst-spawn2.c (do_test): Use libsupport. * posix/tst-spawn3.c (do_test): Likewise. --- ChangeLog | 5 ++++ posix/tst-spawn2.c | 26 +++++++++------- posix/tst-spawn3.c | 88 ++++++++++++++++-------------------------------------- 3 files changed, 46 insertions(+), 73 deletions(-) diff --git a/posix/tst-spawn2.c b/posix/tst-spawn2.c index 73a37b6..3a2e041 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 8577b03..28a4872 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