From patchwork Mon Jul 23 08:51:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 947648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41YvqD5jjjz9s3N for ; Mon, 23 Jul 2018 18:31:49 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 6FB683E6FFC for ; Mon, 23 Jul 2018 10:31:46 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) by picard.linux.it (Postfix) with ESMTP id CE4C93E6004 for ; Mon, 23 Jul 2018 10:31:44 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id 700A11A000B0 for ; Mon, 23 Jul 2018 10:31:42 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="42541068" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Jul 2018 16:31:33 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 0DBC34B66A0A for ; Mon, 23 Jul 2018 16:31:34 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.156) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.399.0; Mon, 23 Jul 2018 16:31:32 +0800 From: Xiao Yang To: Date: Mon, 23 Jul 2018 16:51:47 +0800 Message-ID: <1532335907-9273-1-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.156] X-yoursite-MailScanner-ID: 0DBC34B66A0A.A977D X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=none autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH] syscalls/prctl03.c: New test for prctl() with PR_{SET, GET}_CHILD_SUBREAPER X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Test PR_SET_CHILD_SUBREAPER and PR_GET_CHILD_SUBREAPER flags of prctl(2). Signed-off-by: Xiao Yang --- runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 1 + testcases/kernel/syscalls/prctl/.gitignore | 1 + testcases/kernel/syscalls/prctl/prctl03.c | 101 +++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 testcases/kernel/syscalls/prctl/prctl03.c diff --git a/runtest/ltplite b/runtest/ltplite index 5a7819c..0840564 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -574,6 +574,7 @@ poll01 poll01 prctl01 prctl01 prctl02 prctl02 +prctl03 prctl03 pread01 pread01 pread02 pread02 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 3121cd9..fea4ccb 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -483,6 +483,7 @@ poll01 poll01 prctl01 prctl01 prctl02 prctl02 +prctl03 prctl03 pread01 pread01 pread02 pread02 diff --git a/runtest/syscalls b/runtest/syscalls index dc72484..420ff45 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -808,6 +808,7 @@ ppoll01 ppoll01 prctl01 prctl01 prctl02 prctl02 +prctl03 prctl03 pread01 pread01 pread01_64 pread01_64 diff --git a/testcases/kernel/syscalls/prctl/.gitignore b/testcases/kernel/syscalls/prctl/.gitignore index 6af5df6..2f46a9a 100644 --- a/testcases/kernel/syscalls/prctl/.gitignore +++ b/testcases/kernel/syscalls/prctl/.gitignore @@ -1,2 +1,3 @@ /prctl01 /prctl02 +/prctl03 diff --git a/testcases/kernel/syscalls/prctl/prctl03.c b/testcases/kernel/syscalls/prctl/prctl03.c new file mode 100644 index 0000000..28145d5 --- /dev/null +++ b/testcases/kernel/syscalls/prctl/prctl03.c @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. + * Author: Xiao Yang + * + * Test PR_SET_CHILD_SUBREAPER and PR_GET_CHILD_SUBREAPER of prctl(2). + * 1) If PR_SET_CHILD_SUBREAPER marks a process as a child subreaper, it + * fulfills the role of init(1) for its descendant processes. The + * subreaper process can receive a SIGCHLD signal and wait(2) on its + * descendant orphan process to discover corresponding termination status. + * 2) The setting of PR_SET_CHILD_SUBREAPER is not inherited by children + * created by fork(2). + * 3) PR_GET_CHILD_SUBREAPER can get the setting of PR_SET_CHILD_SUBREAPER. + * + * These flags was added by kenrel commit ebec18a6d3aa: + * "prctl: add PR_{SET,GET}_CHILD_SUBREAPER to allow simple process supervision" + */ + +#include +#include +#include +#include +#include + +#include "tst_test.h" + +#ifndef PR_SET_CHILD_SUBREAPER +# define PR_SET_CHILD_SUBREAPER 36 +# define PR_GET_CHILD_SUBREAPER 37 +#endif + +static void check_get_subreaper(int exp_val) +{ + int get_val; + + TEST(prctl(PR_GET_CHILD_SUBREAPER, &get_val)); + if (TEST_RETURN == -1) { + tst_res(TFAIL | TTERRNO, "prctl(PR_GET_CHILD_SUBREAPER) failed"); + return; + } + + if (get_val == exp_val) { + tst_res(TPASS, "prctl(PR_GET_CHILD_SUBREAPER) got expected %d", + get_val); + } else { + tst_res(TFAIL, "prctl(PR_GET_CHILD_SUBREAPER) got %d, expected %d", + get_val, exp_val); + } +} + +static void verify_prctl(void) +{ + int status, ret; + pid_t pid; + + TEST(prctl(PR_SET_CHILD_SUBREAPER, 1)); + if (TEST_RETURN == -1) { + if (TEST_ERRNO == EINVAL) { + tst_res(TCONF, + "prctl() doesn't support PR_SET_CHILD_SUBREAPER"); + } else { + tst_res(TFAIL | TTERRNO, + "prctl(PR_SET_CHILD_SUBREAPER) failed"); + } + return; + } + + tst_res(TPASS, "prctl(PR_SET_CHILD_SUBREAPER) succeeded"); + + pid = SAFE_FORK(); + if (!pid) { + pid_t cpid; + + cpid = SAFE_FORK(); + if (!cpid) { + TST_CHECKPOINT_WAIT(0); + exit(0); + } + + check_get_subreaper(0); + exit(1); + } + + SAFE_WAITPID(pid, NULL, 0); + TST_CHECKPOINT_WAKE(0); + ret = wait(&status); + if (ret > 0 && !WEXITSTATUS(status)) { + tst_res(TPASS, "wait() got orphan process, pid %d status %d", + ret, status); + } else { + tst_res(TFAIL | TERRNO, "wait() failed to get orphan process"); + } + + check_get_subreaper(1); +} + +static struct tst_test test = { + .forks_child = 1, + .needs_checkpoints = 1, + .test_all = verify_prctl, +};