public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: zhanglianjie <zhanglianjie@uniontech.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3 3/5] syscalls/clone05: Convert to new API
Date: Mon, 11 Oct 2021 17:59:52 +0200	[thread overview]
Message-ID: <YWRfeIfOExBjpety@yuki> (raw)
In-Reply-To: <20210923085224.868-3-zhanglianjie@uniontech.com>

Hi!
> +/*\
> + * [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 int child_exited;
              ^
This should be volatile as well in order to avoid compiler
mis-optimizations.

> +static void *child_stack;
> 
> -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");
> +	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_PID_SILENT(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_VAL(child_exited, 1);
>  }
> 
>  static void setup(void)
>  {
> -	tst_sig(FORK, DEF_HANDLER, cleanup);
> -
> -	TEST_PAUSE;
> +	child_stack = SAFE_MALLOC(CHILD_STACK_SIZE);
> +	child_exited = 0;

Here again this has to be cleared in the test function because
oftherwise the test will fail with -i 2.

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

Please use the guarded buffer in this test as well.

> -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,
> +};
> --
> 2.20.1
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

  reply	other threads:[~2021-10-11 15:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-23  8:52 [LTP] [PATCH v3 1/5] syscalls/clone02: Convert to new API zhanglianjie
2021-09-23  8:52 ` [LTP] [PATCH v3 2/5] syscalls/clone03: " zhanglianjie
2021-09-24  9:19   ` Richard Palethorpe
2021-10-11 15:02     ` Cyril Hrubis
2021-09-23  8:52 ` [LTP] [PATCH v3 3/5] syscalls/clone05: " zhanglianjie
2021-10-11 15:59   ` Cyril Hrubis [this message]
2021-09-23  8:52 ` [LTP] [PATCH v3 4/5] syscalls/clone06: " zhanglianjie
2021-10-12  9:21   ` Cyril Hrubis
2021-10-13  2:49     ` zhanglianjie
2021-09-23  8:52 ` [LTP] [PATCH v3 5/5] syscalls/clone07: " zhanglianjie
2021-10-12  9:37   ` Cyril Hrubis
2021-10-13  5:14     ` zhanglianjie
2021-10-13 10:00       ` Cyril Hrubis
2021-10-11 15:40 ` [LTP] [PATCH v3 1/5] syscalls/clone02: " Cyril Hrubis
2021-10-12  6:39   ` zhanglianjie

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=YWRfeIfOExBjpety@yuki \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=zhanglianjie@uniontech.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox