All of lore.kernel.org
 help / color / mirror / Atom feed
From: zhanglianjie <zhanglianjie@uniontech.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 3/5] syscalls/clone05: Convert to new API
Date: Thu, 14 Oct 2021 09:25:31 +0800	[thread overview]
Message-ID: <20211014012533.18205-3-zhanglianjie@uniontech.com> (raw)
In-Reply-To: <20211014012533.18205-1-zhanglianjie@uniontech.com>

Signed-off-by: zhanglianjie <zhanglianjie@uniontech.com>

diff --git a/testcases/kernel/syscalls/clone/clone05.c b/testcases/kernel/syscalls/clone/clone05.c
index 494b772dd..69816ece6 100644
--- a/testcases/kernel/syscalls/clone/clone05.c
+++ b/testcases/kernel/syscalls/clone/clone05.c
@@ -1,103 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
  * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com>
  * Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
- *
- * 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.
- *
  */

-/*
+/*\
+ * [Description]
  * Call clone() with CLONE_VFORK flag set. verify that
  * execution of parent is suspended until child finishes
  */

 #define _GNU_SOURCE

-#include <errno.h>
+#include <stdlib.h>
 #include <sched.h>
-#include <sys/wait.h>
-#include "test.h"
+#include "tst_test.h"
 #include "clone_platform.h"

-char *TCID = "clone05";
-int TST_TOTAL = 1;
-
-static void setup(void);
-static void cleanup(void);
-static int child_fn(void *);
+static volatile int child_exited;
+static void *child_stack;

-static int child_exited = 0;
-
-int main(int ac, char **av)
+static int child_fn(void *unused LTP_ATTRIBUTE_UNUSED)
 {
+	int i;

-	int lc, status;
-	void *child_stack;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	child_stack = malloc(CHILD_STACK_SIZE);
-	if (child_stack == NULL)
-		tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, child_fn, NULL,
-		               CHILD_STACK_SIZE, child_stack));
-
-		if ((TEST_RETURN != -1) && (child_exited))
-			tst_resm(TPASS, "Test Passed");
-		else
-			tst_resm(TFAIL, "Test Failed");
-
-		if ((wait(&status)) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "wait failed, status: %d", status);
-
-		child_exited = 0;
+	for (i = 0; i < 100; i++) {
+		sched_yield();
+		usleep(1000);
 	}

-	free(child_stack);
-
-	cleanup();
-	tst_exit();
+	child_exited = 1;
+	_exit(0);
 }

-static void setup(void)
+static void verify_clone(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	child_exited = 0;
+
+	TST_EXP_PID_SILENT(ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, child_fn, NULL,
+					CHILD_STACK_SIZE, child_stack), "clone with vfork");

-	TEST_PAUSE;
-}
+	if (!TST_PASS)
+		return;

-static void cleanup(void)
-{
+	TST_EXP_VAL(child_exited, 1);
 }

-static int child_fn(void *unused __attribute__((unused)))
-{
-	int i;
-
-	/* give the kernel scheduler chance to run the parent */
-	for (i = 0; i < 100; i++) {
-		sched_yield();
-		usleep(1000);
-	}
-
-	child_exited = 1;
-	_exit(1);
-}
+static struct tst_test test = {
+	.test_all = verify_clone,
+	.bufs = (struct tst_buffers []) {
+		{&child_stack, .size = CHILD_STACK_SIZE},
+		{},
+	},
+};
--
2.20.1




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2021-10-14  1:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-14  1:25 [LTP] [PATCH v4 1/5] syscalls/clone02: Convert to new API zhanglianjie
2021-10-14  1:25 ` [LTP] [PATCH v4 2/5] syscalls/clone03: " zhanglianjie
2021-10-27 12:32   ` Cyril Hrubis
2021-10-14  1:25 ` zhanglianjie [this message]
2021-10-27 12:52   ` [LTP] [PATCH v4 3/5] syscalls/clone05: " Cyril Hrubis
2021-10-14  1:25 ` [LTP] [PATCH v4 4/5] syscalls/clone06: " zhanglianjie
2021-10-27 13:26   ` Cyril Hrubis
2021-10-14  1:25 ` [LTP] [PATCH v4 5/5] syscalls/clone07: " zhanglianjie
2021-10-27 13:40   ` Cyril Hrubis
2021-10-15  9:57 ` [LTP] [PATCH v4 1/5] syscalls/clone02: " Petr Vorel
2021-10-16 13:07   ` zhanglianjie
2021-10-27 12:00 ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211014012533.18205-3-zhanglianjie@uniontech.com \
    --to=zhanglianjie@uniontech.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.