From: Cyril Hrubis <chrubis@suse.cz>
To: zhanglianjie <zhanglianjie@uniontech.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3 4/5] syscalls/clone06: Convert to new API
Date: Tue, 12 Oct 2021 11:21:54 +0200 [thread overview]
Message-ID: <YWVTsg3BLFwZRcl0@yuki> (raw)
In-Reply-To: <20210923085224.868-4-zhanglianjie@uniontech.com>
Hi!
> - cleanup();
> - tst_exit();
> + parent_env = getenv("TERM") ? : "";
I guess that it would make more sense to create a new variable than
depend on anything that may or may not be present on the system.
What about we setenv a variable instead and use that for the test?
#define ENV_VAL "LTP test variable value"
#define ENV_ID "LTP_CLONE_TEST"
static void setup(void)
{
int ret;
ret = setenv(ENV_ID, ENV_VAL, 0)
if (ret)
tst_brk(TBROK | TERRNO, "setenv() failed");
}
> + TST_EXP_VAL(strcmp(buff, parent_env), 0,
> + "verify environment variables by child");
Also there is no need to propagate the value to the parent like this,
the child process can report the result (in the new library) as well, so
this really could be as simple as:
static int do_child(void *arg LTP_ATTRIBUTE_UNUSED)
{
const char *env_val = getenv(ENV_ID);
if (!env_val) {
tst_res(TFAIL, "Variable " ENV_ID " not defined in child");
return;
}
if (strcmp(env_val, ENV_VAL)) {
tst_res(TFAIL, "Variable value is different");
return;
}
tst_res(TPASS, ...);
}
> }
>
> static void setup(void)
> {
> - tst_sig(FORK, DEF_HANDLER, cleanup);
> - TEST_PAUSE;
> + child_stack = SAFE_MALLOC(CHILD_STACK_SIZE);
> + buff = SAFE_MMAP(NULL, MAX_LINE_LENGTH, PROT_READ | PROT_WRITE,
> + MAP_SHARED | MAP_ANONYMOUS, -1, 0);
> }
>
> static void cleanup(void)
> {
> -}
> -
> -/*
> - * Function executed by child.
> - * Gets the value for environment variable,TERM &
> - * writes it to a pipe.
> - */
> -static int child_environ(void)
> -{
> -
> - char var[MAX_LINE_LENGTH];
> -
> - /* Close read end from child */
> - if ((close(pfd[0])) == -1)
> - tst_brkm(TBROK | TERRNO, cleanup, "close(pfd[0]) failed");
> -
> - if ((sprintf(var, "%s", getenv("TERM") ? : "")) < 0)
> - tst_resm(TWARN | TERRNO, "sprintf() failed");
> -
> - if ((write(pfd[1], var, MAX_LINE_LENGTH)) == -1)
> - tst_resm(TWARN | TERRNO, "write to pipe failed");
> -
> - /* Close write end of pipe from child */
> - if ((close(pfd[1])) == -1)
> - tst_resm(TWARN | TERRNO, "close(pfd[1]) failed");
> + free(child_stack);
>
> - exit(0);
> + if (buff)
> + SAFE_MUNMAP(buff, MAX_LINE_LENGTH);
> }
> +
> +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
next prev parent reply other threads:[~2021-10-12 9:21 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
2021-09-23 8:52 ` [LTP] [PATCH v3 4/5] syscalls/clone06: " zhanglianjie
2021-10-12 9:21 ` Cyril Hrubis [this message]
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=YWVTsg3BLFwZRcl0@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