* [LTP] [PATCH] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME @ 2019-05-09 12:20 Yang Xu 2019-05-22 10:16 ` xuyang 2019-05-23 9:40 ` Cyril Hrubis 0 siblings, 2 replies; 13+ messages in thread From: Yang Xu @ 2019-05-09 12:20 UTC (permalink / raw) To: ltp Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com> --- include/lapi/prctl.h | 5 +++ runtest/syscalls | 1 + testcases/kernel/syscalls/prctl/.gitignore | 1 + testcases/kernel/syscalls/prctl/prctl05.c | 51 ++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 testcases/kernel/syscalls/prctl/prctl05.c diff --git a/include/lapi/prctl.h b/include/lapi/prctl.h index c3612e643..91da9c2d6 100644 --- a/include/lapi/prctl.h +++ b/include/lapi/prctl.h @@ -9,6 +9,11 @@ #include <sys/prctl.h> +#ifndef PR_SET_NAME +# define PR_SET_NAME 15 +# define PR_GET_NAME 16 +#endif + #ifndef PR_SET_CHILD_SUBREAPER # define PR_SET_CHILD_SUBREAPER 36 # define PR_GET_CHILD_SUBREAPER 37 diff --git a/runtest/syscalls b/runtest/syscalls index 51bff2990..950615bef 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -864,6 +864,7 @@ prctl01 prctl01 prctl02 prctl02 prctl03 prctl03 prctl04 prctl04 +prctl05 prctl05 pread01 pread01 pread01_64 pread01_64 diff --git a/testcases/kernel/syscalls/prctl/.gitignore b/testcases/kernel/syscalls/prctl/.gitignore index 1c3da3052..9ecaf9854 100644 --- a/testcases/kernel/syscalls/prctl/.gitignore +++ b/testcases/kernel/syscalls/prctl/.gitignore @@ -2,3 +2,4 @@ /prctl02 /prctl03 /prctl04 +/prctl05 diff --git a/testcases/kernel/syscalls/prctl/prctl05.c b/testcases/kernel/syscalls/prctl/prctl05.c new file mode 100644 index 000000000..8a0ea2eb3 --- /dev/null +++ b/testcases/kernel/syscalls/prctl/prctl05.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com> + * + * Test PR_GET_NAME and PR_SET_NAME of prctl(2). + * 1)Set the name of the calling thread, the name can be up to 16 bytes + * long, including the terminating null byte. If exceeds 16 bytes, the + * string is silently truncated. + * 2)Return the name of the calling thread, the buffer should allow space + * for up to 16 bytes, the returned string will be null-terminated. + */ + +#include <errno.h> +#include <sys/prctl.h> +#include <string.h> +#include <lapi/prctl.h> +#include "tst_test.h" + +#define thread_name "prctl05_test_xxxxx" + +static void verify_prctl(void) +{ + char buf[20]; + + TEST(prctl(PR_SET_NAME, &thread_name)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "prctl(PR_SET_NAME) failed"); + return; + } + tst_res(TPASS, "prctl(PR_SET_NAME) succeeded, set thread name as " + "prctl05_test_xxxxx"); + + TEST(prctl(PR_GET_NAME, &buf)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "prctl(PR_GET_NAME) failed"); + return; + } + + if (!strncmp(thread_name, buf, 15) && strlen(buf) == 15) + tst_res(TPASS, "prctl(PR_GET_NAME) succeeded, " + "thread name is %s", buf); + else + tst_res(TFAIL, + "prctl(PR_GET_NAME) failed to truncate the name into " + "16 byte long"); +} + +static struct tst_test test = { + .test_all = verify_prctl, +}; -- 2.18.1 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME 2019-05-09 12:20 [LTP] [PATCH] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME Yang Xu @ 2019-05-22 10:16 ` xuyang 2019-05-23 9:40 ` Cyril Hrubis 1 sibling, 0 replies; 13+ messages in thread From: xuyang @ 2019-05-22 10:16 UTC (permalink / raw) To: ltp Hi Ping. :-) > Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com> > --- > include/lapi/prctl.h | 5 +++ > runtest/syscalls | 1 + > testcases/kernel/syscalls/prctl/.gitignore | 1 + > testcases/kernel/syscalls/prctl/prctl05.c | 51 ++++++++++++++++++++++ > 4 files changed, 58 insertions(+) > create mode 100644 testcases/kernel/syscalls/prctl/prctl05.c > > diff --git a/include/lapi/prctl.h b/include/lapi/prctl.h > index c3612e643..91da9c2d6 100644 > --- a/include/lapi/prctl.h > +++ b/include/lapi/prctl.h > @@ -9,6 +9,11 @@ > > #include <sys/prctl.h> > > +#ifndef PR_SET_NAME > +# define PR_SET_NAME 15 > +# define PR_GET_NAME 16 > +#endif > + > #ifndef PR_SET_CHILD_SUBREAPER > # define PR_SET_CHILD_SUBREAPER 36 > # define PR_GET_CHILD_SUBREAPER 37 > diff --git a/runtest/syscalls b/runtest/syscalls > index 51bff2990..950615bef 100644 > --- a/runtest/syscalls > +++ b/runtest/syscalls > @@ -864,6 +864,7 @@ prctl01 prctl01 > prctl02 prctl02 > prctl03 prctl03 > prctl04 prctl04 > +prctl05 prctl05 > > pread01 pread01 > pread01_64 pread01_64 > diff --git a/testcases/kernel/syscalls/prctl/.gitignore b/testcases/kernel/syscalls/prctl/.gitignore > index 1c3da3052..9ecaf9854 100644 > --- a/testcases/kernel/syscalls/prctl/.gitignore > +++ b/testcases/kernel/syscalls/prctl/.gitignore > @@ -2,3 +2,4 @@ > /prctl02 > /prctl03 > /prctl04 > +/prctl05 > diff --git a/testcases/kernel/syscalls/prctl/prctl05.c b/testcases/kernel/syscalls/prctl/prctl05.c > new file mode 100644 > index 000000000..8a0ea2eb3 > --- /dev/null > +++ b/testcases/kernel/syscalls/prctl/prctl05.c > @@ -0,0 +1,51 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. > + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com> > + * > + * Test PR_GET_NAME and PR_SET_NAME of prctl(2). > + * 1)Set the name of the calling thread, the name can be up to 16 bytes > + * long, including the terminating null byte. If exceeds 16 bytes, the > + * string is silently truncated. > + * 2)Return the name of the calling thread, the buffer should allow space > + * for up to 16 bytes, the returned string will be null-terminated. > + */ > + > +#include <errno.h> > +#include <sys/prctl.h> > +#include <string.h> > +#include <lapi/prctl.h> > +#include "tst_test.h" > + > +#define thread_name "prctl05_test_xxxxx" > + > +static void verify_prctl(void) > +{ > + char buf[20]; > + > + TEST(prctl(PR_SET_NAME, &thread_name)); > + if (TST_RET == -1) { > + tst_res(TFAIL | TTERRNO, "prctl(PR_SET_NAME) failed"); > + return; > + } > + tst_res(TPASS, "prctl(PR_SET_NAME) succeeded, set thread name as " > + "prctl05_test_xxxxx"); > + > + TEST(prctl(PR_GET_NAME, &buf)); > + if (TST_RET == -1) { > + tst_res(TFAIL | TTERRNO, "prctl(PR_GET_NAME) failed"); > + return; > + } > + > + if (!strncmp(thread_name, buf, 15) && strlen(buf) == 15) > + tst_res(TPASS, "prctl(PR_GET_NAME) succeeded, " > + "thread name is %s", buf); > + else > + tst_res(TFAIL, > + "prctl(PR_GET_NAME) failed to truncate the name into " > + "16 byte long"); > +} > + > +static struct tst_test test = { > + .test_all = verify_prctl, > +}; ^ permalink raw reply [flat|nested] 13+ messages in thread
* [LTP] [PATCH] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME 2019-05-09 12:20 [LTP] [PATCH] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME Yang Xu 2019-05-22 10:16 ` xuyang @ 2019-05-23 9:40 ` Cyril Hrubis 2019-05-23 11:35 ` [LTP] [PATCH v2] " Yang Xu 1 sibling, 1 reply; 13+ messages in thread From: Cyril Hrubis @ 2019-05-23 9:40 UTC (permalink / raw) To: ltp Hi! > + TEST(prctl(PR_GET_NAME, &buf)); > + if (TST_RET == -1) { > + tst_res(TFAIL | TTERRNO, "prctl(PR_GET_NAME) failed"); > + return; > + } > + > + if (!strncmp(thread_name, buf, 15) && strlen(buf) == 15) ^ Here we are calling strlen() on potentionally unterminated buffer I guess that we should do buf[19] = 0 after the PR_GET_NAME prctl(). > + tst_res(TPASS, "prctl(PR_GET_NAME) succeeded, " > + "thread name is %s", buf); > + else > + tst_res(TFAIL, > + "prctl(PR_GET_NAME) failed to truncate the name into " > + "16 byte long"); Can we also check that the /proc/self/task/$tid/comm matches as well? > +} > + > +static struct tst_test test = { > + .test_all = verify_prctl, > +}; Other than that it looks good. -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 13+ messages in thread
* [LTP] [PATCH v2] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME 2019-05-23 9:40 ` Cyril Hrubis @ 2019-05-23 11:35 ` Yang Xu 2019-05-23 11:51 ` Xiao Yang 0 siblings, 1 reply; 13+ messages in thread From: Yang Xu @ 2019-05-23 11:35 UTC (permalink / raw) To: ltp Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com> --- include/lapi/prctl.h | 5 ++ runtest/syscalls | 1 + testcases/kernel/syscalls/prctl/.gitignore | 1 + testcases/kernel/syscalls/prctl/prctl05.c | 71 ++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 testcases/kernel/syscalls/prctl/prctl05.c diff --git a/include/lapi/prctl.h b/include/lapi/prctl.h index f42bd6459..ad0b12bce 100644 --- a/include/lapi/prctl.h +++ b/include/lapi/prctl.h @@ -9,6 +9,11 @@ #include <sys/prctl.h> +#ifndef PR_SET_NAME +# define PR_SET_NAME 15 +# define PR_GET_NAME 16 +#endif + #ifndef PR_SET_SECCOMP # define PR_GET_SECCOMP 21 # define PR_SET_SECCOMP 22 diff --git a/runtest/syscalls b/runtest/syscalls index 04558a580..d2dcd2152 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -862,6 +862,7 @@ prctl01 prctl01 prctl02 prctl02 prctl03 prctl03 prctl04 prctl04 +prctl05 prctl05 pread01 pread01 pread01_64 pread01_64 diff --git a/testcases/kernel/syscalls/prctl/.gitignore b/testcases/kernel/syscalls/prctl/.gitignore index 1c3da3052..9ecaf9854 100644 --- a/testcases/kernel/syscalls/prctl/.gitignore +++ b/testcases/kernel/syscalls/prctl/.gitignore @@ -2,3 +2,4 @@ /prctl02 /prctl03 /prctl04 +/prctl05 diff --git a/testcases/kernel/syscalls/prctl/prctl05.c b/testcases/kernel/syscalls/prctl/prctl05.c new file mode 100644 index 000000000..fad5b23bf --- /dev/null +++ b/testcases/kernel/syscalls/prctl/prctl05.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com> + * + * Test PR_GET_NAME and PR_SET_NAME of prctl(2). + * 1)Set the name of the calling thread, the name can be up to 16 bytes + * long, including the terminating null byte. If exceeds 16 bytes, the + * string is silently truncated. + * 2)Return the name of the calling thread, the buffer should allow space + * for up to 16 bytes, the returned string will be null-terminated. + * 3)Check /proc/self/task/[tid]/comm name whether matches the thread_name. + */ + +#include <errno.h> +#include <sys/types.h> +#include <sys/prctl.h> +#include <string.h> +#include <stdio.h> +#include "lapi/syscalls.h" +#include "lapi/prctl.h" +#include "tst_test.h" + +#define thread_name "prctl05_test_xxxxx" + +static void verify_prctl(void) +{ + char buf[20]; + char comm_buf[20]; + char PROC_NAME_PATH[40]; + pid_t tid; + + TEST(prctl(PR_SET_NAME, &thread_name)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "prctl(PR_SET_NAME) failed"); + return; + } + tst_res(TPASS, + "prctl(PR_SET_NAME) succeeded, set thread name as prctl05_test_xxxxx"); + + TEST(prctl(PR_GET_NAME, &buf)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "prctl(PR_GET_NAME) failed"); + return; + } + + buf[19] = '\0'; + if (!strncmp(thread_name, buf, 15) && strlen(buf) == 15) + tst_res(TPASS, "prctl(PR_GET_NAME) succeeded, " + "thread name is %s", buf); + else + tst_res(TFAIL, + "prctl(PR_GET_NAME) failed to truncate the name into 16 byte long"); + + tid = tst_syscall(__NR_gettid); + + sprintf(PROC_NAME_PATH, "/proc/self/task/%d/comm", tid); + SAFE_FILE_SCANF(PROC_NAME_PATH, "%s", comm_buf); + if (strcmp(buf, comm_buf)) + tst_res(TFAIL, + "%s sets name failed, expected prctl105_test_xx, got %s", + PROC_NAME_PATH, comm_buf); + else + tst_res(TPASS, "%s sets thread name succeed as %s", + PROC_NAME_PATH, comm_buf); + +} + +static struct tst_test test = { + .test_all = verify_prctl, +}; -- 2.18.1 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH v2] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME 2019-05-23 11:35 ` [LTP] [PATCH v2] " Yang Xu @ 2019-05-23 11:51 ` Xiao Yang 2019-05-24 7:36 ` xuyang 2019-05-24 7:50 ` [LTP] [PATCH v3] " Yang Xu 0 siblings, 2 replies; 13+ messages in thread From: Xiao Yang @ 2019-05-23 11:51 UTC (permalink / raw) To: ltp On 05/23/2019 07:35 PM, Yang Xu wrote: > Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com> > --- > include/lapi/prctl.h | 5 ++ > runtest/syscalls | 1 + > testcases/kernel/syscalls/prctl/.gitignore | 1 + > testcases/kernel/syscalls/prctl/prctl05.c | 71 ++++++++++++++++++++++ > 4 files changed, 78 insertions(+) > create mode 100644 testcases/kernel/syscalls/prctl/prctl05.c > > diff --git a/include/lapi/prctl.h b/include/lapi/prctl.h > index f42bd6459..ad0b12bce 100644 > --- a/include/lapi/prctl.h > +++ b/include/lapi/prctl.h > @@ -9,6 +9,11 @@ > > #include <sys/prctl.h> > > +#ifndef PR_SET_NAME > +# define PR_SET_NAME 15 > +# define PR_GET_NAME 16 > +#endif > + > #ifndef PR_SET_SECCOMP > # define PR_GET_SECCOMP 21 > # define PR_SET_SECCOMP 22 > diff --git a/runtest/syscalls b/runtest/syscalls > index 04558a580..d2dcd2152 100644 > --- a/runtest/syscalls > +++ b/runtest/syscalls > @@ -862,6 +862,7 @@ prctl01 prctl01 > prctl02 prctl02 > prctl03 prctl03 > prctl04 prctl04 > +prctl05 prctl05 > > pread01 pread01 > pread01_64 pread01_64 > diff --git a/testcases/kernel/syscalls/prctl/.gitignore b/testcases/kernel/syscalls/prctl/.gitignore > index 1c3da3052..9ecaf9854 100644 > --- a/testcases/kernel/syscalls/prctl/.gitignore > +++ b/testcases/kernel/syscalls/prctl/.gitignore > @@ -2,3 +2,4 @@ > /prctl02 > /prctl03 > /prctl04 > +/prctl05 > diff --git a/testcases/kernel/syscalls/prctl/prctl05.c b/testcases/kernel/syscalls/prctl/prctl05.c > new file mode 100644 > index 000000000..fad5b23bf > --- /dev/null > +++ b/testcases/kernel/syscalls/prctl/prctl05.c > @@ -0,0 +1,71 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. > + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com> > + * > + * Test PR_GET_NAME and PR_SET_NAME of prctl(2). > + * 1)Set the name of the calling thread, the name can be up to 16 bytes > + * long, including the terminating null byte. If exceeds 16 bytes, the > + * string is silently truncated. > + * 2)Return the name of the calling thread, the buffer should allow space > + * for up to 16 bytes, the returned string will be null-terminated. > + * 3)Check /proc/self/task/[tid]/comm name whether matches the thread_name. > + */ > + > +#include <errno.h> > +#include <sys/types.h> > +#include <sys/prctl.h> > +#include <string.h> > +#include <stdio.h> > +#include "lapi/syscalls.h" > +#include "lapi/prctl.h" > +#include "tst_test.h" > + > +#define thread_name "prctl05_test_xxxxx" Hi Xu, It seems better to use upper case for macro. > + > +static void verify_prctl(void) > +{ > + char buf[20]; > + char comm_buf[20]; > + char PROC_NAME_PATH[40]; > + pid_t tid; > + > + TEST(prctl(PR_SET_NAME, &thread_name)); Why do you want to use the address of macro? > + if (TST_RET == -1) { > + tst_res(TFAIL | TTERRNO, "prctl(PR_SET_NAME) failed"); > + return; > + } > + tst_res(TPASS, > + "prctl(PR_SET_NAME) succeeded, set thread name as prctl05_test_xxxxx"); How about using ("...set thread name as %s", thread_name)? > + > + TEST(prctl(PR_GET_NAME, &buf)); &buf is the same as buf here so we can use buf directly. > + if (TST_RET == -1) { > + tst_res(TFAIL | TTERRNO, "prctl(PR_GET_NAME) failed"); > + return; > + } > + > + buf[19] = '\0'; > + if (!strncmp(thread_name, buf, 15) && strlen(buf) == 15) > + tst_res(TPASS, "prctl(PR_GET_NAME) succeeded, " > + "thread name is %s", buf); > + else > + tst_res(TFAIL, > + "prctl(PR_GET_NAME) failed to truncate the name into 16 byte long"); Can we test the shorter name of the calling thread(i.e. shorter than 16 byte) as well? Best Regards, Xiao Yang > + > + tid = tst_syscall(__NR_gettid); > + > + sprintf(PROC_NAME_PATH, "/proc/self/task/%d/comm", tid); > + SAFE_FILE_SCANF(PROC_NAME_PATH, "%s", comm_buf); > + if (strcmp(buf, comm_buf)) > + tst_res(TFAIL, > + "%s sets name failed, expected prctl105_test_xx, got %s", > + PROC_NAME_PATH, comm_buf); > + else > + tst_res(TPASS, "%s sets thread name succeed as %s", > + PROC_NAME_PATH, comm_buf); > + > +} > + > +static struct tst_test test = { > + .test_all = verify_prctl, > +}; ^ permalink raw reply [flat|nested] 13+ messages in thread
* [LTP] [PATCH v2] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME 2019-05-23 11:51 ` Xiao Yang @ 2019-05-24 7:36 ` xuyang 2019-05-24 7:50 ` [LTP] [PATCH v3] " Yang Xu 1 sibling, 0 replies; 13+ messages in thread From: xuyang @ 2019-05-24 7:36 UTC (permalink / raw) To: ltp on 2019/05/23 19:51, Xiao Yang wrote: > > > On 05/23/2019 07:35 PM, Yang Xu wrote: >> Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com> >> --- >> include/lapi/prctl.h | 5 ++ >> runtest/syscalls | 1 + >> testcases/kernel/syscalls/prctl/.gitignore | 1 + >> testcases/kernel/syscalls/prctl/prctl05.c | 71 ++++++++++++++++++++++ >> 4 files changed, 78 insertions(+) >> create mode 100644 testcases/kernel/syscalls/prctl/prctl05.c >> >> diff --git a/include/lapi/prctl.h b/include/lapi/prctl.h >> index f42bd6459..ad0b12bce 100644 >> --- a/include/lapi/prctl.h >> +++ b/include/lapi/prctl.h >> @@ -9,6 +9,11 @@ >> #include <sys/prctl.h> >> +#ifndef PR_SET_NAME >> +# define PR_SET_NAME 15 >> +# define PR_GET_NAME 16 >> +#endif >> + >> #ifndef PR_SET_SECCOMP >> # define PR_GET_SECCOMP 21 >> # define PR_SET_SECCOMP 22 >> diff --git a/runtest/syscalls b/runtest/syscalls >> index 04558a580..d2dcd2152 100644 >> --- a/runtest/syscalls >> +++ b/runtest/syscalls >> @@ -862,6 +862,7 @@ prctl01 prctl01 >> prctl02 prctl02 >> prctl03 prctl03 >> prctl04 prctl04 >> +prctl05 prctl05 >> pread01 pread01 >> pread01_64 pread01_64 >> diff --git a/testcases/kernel/syscalls/prctl/.gitignore >> b/testcases/kernel/syscalls/prctl/.gitignore >> index 1c3da3052..9ecaf9854 100644 >> --- a/testcases/kernel/syscalls/prctl/.gitignore >> +++ b/testcases/kernel/syscalls/prctl/.gitignore >> @@ -2,3 +2,4 @@ >> /prctl02 >> /prctl03 >> /prctl04 >> +/prctl05 >> diff --git a/testcases/kernel/syscalls/prctl/prctl05.c >> b/testcases/kernel/syscalls/prctl/prctl05.c >> new file mode 100644 >> index 000000000..fad5b23bf >> --- /dev/null >> +++ b/testcases/kernel/syscalls/prctl/prctl05.c >> @@ -0,0 +1,71 @@ >> +// SPDX-License-Identifier: GPL-2.0-or-later >> +/* >> + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. >> + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com> >> + * >> + * Test PR_GET_NAME and PR_SET_NAME of prctl(2). >> + * 1)Set the name of the calling thread, the name can be up to 16 bytes >> + * long, including the terminating null byte. If exceeds 16 bytes, >> the >> + * string is silently truncated. >> + * 2)Return the name of the calling thread, the buffer should allow >> space >> + * for up to 16 bytes, the returned string will be null-terminated. >> + * 3)Check /proc/self/task/[tid]/comm name whether matches the >> thread_name. >> + */ >> + >> +#include <errno.h> >> +#include <sys/types.h> >> +#include <sys/prctl.h> >> +#include <string.h> >> +#include <stdio.h> >> +#include "lapi/syscalls.h" >> +#include "lapi/prctl.h" >> +#include "tst_test.h" >> + >> +#define thread_name "prctl05_test_xxxxx" > Hi Xu, > > It seems better to use upper case for macro. > >> + >> +static void verify_prctl(void) >> +{ >> + char buf[20]; >> + char comm_buf[20]; >> + char PROC_NAME_PATH[40]; >> + pid_t tid; >> + >> + TEST(prctl(PR_SET_NAME, &thread_name)); > > Why do you want to use the address of macro? > >> + if (TST_RET == -1) { >> + tst_res(TFAIL | TTERRNO, "prctl(PR_SET_NAME) failed"); >> + return; >> + } >> + tst_res(TPASS, >> + "prctl(PR_SET_NAME) succeeded, set thread name as >> prctl05_test_xxxxx"); > > How about using ("...set thread name as %s", thread_name)? > >> + >> + TEST(prctl(PR_GET_NAME, &buf)); > > &buf is the same as buf here so we can use buf directly. > >> + if (TST_RET == -1) { >> + tst_res(TFAIL | TTERRNO, "prctl(PR_GET_NAME) failed"); >> + return; >> + } >> + >> + buf[19] = '\0'; >> + if (!strncmp(thread_name, buf, 15) && strlen(buf) == 15) >> + tst_res(TPASS, "prctl(PR_GET_NAME) succeeded, " >> + "thread name is %s", buf); >> + else >> + tst_res(TFAIL, >> + "prctl(PR_GET_NAME) failed to truncate the name into 16 >> byte long"); > > Can we test the shorter name of the calling thread(i.e. shorter than > 16 byte) as well? Hi xiao OK. I will add a test for the shorter name and correct my code in v3 patch. Thanks for your review. Best Regards Yang Xu > > Best Regards, > Xiao Yang >> + >> + tid = tst_syscall(__NR_gettid); >> + >> + sprintf(PROC_NAME_PATH, "/proc/self/task/%d/comm", tid); >> + SAFE_FILE_SCANF(PROC_NAME_PATH, "%s", comm_buf); >> + if (strcmp(buf, comm_buf)) >> + tst_res(TFAIL, >> + "%s sets name failed, expected prctl105_test_xx, got %s", >> + PROC_NAME_PATH, comm_buf); >> + else >> + tst_res(TPASS, "%s sets thread name succeed as %s", >> + PROC_NAME_PATH, comm_buf); >> + >> +} >> + >> +static struct tst_test test = { >> + .test_all = verify_prctl, >> +}; > > > > > . > ^ permalink raw reply [flat|nested] 13+ messages in thread
* [LTP] [PATCH v3] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME 2019-05-23 11:51 ` Xiao Yang 2019-05-24 7:36 ` xuyang @ 2019-05-24 7:50 ` Yang Xu 2019-05-24 13:21 ` Cyril Hrubis 2019-05-24 13:45 ` Xiao Yang 1 sibling, 2 replies; 13+ messages in thread From: Yang Xu @ 2019-05-24 7:50 UTC (permalink / raw) To: ltp Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com> --- include/lapi/prctl.h | 5 ++ runtest/syscalls | 1 + testcases/kernel/syscalls/prctl/.gitignore | 1 + testcases/kernel/syscalls/prctl/prctl05.c | 76 ++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 testcases/kernel/syscalls/prctl/prctl05.c diff --git a/include/lapi/prctl.h b/include/lapi/prctl.h index f42bd6459..ad0b12bce 100644 --- a/include/lapi/prctl.h +++ b/include/lapi/prctl.h @@ -9,6 +9,11 @@ #include <sys/prctl.h> +#ifndef PR_SET_NAME +# define PR_SET_NAME 15 +# define PR_GET_NAME 16 +#endif + #ifndef PR_SET_SECCOMP # define PR_GET_SECCOMP 21 # define PR_SET_SECCOMP 22 diff --git a/runtest/syscalls b/runtest/syscalls index 04558a580..d2dcd2152 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -862,6 +862,7 @@ prctl01 prctl01 prctl02 prctl02 prctl03 prctl03 prctl04 prctl04 +prctl05 prctl05 pread01 pread01 pread01_64 pread01_64 diff --git a/testcases/kernel/syscalls/prctl/.gitignore b/testcases/kernel/syscalls/prctl/.gitignore index 1c3da3052..9ecaf9854 100644 --- a/testcases/kernel/syscalls/prctl/.gitignore +++ b/testcases/kernel/syscalls/prctl/.gitignore @@ -2,3 +2,4 @@ /prctl02 /prctl03 /prctl04 +/prctl05 diff --git a/testcases/kernel/syscalls/prctl/prctl05.c b/testcases/kernel/syscalls/prctl/prctl05.c new file mode 100644 index 000000000..e1287abdf --- /dev/null +++ b/testcases/kernel/syscalls/prctl/prctl05.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com> + * + * Test PR_GET_NAME and PR_SET_NAME of prctl(2). + * 1)Set the name of the calling thread, the name can be up to 16 bytes + * long, including the terminating null byte. If exceeds 16 bytes, the + * string is silently truncated. + * 2)Return the name of the calling thread, the buffer should allow space + * for up to 16 bytes, the returned string will be null-terminated. + * 3)Check /proc/self/task/[tid]/comm name whether matches the thread name. + */ + +#include <sys/prctl.h> +#include <string.h> +#include <stdio.h> +#include "lapi/syscalls.h" +#include "lapi/prctl.h" +#include "tst_test.h" + +static struct tcase { + char setname[20]; + char expname[20]; +} tcases[] = { + {"prctl05_test", "prctl05_test"}, + {"prctl05_test_xxxxx", "prctl05_test_xx"} +}; + +static void verify_prctl(unsigned int n) +{ + char buf[20]; + char comm_buf[20]; + char PROC_NAME_PATH[40]; + pid_t tid; + struct tcase *tc = &tcases[n]; + + TEST(prctl(PR_SET_NAME, tc->setname)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "prctl(PR_SET_NAME) failed"); + return; + } + tst_res(TPASS, + "prctl(PR_SET_NAME) succeeded, set thread name as %s", tc->setname); + + TEST(prctl(PR_GET_NAME, buf)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "prctl(PR_GET_NAME) failed"); + return; + } + + if (strcmp(tc->expname, buf)) + tst_res(TFAIL, + "prctl(PR_GET_NAME) failed ,expected %s, got %s", tc->expname, buf); + else + tst_res(TPASS, + "prctl(PR_GET_NAME) succeeded, thread name is %s", buf); + + tid = tst_syscall(__NR_gettid); + + sprintf(PROC_NAME_PATH, "/proc/self/task/%d/comm", tid); + SAFE_FILE_SCANF(PROC_NAME_PATH, "%s", comm_buf); + if (strcmp(tc->expname, comm_buf)) + tst_res(TFAIL, + "%s sets thread name failed, expected %s, got %s", + PROC_NAME_PATH, tc->expname, comm_buf); + else + tst_res(TPASS, "%s sets thread name succeed as %s", + PROC_NAME_PATH, comm_buf); + +} + +static struct tst_test test = { + .test = verify_prctl, + .tcnt = ARRAY_SIZE(tcases), +}; -- 2.18.1 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH v3] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME 2019-05-24 7:50 ` [LTP] [PATCH v3] " Yang Xu @ 2019-05-24 13:21 ` Cyril Hrubis 2019-05-24 13:45 ` Xiao Yang 1 sibling, 0 replies; 13+ messages in thread From: Cyril Hrubis @ 2019-05-24 13:21 UTC (permalink / raw) To: ltp Hi! > +#include <sys/prctl.h> > +#include <string.h> > +#include <stdio.h> > +#include "lapi/syscalls.h" > +#include "lapi/prctl.h" > +#include "tst_test.h" > + > +static struct tcase { > + char setname[20]; > + char expname[20]; > +} tcases[] = { > + {"prctl05_test", "prctl05_test"}, > + {"prctl05_test_xxxxx", "prctl05_test_xx"} > +}; > + > +static void verify_prctl(unsigned int n) > +{ > + char buf[20]; > + char comm_buf[20]; > + char PROC_NAME_PATH[40]; Uppercase identifiers are by convention used for macros, this should be proc_path, or just path. > + pid_t tid; > + struct tcase *tc = &tcases[n]; > + > + TEST(prctl(PR_SET_NAME, tc->setname)); > + if (TST_RET == -1) { > + tst_res(TFAIL | TTERRNO, "prctl(PR_SET_NAME) failed"); > + return; > + } > + tst_res(TPASS, > + "prctl(PR_SET_NAME) succeeded, set thread name as %s", tc->setname); This could be shorter, why not just: tst_res(TPASS, "prctl(PR_SET_NAME, '%s')", tc->setname); > + TEST(prctl(PR_GET_NAME, buf)); > + if (TST_RET == -1) { > + tst_res(TFAIL | TTERRNO, "prctl(PR_GET_NAME) failed"); > + return; > + } Looks like the null-termination got lost between v2 and v3. And it would be better not to hardcode the size with: buf[sizeof(buf)-1] = 0; > + if (strcmp(tc->expname, buf)) > + tst_res(TFAIL, > + "prctl(PR_GET_NAME) failed ,expected %s, got %s", tc->expname, buf); ^ The comma should be before the space. > + else > + tst_res(TPASS, > + "prctl(PR_GET_NAME) succeeded, thread name is %s", buf); > + > + tid = tst_syscall(__NR_gettid); > + > + sprintf(PROC_NAME_PATH, "/proc/self/task/%d/comm", tid); > + SAFE_FILE_SCANF(PROC_NAME_PATH, "%s", comm_buf); > + if (strcmp(tc->expname, comm_buf)) > + tst_res(TFAIL, > + "%s sets thread name failed, expected %s, got %s", This message could be shorter and to the point, something as: tst_res(TFAIL, "%s has %s, expected %s", path, buf, tc->expname); > + PROC_NAME_PATH, tc->expname, comm_buf); > + else > + tst_res(TPASS, "%s sets thread name succeed as %s", Here as well, something as: tst_res(TPASS, "%s set to %s", path, buf); > + PROC_NAME_PATH, comm_buf); > + > +} > + > +static struct tst_test test = { > + .test = verify_prctl, > + .tcnt = ARRAY_SIZE(tcases), > +}; > -- > 2.18.1 > > > -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 13+ messages in thread
* [LTP] [PATCH v3] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME 2019-05-24 7:50 ` [LTP] [PATCH v3] " Yang Xu 2019-05-24 13:21 ` Cyril Hrubis @ 2019-05-24 13:45 ` Xiao Yang 2019-05-24 13:48 ` Cyril Hrubis 1 sibling, 1 reply; 13+ messages in thread From: Xiao Yang @ 2019-05-24 13:45 UTC (permalink / raw) To: ltp On 05/24/2019 03:50 PM, Yang Xu wrote: > Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com> > --- > include/lapi/prctl.h | 5 ++ > runtest/syscalls | 1 + > testcases/kernel/syscalls/prctl/.gitignore | 1 + > testcases/kernel/syscalls/prctl/prctl05.c | 76 ++++++++++++++++++++++ > 4 files changed, 83 insertions(+) > create mode 100644 testcases/kernel/syscalls/prctl/prctl05.c > > diff --git a/include/lapi/prctl.h b/include/lapi/prctl.h > index f42bd6459..ad0b12bce 100644 > --- a/include/lapi/prctl.h > +++ b/include/lapi/prctl.h > @@ -9,6 +9,11 @@ > > #include <sys/prctl.h> > > +#ifndef PR_SET_NAME > +# define PR_SET_NAME 15 > +# define PR_GET_NAME 16 > +#endif > + > #ifndef PR_SET_SECCOMP > # define PR_GET_SECCOMP 21 > # define PR_SET_SECCOMP 22 > diff --git a/runtest/syscalls b/runtest/syscalls > index 04558a580..d2dcd2152 100644 > --- a/runtest/syscalls > +++ b/runtest/syscalls > @@ -862,6 +862,7 @@ prctl01 prctl01 > prctl02 prctl02 > prctl03 prctl03 > prctl04 prctl04 > +prctl05 prctl05 > > pread01 pread01 > pread01_64 pread01_64 > diff --git a/testcases/kernel/syscalls/prctl/.gitignore b/testcases/kernel/syscalls/prctl/.gitignore > index 1c3da3052..9ecaf9854 100644 > --- a/testcases/kernel/syscalls/prctl/.gitignore > +++ b/testcases/kernel/syscalls/prctl/.gitignore > @@ -2,3 +2,4 @@ > /prctl02 > /prctl03 > /prctl04 > +/prctl05 > diff --git a/testcases/kernel/syscalls/prctl/prctl05.c b/testcases/kernel/syscalls/prctl/prctl05.c > new file mode 100644 > index 000000000..e1287abdf > --- /dev/null > +++ b/testcases/kernel/syscalls/prctl/prctl05.c > @@ -0,0 +1,76 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. > + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com> > + * > + * Test PR_GET_NAME and PR_SET_NAME of prctl(2). > + * 1)Set the name of the calling thread, the name can be up to 16 bytes > + * long, including the terminating null byte. If exceeds 16 bytes, the > + * string is silently truncated. > + * 2)Return the name of the calling thread, the buffer should allow space > + * for up to 16 bytes, the returned string will be null-terminated. > + * 3)Check /proc/self/task/[tid]/comm name whether matches the thread name. > + */ > + > +#include <sys/prctl.h> > +#include <string.h> > +#include <stdio.h> > +#include "lapi/syscalls.h" > +#include "lapi/prctl.h" > +#include "tst_test.h" > + > +static struct tcase { > + char setname[20]; > + char expname[20]; > +} tcases[] = { > + {"prctl05_test", "prctl05_test"}, > + {"prctl05_test_xxxxx", "prctl05_test_xx"} > +}; > + > +static void verify_prctl(unsigned int n) > +{ > + char buf[20]; > + char comm_buf[20]; > + char PROC_NAME_PATH[40]; > + pid_t tid; > + struct tcase *tc = &tcases[n]; > + > + TEST(prctl(PR_SET_NAME, tc->setname)); > + if (TST_RET == -1) { > + tst_res(TFAIL | TTERRNO, "prctl(PR_SET_NAME) failed"); > + return; > + } > + tst_res(TPASS, > + "prctl(PR_SET_NAME) succeeded, set thread name as %s", tc->setname); > + > + TEST(prctl(PR_GET_NAME, buf)); > + if (TST_RET == -1) { > + tst_res(TFAIL | TTERRNO, "prctl(PR_GET_NAME) failed"); > + return; > + } > + > + if (strcmp(tc->expname, buf)) > + tst_res(TFAIL, > + "prctl(PR_GET_NAME) failed ,expected %s, got %s", tc->expname, buf); > + else > + tst_res(TPASS, > + "prctl(PR_GET_NAME) succeeded, thread name is %s", buf); Hi Xu, It is not necessary to continue if buf mismatches tc->expname. > + > + tid = tst_syscall(__NR_gettid); > + > + sprintf(PROC_NAME_PATH, "/proc/self/task/%d/comm", tid); > + SAFE_FILE_SCANF(PROC_NAME_PATH, "%s", comm_buf); You didn't create multiple threads here so it seems simpler to use /proc/self/comm instead of /proc/self/task/<tid>/comm. do you think so? Please see the following url for details: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/proc.txt BTW: Should we print three TPASS messages for one test? Can we replace previous TPASS with TINFO and then print TPASS at the end? Best Regards, Xiao Yang > + if (strcmp(tc->expname, comm_buf)) > + tst_res(TFAIL, > + "%s sets thread name failed, expected %s, got %s", > + PROC_NAME_PATH, tc->expname, comm_buf); > + else > + tst_res(TPASS, "%s sets thread name succeed as %s", > + PROC_NAME_PATH, comm_buf); > + > +} > + > +static struct tst_test test = { > + .test = verify_prctl, > + .tcnt = ARRAY_SIZE(tcases), > +}; ^ permalink raw reply [flat|nested] 13+ messages in thread
* [LTP] [PATCH v3] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME 2019-05-24 13:45 ` Xiao Yang @ 2019-05-24 13:48 ` Cyril Hrubis 2019-05-24 13:58 ` Xiao Yang 0 siblings, 1 reply; 13+ messages in thread From: Cyril Hrubis @ 2019-05-24 13:48 UTC (permalink / raw) To: ltp Hi! > > + if (strcmp(tc->expname, buf)) > > + tst_res(TFAIL, > > + "prctl(PR_GET_NAME) failed ,expected %s, got %s", tc->expname, buf); > > + else > > + tst_res(TPASS, > > + "prctl(PR_GET_NAME) succeeded, thread name is %s", buf); > Hi Xu, > > It is not necessary to continue if buf mismatches tc->expname. > > > + > > + tid = tst_syscall(__NR_gettid); > > + > > + sprintf(PROC_NAME_PATH, "/proc/self/task/%d/comm", tid); > > + SAFE_FILE_SCANF(PROC_NAME_PATH, "%s", comm_buf); > > You didn't create multiple threads here so it seems simpler to use > /proc/self/comm > instead of /proc/self/task/<tid>/comm. do you think so? > Please see the following url for details: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/proc.txt Actually we should check both. > BTW: > Should we print three TPASS messages for one test? > Can we replace previous TPASS with TINFO and then print TPASS at the end? I think that it's cleaner to print PASS/FAIL message for each subtest. -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 13+ messages in thread
* [LTP] [PATCH v3] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME 2019-05-24 13:48 ` Cyril Hrubis @ 2019-05-24 13:58 ` Xiao Yang 2019-05-27 8:19 ` [LTP] [PATCH v4] " Yang Xu 0 siblings, 1 reply; 13+ messages in thread From: Xiao Yang @ 2019-05-24 13:58 UTC (permalink / raw) To: ltp On 05/24/2019 09:48 PM, Cyril Hrubis wrote: > Hi! >>> + if (strcmp(tc->expname, buf)) >>> + tst_res(TFAIL, >>> + "prctl(PR_GET_NAME) failed ,expected %s, got %s", tc->expname, buf); >>> + else >>> + tst_res(TPASS, >>> + "prctl(PR_GET_NAME) succeeded, thread name is %s", buf); >> Hi Xu, >> >> It is not necessary to continue if buf mismatches tc->expname. >> >>> + >>> + tid = tst_syscall(__NR_gettid); >>> + >>> + sprintf(PROC_NAME_PATH, "/proc/self/task/%d/comm", tid); >>> + SAFE_FILE_SCANF(PROC_NAME_PATH, "%s", comm_buf); >> You didn't create multiple threads here so it seems simpler to use >> /proc/self/comm >> instead of /proc/self/task/<tid>/comm. do you think so? >> Please see the following url for details: >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/proc.txt > Actually we should check both. Hi Cyril, Thanks for your quick reply. It's better to check both. >> BTW: >> Should we print three TPASS messages for one test? >> Can we replace previous TPASS with TINFO and then print TPASS at the end? > I think that it's cleaner to print PASS/FAIL message for each subtest. OK, we can keep it as you said. Best Regards, Xiao Yang ^ permalink raw reply [flat|nested] 13+ messages in thread
* [LTP] [PATCH v4] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME 2019-05-24 13:58 ` Xiao Yang @ 2019-05-27 8:19 ` Yang Xu 2019-05-27 13:41 ` Cyril Hrubis 0 siblings, 1 reply; 13+ messages in thread From: Yang Xu @ 2019-05-27 8:19 UTC (permalink / raw) To: ltp Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com> --- include/lapi/prctl.h | 5 ++ runtest/syscalls | 1 + testcases/kernel/syscalls/prctl/.gitignore | 1 + testcases/kernel/syscalls/prctl/prctl05.c | 81 ++++++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 testcases/kernel/syscalls/prctl/prctl05.c diff --git a/include/lapi/prctl.h b/include/lapi/prctl.h index f42bd6459..ad0b12bce 100644 --- a/include/lapi/prctl.h +++ b/include/lapi/prctl.h @@ -9,6 +9,11 @@ #include <sys/prctl.h> +#ifndef PR_SET_NAME +# define PR_SET_NAME 15 +# define PR_GET_NAME 16 +#endif + #ifndef PR_SET_SECCOMP # define PR_GET_SECCOMP 21 # define PR_SET_SECCOMP 22 diff --git a/runtest/syscalls b/runtest/syscalls index 04558a580..d2dcd2152 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -862,6 +862,7 @@ prctl01 prctl01 prctl02 prctl02 prctl03 prctl03 prctl04 prctl04 +prctl05 prctl05 pread01 pread01 pread01_64 pread01_64 diff --git a/testcases/kernel/syscalls/prctl/.gitignore b/testcases/kernel/syscalls/prctl/.gitignore index 1c3da3052..9ecaf9854 100644 --- a/testcases/kernel/syscalls/prctl/.gitignore +++ b/testcases/kernel/syscalls/prctl/.gitignore @@ -2,3 +2,4 @@ /prctl02 /prctl03 /prctl04 +/prctl05 diff --git a/testcases/kernel/syscalls/prctl/prctl05.c b/testcases/kernel/syscalls/prctl/prctl05.c new file mode 100644 index 000000000..bbd2a9c98 --- /dev/null +++ b/testcases/kernel/syscalls/prctl/prctl05.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com> + * + * Test PR_GET_NAME and PR_SET_NAME of prctl(2). + * 1)Set the name of the calling thread, the name can be up to 16 bytes + * long, including the terminating null byte. If exceeds 16 bytes, the + * string is silently truncated. + * 2)Return the name of the calling thread, the buffer should allow space + * for up to 16 bytes, the returned string will be null-terminated. + * 3)Check /proc/self/task/[tid]/comm and /proc/self/comm name whether + * matches the thread name. + */ + +#include <sys/prctl.h> +#include <string.h> +#include <stdio.h> +#include "lapi/syscalls.h" +#include "lapi/prctl.h" +#include "tst_test.h" + +static struct tcase { + char setname[20]; + char expname[20]; +} tcases[] = { + {"prctl05_test", "prctl05_test"}, + {"prctl05_test_xxxxx", "prctl05_test_xx"} +}; + +static void check_proc_comm(char *path, char *name) +{ + char comm_buf[20]; + + SAFE_FILE_SCANF(path, "%s", comm_buf); + if (strcmp(name, comm_buf)) + tst_res(TFAIL, + "%s has %s, expected %s", path, comm_buf, name); + else + tst_res(TPASS, "%s sets to %s", path, comm_buf); +} + +static void verify_prctl(unsigned int n) +{ + char buf[20]; + char comm_path[40]; + pid_t tid; + struct tcase *tc = &tcases[n]; + + TEST(prctl(PR_SET_NAME, tc->setname)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "prctl(PR_SET_NAME) failed"); + return; + } + tst_res(TPASS, "prctl(PR_SET_NAME, '%s') succeeded", tc->setname); + + TEST(prctl(PR_GET_NAME, buf)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "prctl(PR_GET_NAME) failed"); + return; + } + + if (strcmp(tc->expname, buf)) { + tst_res(TFAIL, + "prctl(PR_GET_NAME) failed, expected %s, got %s", tc->expname, buf); + return; + } + tst_res(TPASS, "prctl(PR_GET_NAME) succeeded, thread name is %s", buf); + + tid = tst_syscall(__NR_gettid); + + sprintf(comm_path, "/proc/self/task/%d/comm", tid); + check_proc_comm(comm_path, tc->expname); + + check_proc_comm("/proc/self/comm", tc->expname); +} + +static struct tst_test test = { + .test = verify_prctl, + .tcnt = ARRAY_SIZE(tcases), +}; -- 2.18.1 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH v4] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME 2019-05-27 8:19 ` [LTP] [PATCH v4] " Yang Xu @ 2019-05-27 13:41 ` Cyril Hrubis 0 siblings, 0 replies; 13+ messages in thread From: Cyril Hrubis @ 2019-05-27 13:41 UTC (permalink / raw) To: ltp Hi! Pushed with minor change, thanks. ... > + if (strcmp(tc->expname, buf)) { > + tst_res(TFAIL, > + "prctl(PR_GET_NAME) failed, expected %s, got %s", tc->expname, buf); > + return; > + } I've changed this strcmp() to strncmp() to avoid undefined behavior in unlikely case that kernel failed to terminated the buffer. -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2019-05-27 13:41 UTC | newest] Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-05-09 12:20 [LTP] [PATCH] syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME Yang Xu 2019-05-22 10:16 ` xuyang 2019-05-23 9:40 ` Cyril Hrubis 2019-05-23 11:35 ` [LTP] [PATCH v2] " Yang Xu 2019-05-23 11:51 ` Xiao Yang 2019-05-24 7:36 ` xuyang 2019-05-24 7:50 ` [LTP] [PATCH v3] " Yang Xu 2019-05-24 13:21 ` Cyril Hrubis 2019-05-24 13:45 ` Xiao Yang 2019-05-24 13:48 ` Cyril Hrubis 2019-05-24 13:58 ` Xiao Yang 2019-05-27 8:19 ` [LTP] [PATCH v4] " Yang Xu 2019-05-27 13:41 ` Cyril Hrubis
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.