From patchwork Fri Jun 2 09:55:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1789550 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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 ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QXdhS5ZFkz20Q4 for ; Fri, 2 Jun 2023 19:57:12 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 23A1F3CCE48 for ; Fri, 2 Jun 2023 11:57:10 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id DC4123CCDD8 for ; Fri, 2 Jun 2023 11:57:07 +0200 (CEST) Received: from esa1.hc1455-7.c3s2.iphmx.com (esa1.hc1455-7.c3s2.iphmx.com [207.54.90.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 8FCE11400457 for ; Fri, 2 Jun 2023 11:57:06 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6600,9927,10728"; a="119122301" X-IronPort-AV: E=Sophos;i="6.00,212,1681138800"; d="scan'208";a="119122301" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa1.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 18:57:04 +0900 Received: from yto-m2.gw.nic.fujitsu.com (yto-nat-yto-m2.gw.nic.fujitsu.com [192.168.83.65]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 55F70C68E4 for ; Fri, 2 Jun 2023 18:57:02 +0900 (JST) Received: from aks-ab1.gw.nic.fujitsu.com (aks-ab1.gw.nic.fujitsu.com [192.51.207.11]) by yto-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id 8C5E0D5EA3 for ; Fri, 2 Jun 2023 18:57:01 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.215.131]) by aks-ab1.gw.nic.fujitsu.com (Postfix) with ESMTP id A7F8E2FC69FB; Fri, 2 Jun 2023 18:57:00 +0900 (JST) From: Yang Xu To: ltp@lists.linux.it Date: Fri, 2 Jun 2023 17:55:55 +0800 Message-Id: <1685699755-4766-1-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1408-9.0.0.1002-27666.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1408-9.0.1002-27666.006 X-TMASE-Result: 10--2.123800-10.000000 X-TMASE-MatchedRID: 24Sf70/zn6qhhjsqgSuNbxF4zyLyne+AVBDQSDMig9HEosIs7IJbkIh+ mL+ciFCpbnRB47KLJ1QzLmfGY6iDkX5uUfhNvnKzOWUWxTQJdI8UZYubbUj2DLt4BAaULwAVJf5 otvavOZf9vT5evMX4tM0lquesZhhHpljg/F9ExYTFVAV8vDjN/6n/3nyhTdZwZYqF36J/b8ZjaQ GYA98fM/sRZb2bIX9Ww06evX0vRhJVnAszo0EfNLrbxxduc6FPv1wCVBblimutuWYz9oVoL2tgc kGXH2knxdZk3h//tzkDfZ2MQc5Ymnzh4vqEo4GEngIgpj8eDcByZ8zcONpAscRB0bsfrpPIcSqb xBgG0w7vCc/rjI9C+jGrCVPFEdZvTyNC1c6am3IFdR/vblG5BTW7lwZjG9qX7T34oPpSbabv9mw 2z9YBSrXIF+5Zx9tOoJSTU+6ceilB73EZz7XBCOp1XUG/h2MOieWdV7FfKATLbAp0fm+COw== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Virus-Scanned: clamav-milter 1.0.1 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH] syscalls/fork03: Convert into 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: Yang Xu Reviewed-by: Petr Vorel --- testcases/kernel/syscalls/fork/fork03.c | 146 +++++++----------------- 1 file changed, 44 insertions(+), 102 deletions(-) diff --git a/testcases/kernel/syscalls/fork/fork03.c b/testcases/kernel/syscalls/fork/fork03.c index 25b36c897..072f12797 100644 --- a/testcases/kernel/syscalls/fork/fork03.c +++ b/testcases/kernel/syscalls/fork/fork03.c @@ -1,119 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* + * Copyright (c) International Business Machines Corp., 2001 * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * AUTHOR + *      07/2001 Ported by Wayne Boyer */ -/* - * NAME - * fork03.c - * - * DESCRIPTION - * Check that child can use a large text space and do a large - * number of operations. - * - * ALGORITHM - * Fork one process, check for pid == 0 in child. - * Check for pid > 0 in parent after wait. - * - * USAGE - * fork03 +/*\ + *[Description] * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None + * Check that child process can use a large text space and do a large number + * of operations. In this situation, Check for pid == 0 in child and check + * for pid > 0 in parent after wait. */ #include +#include #include -#include -#include "test.h" - -char *TCID = "fork03"; -int TST_TOTAL = 1; - -static void setup(void); -static void cleanup(void); +#include +#include "tst_test.h" -int main(int ac, char **av) +static void verify_fork(void) { float fl1, fl2; - int i; - int pid1, pid2, status; - - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - pid1 = fork(); - if (pid1 == -1) - tst_brkm(TBROK, cleanup, "fork() failed"); - - if (pid1 == 0) { - /* child uses some cpu cycles */ - for (i = 1; i < 32767; i++) { - fl1 = 0.000001; - fl1 = fl2 = 0.000001; - fl1 = fl1 * 10.0; - fl2 = fl1 / 1.232323; - fl1 = fl2 - fl2; - fl1 = fl2; - } - - /* Pid must always be zero in child */ - if (pid1 != 0) - exit(1); - else - exit(0); - } else { - tst_resm(TINFO, "process id in parent of child from " - "fork : %d", pid1); - pid2 = wait(&status); /* wait for child */ - - if (pid1 != pid2) { - tst_resm(TFAIL, "pids don't match : %d vs %d", - pid1, pid2); - continue; - } - - if ((status >> 8) != 0) { - tst_resm(TFAIL, "child exited with failure"); - continue; - } - - tst_resm(TPASS, "test 1 PASSED"); + int pid1, pid2, status, i; + + pid1 = SAFE_FORK(); + if (!pid1) { + /* child uses some cpu time slices */ + for (i = 1; i < 32767; i++) { + fl1 = 0.000001; + fl1 = fl2 = 0.000001; + fl1 = fl1 * 10.0; + fl2 = fl1 / 1.232323; + fl1 = fl2 - fl2; + fl1 = fl2; } + if (!pid1) + exit(0); + else + exit(1); } - cleanup(); - tst_exit(); -} - -static void setup(void) -{ - tst_sig(FORK, DEF_HANDLER, cleanup); - TEST_PAUSE; + tst_res(TINFO, "process id in parent of child from fork : %d", pid1); + pid2 = SAFE_WAIT(&status); + if (pid1 != pid2) { + tst_res(TFAIL, "pids don't match : %d vs %d", pid1, pid2); + return; + } + if ((status >> 8) != 0) { + tst_res(TFAIL, "child exited with failure"); + return; + } + tst_res(TPASS, "test PASSED"); } -static void cleanup(void) -{ -} +static struct tst_test test = { + .test_all = verify_fork, + .forks_child = 1, +};