syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
PATCH 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
--- 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
include/lapi/prctl.h +5 -0
@@ -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
runtest/syscalls +1 -0
@@ -864,6 +864,7 @@ prctl01 prctl01 prctl02 prctl02 prctl03 prctl03 prctl04 prctl04 +prctl05 prctl05 pread01 pread01 pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
@@ -2,3 +2,4 @@ /prctl02 /prctl03 /prctl04 +/prctl05
testcases/kernel/syscalls/prctl/prctl05.c new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.18.1
PATCH 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
Hi
Ping. :-)
Quoted 103 lines
Signed-off-by Yang Xu <[email protected]>--- 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.cinclude/lapi/prctl.h +5
-0@@ -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 37runtest/syscalls +1
-0@@ -864,6 +864,7 @@ prctl01 prctl01 prctl02 prctl02 prctl03 prctl03 prctl04 prctl04 +prctl05 prctl05 pread01 pread01 pread01_64 pread01_64testcases/kernel/syscalls/prctl/.gitignore +1
-0@@ -2,3 +2,4 @@ /prctl02 /prctl03 /prctl04 +/prctl05testcases/kernel/syscalls/prctl/prctl05.c new file +51
-0@@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +* Author: Yang Xu <[email protected]> +* +* 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, +};
PATCH 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
In reply to Yang XuHi!
testcases/kernel/syscalls/prctl/prctl05.c line 40
Quoted 7 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +7
-0+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().
testcases/kernel/syscalls/prctl/prctl05.c line 46
Quoted 6 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +6
-0+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?
testcases/kernel/syscalls/prctl/prctl05.c line 51
Quoted 5 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +5
-0+} + +static struct tst_test test = { + .test_all = verify_prctl, +};
Other than that it looks good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
--- 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
include/lapi/prctl.h +5 -0
@@ -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
runtest/syscalls +1 -0
@@ -862,6 +862,7 @@ prctl01 prctl01 prctl02 prctl02 prctl03 prctl03 prctl04 prctl04 +prctl05 prctl05 pread01 pread01 pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
@@ -2,3 +2,4 @@ /prctl02 /prctl03 /prctl04 +/prctl05
testcases/kernel/syscalls/prctl/prctl05.c new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
2.18.1
PATCH v2 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
Quoted 66 lines · Yang Xu
Signed-off-by Yang Xu <[email protected]>--- 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.cinclude/lapi/prctl.h +5
-0@@ -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 22runtest/syscalls +1
-0@@ -862,6 +862,7 @@ prctl01 prctl01 prctl02 prctl02 prctl03 prctl03 prctl04 prctl04 +prctl05 prctl05 pread01 pread01 pread01_64 pread01_64testcases/kernel/syscalls/prctl/.gitignore +1
-0@@ -2,3 +2,4 @@ /prctl02 /prctl03 /prctl04 +/prctl05testcases/kernel/syscalls/prctl/prctl05.c new file +14
-0@@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +* Author: Yang Xu <[email protected]> +* +* 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. +*/ +
testcases/kernel/syscalls/prctl/prctl05.c line 24
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +10
-0+#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.
testcases/kernel/syscalls/prctl/prctl05.c line 33
Quoted 9 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +9
-0+ +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?
testcases/kernel/syscalls/prctl/prctl05.c line 39
Quoted 6 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +6
-0+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)?
testcases/kernel/syscalls/prctl/prctl05.c line 41
Quoted 2 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +2
-0+ +TEST (prctl (PR_GET_NAME , &buf));
&buf is the same as buf here so we can use buf directly.
testcases/kernel/syscalls/prctl/prctl05.c line 53
Quoted 12 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +12
-0+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
Quoted 18 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +18
-0+ + 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, +};
PATCH v2 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
Quoted 126 lines · Xiao Yang
Quoted 68 lines · Yang Xu
Signed-off-by Yang Xu <[email protected]>--- 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.cinclude/lapi/prctl.h +4
-0@@ -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 22runtest/syscalls +1
-0@@ -862,6 +862,7 @@ prctl01 prctl01 prctl02 prctl02 prctl03 prctl03 prctl04 prctl04 +prctl05 prctl05 pread01 pread01 pread01_64 pread01_64testcases/kernel/syscalls/prctl/.gitignore +1
-0@@ -2,3 +2,4 @@ /prctl02 /prctl03 /prctl04 +/prctl05testcases/kernel/syscalls/prctl/prctl05.c new file +8
-0@@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +* Author: Yang Xu <[email protected]> +* +* 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 thethread_name.
+ */testcases/kernel/syscalls/prctl/prctl05.c new file +1
-0+testcases/kernel/syscalls/prctl/prctl05.c line 24
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +10
-0+#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.
testcases/kernel/syscalls/prctl/prctl05.c line 33
Quoted 9 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +9
-0+ +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?
Quoted 7 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +6
-0+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)?testcases/kernel/syscalls/prctl/prctl05.c
Quoted 2 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +2
-0+ +TEST (prctl (PR_GET_NAME , &buf));&buf is the same as buf here so we can use buf directly.
Quoted 12 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +12
-0+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 16Quoted 1 line
byte long");
Quoted 2 lines
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
Quoted 27 lines
Best Regards,
Xiao YangQuoted 8 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +8
-0+ + 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",testcases/kernel/syscalls/prctl/prctl05.c line 71
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +10
-0+ 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, +};.
PATCH v3 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
In reply to Xiao Yang--- 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
include/lapi/prctl.h +5 -0
@@ -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
runtest/syscalls +1 -0
@@ -862,6 +862,7 @@ prctl01 prctl01 prctl02 prctl02 prctl03 prctl03 prctl04 prctl04 +prctl05 prctl05 pread01 pread01 pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
@@ -2,3 +2,4 @@ /prctl02 /prctl03 /prctl04 +/prctl05
testcases/kernel/syscalls/prctl/prctl05.c new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
2.18.1
PATCH v3 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
Hi!
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +10
-0+#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];
testcases/kernel/syscalls/prctl/prctl05.c line 34
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +10
-0+} 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.
testcases/kernel/syscalls/prctl/prctl05.c line 44
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +10
-0+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);
testcases/kernel/syscalls/prctl/prctl05.c line 50
Quoted 5 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +5
-0+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;
testcases/kernel/syscalls/prctl/prctl05.c line 54
Quoted 3 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +3
-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.
testcases/kernel/syscalls/prctl/prctl05.c line 65
Quoted 11 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +11
-0+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);
testcases/kernel/syscalls/prctl/prctl05.c line 68
Quoted 3 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +3
-0+ 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);
Quoted 13 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +8
-0+ PROC_NAME_PATH, comm_buf); + +} + +static struct tst_test test = { + .test = verify_prctl, + .tcnt =ARRAY_SIZE (tcases), +};Signature · 1 line
2.18.1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
In reply to Yang XuQuoted 99 lines · Yang Xu
Signed-off-by Yang Xu <[email protected]>--- 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.cinclude/lapi/prctl.h +5
-0@@ -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 22runtest/syscalls +1
-0@@ -862,6 +862,7 @@ prctl01 prctl01 prctl02 prctl02 prctl03 prctl03 prctl04 prctl04 +prctl05 prctl05 pread01 pread01 pread01_64 pread01_64testcases/kernel/syscalls/prctl/.gitignore +1
-0@@ -2,3 +2,4 @@ /prctl02 /prctl03 /prctl04 +/prctl05testcases/kernel/syscalls/prctl/prctl05.c new file +47
-0@@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +* Author: Yang Xu <[email protected]> +* +* 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 ) {
testcases/kernel/syscalls/prctl/prctl05.c line 57
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +10
-0+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.
testcases/kernel/syscalls/prctl/prctl05.c line 62
Quoted 5 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +5
-0+ + 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
Quoted 14 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +14
-0+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), +};
PATCH v3 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
Hi!
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl05.c line 57
Quoted 6 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +6
-0+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.
Quoted 11 lines
testcases/kernel/syscalls/prctl/prctl05.c line 62
Quoted 5 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +5
-0+ + 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.
Quoted 3 lines
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.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
Quoted 21 lines · Cyril Hrubis
Hi!
Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl05.c line 57
Quoted 6 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +6
-0+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.Quoted 10 lines
testcases/kernel/syscalls/prctl/prctl05.c line 62
Quoted 5 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +5
-0+ + 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
Quoted 1 line
Actually we should check both.
Hi Cyril,
Thanks for your quick reply.
It's better to check both.
Quoted 4 lines
Quoted 3 lines
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
PATCH v4 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
--- 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
include/lapi/prctl.h +5 -0
@@ -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
runtest/syscalls +1 -0
@@ -862,6 +862,7 @@ prctl01 prctl01 prctl02 prctl02 prctl03 prctl03 prctl04 prctl04 +prctl05 prctl05 pread01 pread01 pread01_64 pread01_64
testcases/kernel/syscalls/prctl/.gitignore +1 -0
@@ -2,3 +2,4 @@ /prctl02 /prctl03 /prctl04 +/prctl05
testcases/kernel/syscalls/prctl/prctl05.c new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
2.18.1
PATCH v4 1/1 syscalls/prctl05.c: New test for prctl() with PR_{SET, GET}_NAME
Hi!
Pushed with minor change, thanks.
...
testcases/kernel/syscalls/prctl/prctl05.c line 67
Quoted 5 lines
testcases/kernel/syscalls/prctl/prctl05.c new file +5
-0+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.
Signature · 2 lines
Cyril Hrubis [email protected]