From patchwork Thu Sep 23 08:52:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanglianjie X-Patchwork-Id: 1531626 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HFTTz0X81z9sxS for ; Thu, 23 Sep 2021 18:53:43 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4EC2B3C8F6A for ; Thu, 23 Sep 2021 10:53:40 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 4D84D3C8F64 for ; Thu, 23 Sep 2021 10:53:18 +0200 (CEST) Received: from smtpbg516.qq.com (smtpbg516.qq.com [203.205.250.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 51F051001295 for ; Thu, 23 Sep 2021 10:53:15 +0200 (CEST) X-QQ-mid: bizesmtp51t1632387191t8h0mgb3 Received: from localhost.localdomain (unknown [58.240.82.166]) by esmtp6.qq.com (ESMTP) with id ; Thu, 23 Sep 2021 16:53:07 +0800 (CST) X-QQ-SSF: 0140000000000040C000B00B0000000 X-QQ-FEAT: SCIwIIlHPKlIoWDZuATvthFXW/WQRh5j0d8lG9WG3FEmtjfNA1tsbivs5XflI IdwEQAIvpUdzGknLUT5wF+iw0e2/13b6BzxQaG74EVna/AN9HjzL3m51M8bwt12RyW0cMK9 Bz0ynvXp6K7dSdf0uKdeuUsczwvFHowsGU22uzC6vyERxsekvB5LDLYqdg8BhF9sJ+rvk11 rzhXfjRe+7xHVnQRn6MjQYdKb13sHi7kno3nZraeIi2hkQjLINYidTHMrA1zoYabG9uFE0B LOyiDLUs0yspDQGymOiuJMDI0KU4DBUPHuAQeMQal6YXRBBis3raxNKn8zLvvtPvGDtid8i aSb4Nm1Qe+pMPS4frgUTCl9Llqdng== X-QQ-GoodBg: 2 From: zhanglianjie To: ltp@lists.linux.it Date: Thu, 23 Sep 2021 16:52:24 +0800 Message-Id: <20210923085224.868-5-zhanglianjie@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210923085224.868-1-zhanglianjie@uniontech.com> References: <20210923085224.868-1-zhanglianjie@uniontech.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign5 X-QQ-Bgrelay: 1 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v3 5/5] syscalls/clone07: Convert to new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 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" Signed-off-by: zhanglianjie --- 2.20.1 diff --git a/testcases/kernel/syscalls/clone/clone07.c b/testcases/kernel/syscalls/clone/clone07.c index 4b2e04ee7..304810c40 100644 --- a/testcases/kernel/syscalls/clone/clone07.c +++ b/testcases/kernel/syscalls/clone/clone07.c @@ -1,86 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) International Business Machines Corp., 2003. * Copyright (c) 2012 Wanlong Gao - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ -/* - * This is a test for a glibc bug for the clone(2) system call. */ -#if defined UCLINUX && !__THROW -/* workaround for libc bug */ -#define __THROW -#endif +/*\ + * [Description] + * This is a test for a glibc bug for the clone(2) system call. + */ -#include #include -#include -#include "test.h" +#include +#include +#include "tst_test.h" +#include "lapi/syscalls.h" #include "clone_platform.h" -#define TRUE 1 -#define FALSE 0 - -static void setup(); -static int do_child(); - -char *TCID = "clone07"; -int TST_TOTAL = 1; - -static void sigsegv_handler(int); -static void sigusr2_handler(int); static int child_pid; -static int fail = FALSE; +static int fail; +static void *child_stack; -int main(int ac, char **av) +static int do_child(void *arg LTP_ATTRIBUTE_UNUSED) { + return 0; +} - int lc, status; - void *child_stack; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); +static void sigsegv_handler(int sig LTP_ATTRIBUTE_UNUSED) +{ + if (child_pid == 0) { + kill(getppid(), SIGUSR2); + _exit(42); + } +} - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - child_stack = malloc(CHILD_STACK_SIZE); - if (child_stack == NULL) - tst_brkm(TBROK, NULL, - "Cannot allocate stack for child"); +static void sigusr2_handler(int sig LTP_ATTRIBUTE_UNUSED) +{ + if (child_pid != 0) + fail = 1; +} - child_pid = ltp_clone(SIGCHLD, do_child, NULL, - CHILD_STACK_SIZE, child_stack); +static void verify_clone(void) +{ + TST_EXP_PID_SILENT(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, + child_stack)); - if (child_pid < 0) - tst_brkm(TBROK | TERRNO, NULL, "clone failed"); + child_pid = TST_RET; - if ((wait(&status)) == -1) - tst_brkm(TBROK | TERRNO, NULL, - "wait failed, status: %d", status); + if (!TST_PASS) + return; - free(child_stack); - } + tst_reap_children(); - if (fail == FALSE) - tst_resm(TPASS, - "Use of return() in child did not cause SIGSEGV"); - else - tst_resm(TFAIL, "Use of return() in child caused SIGSEGV"); + TST_EXP_VAL(fail, 0, "Use of return() in child did not cause SIGSEGV"); - tst_exit(); } static void setup(void) @@ -88,41 +60,26 @@ static void setup(void) struct sigaction def_act; struct sigaction act; - TEST_PAUSE; - act.sa_handler = sigsegv_handler; act.sa_flags = SA_RESTART; - sigemptyset(&act.sa_mask); - if ((sigaction(SIGSEGV, &act, NULL)) == -1) - tst_resm(TWARN | TERRNO, - "sigaction() for SIGSEGV failed in test_setup()"); + SAFE_SIGEMPTYSET(&act.sa_mask); + SAFE_SIGACTION(SIGSEGV, &act, NULL); - /* Setup signal handler for SIGUSR2 */ def_act.sa_handler = sigusr2_handler; def_act.sa_flags = SA_RESTART | SA_RESETHAND; - sigemptyset(&def_act.sa_mask); - - if ((sigaction(SIGUSR2, &def_act, NULL)) == -1) - tst_resm(TWARN | TERRNO, - "sigaction() for SIGUSR2 failed in test_setup()"); -} + SAFE_SIGEMPTYSET(&def_act.sa_mask); + SAFE_SIGACTION(SIGUSR2, &def_act, NULL); -static int do_child(void) -{ - return 0; + child_stack = SAFE_MALLOC(CHILD_STACK_SIZE); } -static void sigsegv_handler(int sig) +static void cleanup(void) { - if (child_pid == 0) { - kill(getppid(), SIGUSR2); - _exit(42); - } + free(child_stack); } -/* sig_default_handler() - Default handler for parent */ -static void sigusr2_handler(int sig) -{ - if (child_pid != 0) - fail = TRUE; -} +static struct tst_test test = { + .setup = setup, + .test_all = verify_clone, + .cleanup = cleanup, +};