* [LTP] [PATCH 5/7] syscalls/clone05: Convert to new API
@ 2021-08-13 7:26 zhanglianjie
2021-08-25 14:28 ` Cyril Hrubis
0 siblings, 1 reply; 3+ messages in thread
From: zhanglianjie @ 2021-08-13 7:26 UTC (permalink / raw)
To: ltp
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..7e8253bfe 100644
--- a/testcases/kernel/syscalls/clone/clone05.c
+++ b/testcases/kernel/syscalls/clone/clone05.c
@@ -1,103 +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>
* 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 int child_exited = 0;
+static void *child_stack;
-int main(int ac, char **av)
+static int child_fn(void *unused __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");
+ for (i = 0; i < 100; i++) {
+ sched_yield();
+ usleep(1000);
+ }
- if ((wait(&status)) == -1)
- tst_brkm(TBROK | TERRNO, cleanup,
- "wait failed, status: %d", status);
+ child_exited = 1;
+ _exit(0);
+}
- child_exited = 0;
- }
+static void verify_clone(void)
+{
+ TST_EXP_POSITIVE(ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, child_fn, NULL,
+ CHILD_STACK_SIZE, child_stack), "clone with vfork");
- free(child_stack);
+ if (!TST_PASS)
+ return;
- cleanup();
- tst_exit();
+ TST_EXP_PASS(!child_exited);
}
static void setup(void)
{
- tst_sig(FORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
+ child_stack = SAFE_MALLOC(CHILD_STACK_SIZE);
+ child_exited = 0;
}
static void cleanup(void)
{
+ free(child_stack);
}
-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 = {
+ .setup = setup,
+ .test_all = verify_clone,
+ .cleanup = cleanup,
+};
\ No newline@end of file
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [LTP] [PATCH 5/7] syscalls/clone05: Convert to new API
2021-08-13 7:26 [LTP] [PATCH 5/7] syscalls/clone05: Convert to new API zhanglianjie
@ 2021-08-25 14:28 ` Cyril Hrubis
2021-08-26 11:10 ` zhanglianjie
0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2021-08-25 14:28 UTC (permalink / raw)
To: ltp
Hi!
> static int child_exited = 0;
^
This should be volatile to avoid compiler miscompilation,
also there is no point in setting it to 0 either, it's
global variable and these are initialized to zero
regardless.
> +static void *child_stack;
>
> -int main(int ac, char **av)
> +static int child_fn(void *unused __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");
> + for (i = 0; i < 100; i++) {
> + sched_yield();
> + usleep(1000);
> + }
>
> - if ((wait(&status)) == -1)
> - tst_brkm(TBROK | TERRNO, cleanup,
> - "wait failed, status: %d", status);
> + child_exited = 1;
> + _exit(0);
> +}
>
> - child_exited = 0;
> - }
> +static void verify_clone(void)
> +{
> + TST_EXP_POSITIVE(ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, child_fn, NULL,
> + CHILD_STACK_SIZE, child_stack), "clone with vfork");
>
> - free(child_stack);
> + if (!TST_PASS)
> + return;
>
> - cleanup();
> - tst_exit();
> + TST_EXP_PASS(!child_exited);
This is misuse of the macro, since the macro checks for -1 on failure
and we will get 1 on failure here.
I guess that we should add TST_EXP_VAL() instead for cases like this and
we would do:
TST_EXP_VAL(child_exited, 1);
Will you send a patch or should I add it?
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 3+ messages in thread* [LTP] [PATCH 5/7] syscalls/clone05: Convert to new API
2021-08-25 14:28 ` Cyril Hrubis
@ 2021-08-26 11:10 ` zhanglianjie
0 siblings, 0 replies; 3+ messages in thread
From: zhanglianjie @ 2021-08-26 11:10 UTC (permalink / raw)
To: ltp
Hi,
>> +static void verify_clone(void)
>> +{
>> + TST_EXP_POSITIVE(ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, child_fn, NULL,
>> + CHILD_STACK_SIZE, child_stack), "clone with vfork");
>>
>> - free(child_stack);
>> + if (!TST_PASS)
>> + return;
>>
>> - cleanup();
>> - tst_exit();
>> + TST_EXP_PASS(!child_exited);
>
> This is misuse of the macro, since the macro checks for -1 on failure
> and we will get 1 on failure here.
>
> I guess that we should add TST_EXP_VAL() instead for cases like this and
> we would do:
>
> TST_EXP_VAL(child_exited, 1);
>
> Will you send a patch or should I add it?
>
I will send patch to add TST_EXP_VAL, thank you.
--
Regards,
Zhang Lianjie
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-08-26 11:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-13 7:26 [LTP] [PATCH 5/7] syscalls/clone05: Convert to new API zhanglianjie
2021-08-25 14:28 ` Cyril Hrubis
2021-08-26 11:10 ` zhanglianjie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox