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 Netto X-Patchwork-Id: 99832 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp1697559qge; Mon, 15 May 2017 12:37:17 -0700 (PDT) X-Received: by 10.99.164.2 with SMTP id c2mr7970991pgf.73.1494877037167; Mon, 15 May 2017 12:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494877037; cv=none; d=google.com; s=arc-20160816; b=L3pAcZoVXDGjyWdLIA5UekYLZgCoPzAga9+odI4q35baFvwvPEOZm20TtX5nXiXit7 a7DdhUUWhKsIEKw8hCjp7TmV2jgUAMXYVh7PI6gexP/yaYLun+aeXTJwXOx5Rl6ycEAs z5vlchT/NHAAhi2U1/evdyX7SgkrGlxMTRekgF7J8RJC+vQfHsby+Ku6lNP0NRJw/MGU 2Vj91P1mNJCv2kAlqrL/gzZ6QeZtvukqRPAiEqjSXP2eWjfoz+4pwQjhLbNn0ArXDhPJ pVciVl5Lutnso20PpU8jHmfiWD/Imf4Ucf5LWlpS9GHlZ13lXtD5rkRH7B2HfsAErzpf eE/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:delivered-to:sender:list-help :list-post:list-archive:list-subscribe:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=7+dZvQgaE4i2oBiNT/ppv8foYLk//AkkE4Y+xEUlxko=; b=mjxE+laiYDJs+c4trFi946G734Xg9pFgPEqf+PD6RJNjkYRFKy7GUxpDIYVIIueh2R BrIx+WJUVyyUuiFWHHGJf66VmcSEO1Cx0wEBYhMEOIpjQu4EZFah9g3fDci0l3ic2NjH +DssSf8cnN1OeK66ESnxl/OyizWGFUJw0f+sZAlHHJ/l2pF6DQDl4PUDiKWuqjS6Ek7w 3lsudnm7AWCainbi89aVYAbDl0iyuxJtUX/O4kXnlZ+bd8LIrZm5l3F4CLMlEfNGApbs QpH2uyNEeoZJqMChM8zjpDVQGf1UbGQCssIHTNNZ87plTZ5MDCtL6psg29UjnSPcYtND UoNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-79427-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-79427-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id w6si11349754pfk.420.2017.05.15.12.37.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 May 2017 12:37:17 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-79427-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-79427-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-79427-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=qrg8sC6d8mXwOH6vQU3OLfMBfFf0mFswQBHUR/g1xAZ8oryTuAK8K NyVXo9EgU89fKeodWwjjkdFYvMvUZgnDnj1sUa4MuA5g88HNXGd4O9SLXC0Tc8N1 BPw3pa39+cu9jj3r/Q0AIvXoHelpdSvRa12Kvna6jwJy8l39kwhyhc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=HaPqeaMIPoqUKB03+Dq9qsclcz4=; b=FEH6KsUlAS+sA8GIJfqRcA/2NAls zKDSxYGoTN04QgbiD/nKFpubXf270xyJYlLCtesvnr3m8zpdpoRcqAOZAyilEx6D +tF42Bvspzx5tWmGpEMGk6JzBBJiY5w0n0cbSIPEALNg/SNT6mjB9UqHJFKMBR8R 9nljH2Mek1grDnw= 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(-) -- 2.7.4 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