All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 1/7] syscalls/clone01: Convert to new API
@ 2021-09-02  1:08 zhanglianjie
  2021-09-02  6:02 ` Petr Vorel
  0 siblings, 1 reply; 7+ messages in thread
From: zhanglianjie @ 2021-09-02  1:08 UTC (permalink / raw)
  To: ltp

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

diff --git a/testcases/kernel/syscalls/clone/clone01.c b/testcases/kernel/syscalls/clone/clone01.c
index e490b4e77..ed7ef60a3 100644
--- a/testcases/kernel/syscalls/clone/clone01.c
+++ b/testcases/kernel/syscalls/clone/clone01.c
@@ -1,90 +1,63 @@
+// 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>
- *
- * 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 the clone(2) system call.
- *	It is intended to provide a limited exposure of the system call.
+/*\
+ * [Description]
+ *
+ * Basic clone() test.
+ *
+ * Use clone() to create a child process, and wait for the child process to exit,
+ * verify that the child process pid is correct.
  */

-#if defined UCLINUX && !__THROW
-/* workaround for libc bug */
-#define __THROW
-#endif
-
-#include <errno.h>
-#include <sched.h>
-#include <sys/wait.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <stdlib.h>
+#include "tst_test.h"
 #include "clone_platform.h"

-static void setup(void);
-static void cleanup(void);
-static int do_child();
+static void *child_stack;

-char *TCID = "clone01";
-int TST_TOTAL = 1;
+static int do_child(void *arg LTP_ATTRIBUTE_UNUSED)
+{
+	exit(0);
+}

-int main(int ac, char **av)
+static void verify_clone(void)
 {
-	void *child_stack;
 	int status, child_pid;

-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
+	TST_EXP_POSITIVE(ltp_clone(SIGCHLD, do_child, NULL,
+		CHILD_STACK_SIZE, child_stack), "clone()");

-	child_stack = malloc(CHILD_STACK_SIZE);
-	if (child_stack == NULL)
-		tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
+	child_pid = SAFE_WAIT(&status);

-	tst_count = 0;
-
-	TEST(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, child_stack));
-	if (TEST_RETURN == -1)
-		tst_resm(TFAIL | TTERRNO, "clone failed");
-
-	child_pid = SAFE_WAIT(cleanup, &status);
-
-	if (TEST_RETURN == child_pid)
-		tst_resm(TPASS, "clone returned %ld", TEST_RETURN);
+	if (TST_RET == child_pid)
+		tst_res(TPASS, "clone returned %ld", TST_RET);
 	else
-		tst_resm(TFAIL, "clone returned %ld, wait returned %d",
-			 TEST_RETURN, child_pid);
-
-	free(child_stack);
-
-	cleanup();
+		tst_res(TFAIL, "clone returned %ld, wait returned %d",
+			 TST_RET, child_pid);

-	tst_exit();
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+		tst_res(TPASS, "Child exited with 0");
+	else
+		tst_res(TFAIL, "Child %s", tst_strstatus(status));
 }

 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
+	child_stack = SAFE_MALLOC(CHILD_STACK_SIZE);
 }

 static void cleanup(void)
 {
+	free(child_stack);
 }

-static int do_child(void)
-{
-	exit(0);
-}
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_clone,
+	.forks_child = 1,
+};
--
2.20.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 1/7] syscalls/clone01: Convert to new API
  2021-09-02  1:08 [LTP] [PATCH v2 1/7] syscalls/clone01: Convert to new API zhanglianjie
@ 2021-09-02  6:02 ` Petr Vorel
  2021-09-07 11:09     ` zhanglianjie
  2021-09-23  8:56   ` zhanglianjie
  0 siblings, 2 replies; 7+ messages in thread
From: Petr Vorel @ 2021-09-02  6:02 UTC (permalink / raw)
  To: ltp

Hi zhanglianjie,

...
> +static void verify_clone(void)
>  {
> -	void *child_stack;
>  	int status, child_pid;

> -	tst_parse_opts(ac, av, NULL, NULL);
> -
> -	setup();
> +	TST_EXP_POSITIVE(ltp_clone(SIGCHLD, do_child, NULL,
Shouldn't be TST_EXP_PID_SILENT()
Because TST_EXP_POSITIVE() prints extra TPASS which is useless:

clone01.c:31: TPASS: clone() returned 11556
clone01.c:37: TPASS: clone returned 11556
clone01.c:43: TPASS: Child exited with 0

but with TST_EXP_PID_SILENT():
clone01.c:37: TPASS: clone returned 11986
clone01.c:43: TPASS: Child exited with 0

and on deliberate error (using -1 as flag):
clone01.c:31: TFAIL: clone() failed: EINVAL (22)
clone01.c:34: TBROK: wait(0x7ffed515f3ec) failed: ECHILD (10)

> +		CHILD_STACK_SIZE, child_stack), "clone()");

> -	child_stack = malloc(CHILD_STACK_SIZE);
> -	if (child_stack == NULL)
> -		tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
> +	child_pid = SAFE_WAIT(&status);

> -	tst_count = 0;
> -
> -	TEST(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, child_stack));
> -	if (TEST_RETURN == -1)
> -		tst_resm(TFAIL | TTERRNO, "clone failed");
> -
> -	child_pid = SAFE_WAIT(cleanup, &status);
> -
> -	if (TEST_RETURN == child_pid)
> -		tst_resm(TPASS, "clone returned %ld", TEST_RETURN);
> +	if (TST_RET == child_pid)
	if (child_pid ==  TST_RET)

=> run `make check-clone01' to see this error (and run make check-* for other
tests).


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH v2 1/7] syscalls/clone01: Convert to new API
@ 2021-09-07 11:09     ` zhanglianjie
  0 siblings, 0 replies; 7+ messages in thread
From: zhanglianjie @ 2021-09-07 11:09 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi,
Thank you I will resubmit.

On 2021-09-02 14:02, Petr Vorel wrote:
> Hi zhanglianjie,
> 
> ...
>> +static void verify_clone(void)
>>   {
>> -	void *child_stack;
>>   	int status, child_pid;
> 
>> -	tst_parse_opts(ac, av, NULL, NULL);
>> -
>> -	setup();
>> +	TST_EXP_POSITIVE(ltp_clone(SIGCHLD, do_child, NULL,
> Shouldn't be TST_EXP_PID_SILENT()
> Because TST_EXP_POSITIVE() prints extra TPASS which is useless:
> 
> clone01.c:31: TPASS: clone() returned 11556
> clone01.c:37: TPASS: clone returned 11556
> clone01.c:43: TPASS: Child exited with 0
> 
> but with TST_EXP_PID_SILENT():
> clone01.c:37: TPASS: clone returned 11986
> clone01.c:43: TPASS: Child exited with 0
> 
> and on deliberate error (using -1 as flag):
> clone01.c:31: TFAIL: clone() failed: EINVAL (22)
> clone01.c:34: TBROK: wait(0x7ffed515f3ec) failed: ECHILD (10)
> 
>> +		CHILD_STACK_SIZE, child_stack), "clone()");
> 
>> -	child_stack = malloc(CHILD_STACK_SIZE);
>> -	if (child_stack == NULL)
>> -		tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
>> +	child_pid = SAFE_WAIT(&status);
> 
>> -	tst_count = 0;
>> -
>> -	TEST(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, child_stack));
>> -	if (TEST_RETURN == -1)
>> -		tst_resm(TFAIL | TTERRNO, "clone failed");
>> -
>> -	child_pid = SAFE_WAIT(cleanup, &status);
>> -
>> -	if (TEST_RETURN == child_pid)
>> -		tst_resm(TPASS, "clone returned %ld", TEST_RETURN);
>> +	if (TST_RET == child_pid)
> 	if (child_pid ==  TST_RET)
> 
> => run `make check-clone01' to see this error (and run make check-* for other
> tests).
> 
> 
> Kind regards,
> Petr
> 

-- 
Regards,
Zhang Lianjie



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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH v2 1/7] syscalls/clone01: Convert to new API
  2021-09-02  6:02 ` Petr Vorel
  2021-09-07 11:09     ` zhanglianjie
@ 2021-09-23  8:56   ` zhanglianjie
  2021-09-23  9:05     ` Petr Vorel
  1 sibling, 1 reply; 7+ messages in thread
From: zhanglianjie @ 2021-09-23  8:56 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi,
Please ignore other patches about clone testcases and just focus on 
v3.thanks.


On 2021-09-02 14:02, Petr Vorel wrote:
> Hi zhanglianjie,
> 
> ...
>> +static void verify_clone(void)
>>   {
>> -	void *child_stack;
>>   	int status, child_pid;
> 
>> -	tst_parse_opts(ac, av, NULL, NULL);
>> -
>> -	setup();
>> +	TST_EXP_POSITIVE(ltp_clone(SIGCHLD, do_child, NULL,
> Shouldn't be TST_EXP_PID_SILENT()
> Because TST_EXP_POSITIVE() prints extra TPASS which is useless:
> 
> clone01.c:31: TPASS: clone() returned 11556
> clone01.c:37: TPASS: clone returned 11556
> clone01.c:43: TPASS: Child exited with 0
> 
> but with TST_EXP_PID_SILENT():
> clone01.c:37: TPASS: clone returned 11986
> clone01.c:43: TPASS: Child exited with 0
> 
> and on deliberate error (using -1 as flag):
> clone01.c:31: TFAIL: clone() failed: EINVAL (22)
> clone01.c:34: TBROK: wait(0x7ffed515f3ec) failed: ECHILD (10)
> 
>> +		CHILD_STACK_SIZE, child_stack), "clone()");
> 
>> -	child_stack = malloc(CHILD_STACK_SIZE);
>> -	if (child_stack == NULL)
>> -		tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
>> +	child_pid = SAFE_WAIT(&status);
> 
>> -	tst_count = 0;
>> -
>> -	TEST(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, child_stack));
>> -	if (TEST_RETURN == -1)
>> -		tst_resm(TFAIL | TTERRNO, "clone failed");
>> -
>> -	child_pid = SAFE_WAIT(cleanup, &status);
>> -
>> -	if (TEST_RETURN == child_pid)
>> -		tst_resm(TPASS, "clone returned %ld", TEST_RETURN);
>> +	if (TST_RET == child_pid)
> 	if (child_pid ==  TST_RET)
> 
> => run `make check-clone01' to see this error (and run make check-* for other
> tests).
> 
> 
> Kind regards,
> Petr
> 

-- 
Regards,
Zhang Lianjie



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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH v2 1/7] syscalls/clone01: Convert to new API
  2021-09-23  8:56   ` zhanglianjie
@ 2021-09-23  9:05     ` Petr Vorel
  2021-09-23  9:14       ` zhanglianjie
  0 siblings, 1 reply; 7+ messages in thread
From: Petr Vorel @ 2021-09-23  9:05 UTC (permalink / raw)
  To: zhanglianjie; +Cc: ltp

Hi zhanglianjie,

> Hi,
> Please ignore other patches about clone testcases and just focus on
> v3.thanks.

FYI you can register on our patchwork instance [1] with email you use for
sending patches and update status of your patches (e.g. set patches to be
ignored to "Superseded" or "Changes Requested").

Kind regards,
Petr

[1] https://patchwork.ozlabs.org/register/

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH v2 1/7] syscalls/clone01: Convert to new API
  2021-09-23  9:05     ` Petr Vorel
@ 2021-09-23  9:14       ` zhanglianjie
  2021-09-23  9:25         ` Petr Vorel
  0 siblings, 1 reply; 7+ messages in thread
From: zhanglianjie @ 2021-09-23  9:14 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Oh thank you. ^_^

On 2021-09-23 17:05, Petr Vorel wrote:
> Hi zhanglianjie,
> 
>> Hi,
>> Please ignore other patches about clone testcases and just focus on
>> v3.thanks.
> 
> FYI you can register on our patchwork instance [1] with email you use for
> sending patches and update status of your patches (e.g. set patches to be
> ignored to "Superseded" or "Changes Requested").
> 
> Kind regards,
> Petr
> 
> [1] https://patchwork.ozlabs.org/register/
> 

-- 
Regards,
Zhang Lianjie



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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [LTP] [PATCH v2 1/7] syscalls/clone01: Convert to new API
  2021-09-23  9:14       ` zhanglianjie
@ 2021-09-23  9:25         ` Petr Vorel
  0 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2021-09-23  9:25 UTC (permalink / raw)
  To: zhanglianjie; +Cc: ltp

> Oh thank you. ^_^
FYI you'll be able to change state of your patches.
But in cases like this it helps us to handle the queue (we're always late).

Kind regards,
Petr

> On 2021-09-23 17:05, Petr Vorel wrote:
> > Hi zhanglianjie,

> > > Hi,
> > > Please ignore other patches about clone testcases and just focus on
> > > v3.thanks.

> > FYI you can register on our patchwork instance [1] with email you use for
> > sending patches and update status of your patches (e.g. set patches to be
> > ignored to "Superseded" or "Changes Requested").

> > Kind regards,
> > Petr

> > [1] https://patchwork.ozlabs.org/register/

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-23  9:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02  1:08 [LTP] [PATCH v2 1/7] syscalls/clone01: Convert to new API zhanglianjie
2021-09-02  6:02 ` Petr Vorel
2021-09-07 11:09   ` zhanglianjie
2021-09-07 11:09     ` zhanglianjie
2021-09-23  8:56   ` zhanglianjie
2021-09-23  9:05     ` Petr Vorel
2021-09-23  9:14       ` zhanglianjie
2021-09-23  9:25         ` Petr Vorel

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.