lib: Add SAFE_SETGROUPS() and SAFE_GETGROUPS() function to LTP library
A message that is not in the archive (sent off-list or not yet received): YNM4rlDJLzb4xk6v@yuki
PATCH v3 1/3 lib: Add SAFE_SETGROUPS() and SAFE_GETGROUPS() function to LTP library
--- include/tst_safe_macros.h | 10 ++++++++++ lib/tst_safe_macros.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+)
include/tst_safe_macros.h +10 -0
@@ -136,6 +136,16 @@ pid_t safe_getpgid(const char *file, const int lineno, pid_t pid);#define SAFE_GETPGID (pid) \ safe_getpgid(__FILE__, __LINE__, (pid)) +int safe_setgroups (const char *file,const int lineno,size_t size,const gid_t *list); + +#define SAFE_SETGROUPS (size, list) \ + safe_setgroups(__FILE__, __LINE__, (size), (list)) + +int safe_getgroups (const char *file,const int lineno,int size,gid_t list[]); + +#define SAFE_GETGROUPS (size, list) \ + safe_getgroups(__FILE__, __LINE__, (size), (list)) +#define SAFE_UNLINK (pathname) \ safe_unlink(__FILE__, __LINE__, NULL, (pathname))
lib/tst_safe_macros.c +36 -0
@@ -54,6 +54,42 @@ pid_t safe_getpgid(const char *file, const int lineno, pid_t pid)return pgid; } +int safe_setgroups (const char *file,const int lineno,size_t size,const gid_t *list) +{ +int rval; + + rval =setgroups (size, list); + +if (rval ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"setgroups(%zu, %p) failed" , size, list); + }else if (rval) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"Invalid setgroups(%zu, %p) return value %d" , size, + list, rval); + } + +return rval; +} + +int safe_getgroups (const char *file,const int lineno,int size,gid_t list[]) +{ +int rval; + + rval =getgroups (size, list); + +if (rval ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"getgroups(%i, %p)" , size, list); + }else if (rval <0 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"Invalid getgroups(%i, %p) return value %d" , size, + list, rval); + } + +return rval; +} +int safe_personality (const char *filename,unsigned int lineno,unsigned long persona) {
Signature · 1 line
2.23.0
PATCH v3 2/3 include/tst_test_macro.h: Add TST_EXP_FAIL2 macros
--- doc/c-test-api.txt | 11 +++++++++++ include/tst_test_macros.h | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-)
doc/c-test-api.txt +11 -0
@@ -281,6 +281,17 @@ The 'TST_EXP_FAIL()' is similar to 'TST_EXP_PASS()' but it fails the test if the call haven't failed with -1 and 'errno' wasn't set to the expected one passed as the second argument. +[source,c] +------------------------------------------------------------------------------- +static void test(void) +{ + ... + TST_EXP_FAIL2(msgget(key, flags), EINVAL, "msgget(%i, %i)", key, flags); + ... +} +The 'TST_EXP_FAIL2()' is the same as 'TST_EXP_FAIL' the only difference is that +the return value is a non-negative integer if call passes. + [source,c] ------------------------------------------------------------------------------- const char *tst_strsig(int sig);
include/tst_test_macros.h +6 -2
@@ -120,13 +120,13 @@ extern void *TST_RET_PTR; TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__); \ } while (0) \ -#define TST_EXP_FAIL (SCALL ,ERRNO , ...) \ +#define TST_EXP_FAIL_ (PASS_COND ,SCALL ,ERRNO , ...) \ do { \ TEST(SCALL); \ \ TST_PASS = 0; \ \ - if (TST_RET == 0) { \ + if (PASS_COND) { \ TST_MSG_(TFAIL, " succeeded", #SCALL, ##__VA_ARGS__); \ break; \ } \
@@ -150,4 +150,8 @@ extern void *TST_RET_PTR; } \ } while (0) +#define TST_EXP_FAIL (SCALL ,ERRNO , ...) TST_EXP_FAIL_(TST_RET == 0, SCALL, ERRNO, __VA_ARGS__) + +#define TST_EXP_FAIL2 (SCALL ,ERRNO , ...) TST_EXP_FAIL_(TST_RET >= 0, SCALL, ERRNO, __VA_ARGS__) +#endif /* TST_TEST_MACROS_H__ */
Signature · 1 line
2.23.0
PATCH v3 2/3 include/tst_test_macro.h: Add TST_EXP_FAIL2 macros
Hi!
doc/c-test-api.txt The 'TST_EXP_FAIL()' is similar to 'TST_EXP_PASS()' but it fails the test if · line 294
Quoted 11 lines
+[source,c]
+-------------------------------------------------------------------------------doc/c-test-api.txt +9
-0+static void test(void) +{ + ... + TST_EXP_FAIL2(msgget(key, flags), EINVAL, "msgget(%i, %i)", key, flags); + ... +} +The 'TST_EXP_FAIL2()' is the same as 'TST_EXP_FAIL' the only difference is that +the return value is a non-negative integer if call passes. +
I've fixed this part, it was missing the end of the code block (the ---- at the end) and reworded the description a bit and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 3/3 syscalls/shmget*: Convert into new api
In reply to Yang Xu1) merge shmget05.c into shmget02.c
2) Use SHMMIN -1 and SHMMAX + 1 to trigger EINVAL error
3) Use SHM_RD, SHM_WR, SHM_RW to trigger EACCES error under unpriviledged user
4) add EPERM error test
5) add ENOMEM error test
6) Use TST_EXP_FAIL2 macro
--- include/lapi/shm.h | 14 + runtest/syscalls | 1 - runtest/syscalls-ipc | 1 - .../kernel/syscalls/ipc/shmget/.gitignore | 1 - testcases/kernel/syscalls/ipc/shmget/Makefile | 4 +- .../kernel/syscalls/ipc/shmget/shmget02.c | 248 +++++++----------- .../kernel/syscalls/ipc/shmget/shmget03.c | 202 ++++---------- .../kernel/syscalls/ipc/shmget/shmget04.c | 188 ++++--------- .../kernel/syscalls/ipc/shmget/shmget05.c | 185 ------------- 9 files changed, 210 insertions(+), 634 deletions(-) delete mode 100644 testcases/kernel/syscalls/ipc/shmget/shmget05.c
include/lapi/shm.h +14 -0
@@ -6,8 +6,22 @@#ifndef LAPI_SHM_H__ #define LAPI_SHM_H__ +#include <limits.h> +#ifndef SHM_STAT_ANY # define SHM_STAT_ANY 15#endif +#ifndef SHMMIN +# define SHMMIN 1 +#endif + +#ifndef SHMMAX +# define SHMMAX (ULONG_MAX - (1UL << 24)) +#endif + +#ifndef SHMMNI +# define SHMMNI 4096 +#endif +#endif /* LAPI_SHM_H__ */
runtest/syscalls +0 -1
@@ -1409,7 +1409,6 @@ shmdt02 shmdt02 shmget02 shmget02 shmget03 shmget03 shmget04 shmget04 -shmget05 shmget05 sigaction01 sigaction01 sigaction02 sigaction02
runtest/syscalls-ipc +0 -1
@@ -67,4 +67,3 @@ shmdt02 shmdt02 shmget02 shmget02 shmget03 shmget03 shmget04 shmget04 -shmget05 shmget05
testcases/kernel/syscalls/ipc/shmget/.gitignore +0 -1
@@ -1,4 +1,3 @@ /shmget02 /shmget03 /shmget04 -/shmget05
testcases/kernel/syscalls/ipc/shmget/Makefile +2 -2
@@ -3,10 +3,10 @@ top_srcdir ?= ../../../../.. -LTPLIBS = ltpipc +LTPLIBS = ltpnewipc include $(top_srcdir)/include/mk/testcases.mk -LTPLDLIBS = -lltpipc +LTPLDLIBS = -lltpnewipc include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/ipc/shmget/shmget02.c +88 -160
272 lines not on this page · raw message
testcases/kernel/syscalls/ipc/shmget/shmget03.c +53 -149
224 lines not on this page · raw message
testcases/kernel/syscalls/ipc/shmget/shmget04.c +53 -135
206 lines not on this page · raw message
testcases/kernel/syscalls/ipc/shmget/shmget05.c deleted +0 -185
185 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH v3 3/3 syscalls/shmget*: Convert into new api
Hi!
Pushed with a minor changes, thanks.
testcases/kernel/syscalls/ipc/shmget/shmget03.c +2 -5
@@ -41,7 +41,6 @@ static void setup(void) queues =SAFE_MALLOC (maxshms *sizeof (int ));for (num =0 ; num < maxshms; num++) { - queues[num] =-1 ; res =shmget (shmkey + num,SHM_SIZE ,IPC_CREAT |IPC_EXCL |SHM_RW );if (res ==-1 )tst_brk (TBROK |TERRNO ,"shmget failed unexpectedly" );
@@ -59,10 +58,8 @@ static void cleanup(void)if (!queues)return ; -for (num =0 ; num < queue_cnt; num++) { -if (queues[num] !=-1 ) -SAFE_SHMCTL (queues[num],IPC_RMID ,NULL ); - } +for (num =0 ; num < queue_cnt; num++) +SAFE_SHMCTL (queues[num],IPC_RMID ,NULL );free (queues); }
As there is no need to check for -1 and pre-initialize the array anymore.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 3/3 syscalls/shmget*: Convert into new api
Quoted 3 lines · Cyril Hrubis
Hi!
Pushed with a minor changes, thanks.
It looks like this commit not only converted into new API but also changed the test. We started noticing shmget02 and shmget03 test failures on several systems.
https://bugs.launchpad.net/ubuntu-kernel-tests/+bug/1934432
Reverting the commit helps and tests pass.
Since it is one big patch doing multiple things at the same time, it is difficult to bisect it more and find the cause. Any ideas what went different here comparing to previous version of these tests?
Best regards,
Krzysztof
PATCH v3 3/3 syscalls/shmget*: Convert into new api
Quoted 9 lines · Krzysztof Kozlowski
Quoted 3 lines · Cyril Hrubis
Hi!
Pushed with a minor changes, thanks.It looks like this commit not only converted into new API but also changed the test. We started noticing shmget02 and shmget03 test failures on several systems.
Quoted 8 lines
https://bugs.launchpad.net/ubuntu-kernel-tests/+bug/1934432
Reverting the commit helps and tests pass.
Since it is one big patch doing multiple things at the same time, it is difficult to bisect it more and find the cause. Any ideas what went different here comparing to previous version of these tests?
New tests were added, like testing for EPERM when using SHM_HUGETLB. However, it does not fail with EPERM with there is sufficient RLIMIT_MEMLOCK. I have just sent a fix for that.
Cascardo.
Quoted 6 lines
Best regards,
KrzysztofSignature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 3/3 syscalls/shmget*: Convert into new api
In reply to Yang XuHi!
Quoted 4 lines
testcases/kernel/syscalls/ipc/shmget/shmget02.c +0
-0
...
testcases/kernel/syscalls/ipc/shmget/shmget02.c
Quoted 10 lines
testcases/kernel/syscalls/ipc/shmget/shmget02.c +10
-0+static struct tst_test test = { + .needs_tmpdir =1 , + .needs_root =1 , + .forks_child =1 , + .setup = setup, + .cleanup = cleanup, + .test = do_test, + .tcnt =ARRAY_SIZE (tcases), + .request_hugepages =0 , +};
We got some test failures for the ENOMEM hugepage test and then I we realized that setting .request_hugepages = 0 is no-op since zero is the default value when it's not initialized and we ignore it the tst_test.c.
Thinking of possible solutions I guess that the easiest would be to add a special value that would tell the library to set the pool size to 0.
Something as:
include/tst_test.h +2 -0
@@ -125,6 +125,8 @@ struct tst_tag {extern unsigned int tst_variant; +#define TST_NO_HUGEPAGES ((unsigned long)-1) +struct tst_test {/* number of tests available in test() function */ unsigned int tcnt;
lib/tst_hugepage.c +7 -0
@@ -34,6 +34,11 @@ unsigned long tst_request_hugepages(unsigned long hpages)else tst_hugepages = hpages; +if (hpages ==TST_NO_HUGEPAGES ) { + hpages =0 ; + goto set_hugepages; + } +SAFE_FILE_PRINTF ("/proc/sys/vm/drop_caches" ,"3" ); max_hpages =SAFE_READ_MEMINFO ("MemFree:" ) /SAFE_READ_MEMINFO ("Hugepagesize:" );
@@ -47,6 +52,8 @@ unsigned long tst_request_hugepages(unsigned long hpages) goto out; } +set_hugepages: +tst_sys_conf_save ("?/proc/sys/vm/nr_hugepages" );SAFE_FILE_PRINTF (PATH_NR_HPAGES ,"%lu" , tst_hugepages);SAFE_FILE_SCANF (PATH_NR_HPAGES ,"%lu" , &val);
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 3/3 syscalls/shmget*: Convert into new api
Hi Cyril
Quoted 23 lines
Hi!
Quoted 4 lines
testcases/kernel/syscalls/ipc/shmget/shmget02.c +0
-0...
testcases/kernel/syscalls/ipc/shmget/shmget02.c
Quoted 10 lines
testcases/kernel/syscalls/ipc/shmget/shmget02.c +10
-0+static struct tst_test test = { + .needs_tmpdir =1 , + .needs_root =1 , + .forks_child =1 , + .setup = setup, + .cleanup = cleanup, + .test = do_test, + .tcnt =ARRAY_SIZE (tcases), + .request_hugepages =0 , +};We got some test failures for the ENOMEM hugepage test and then I we realized that setting .request_hugepages = 0 is no-op since zero is the default value when it's not initialized and we ignore it the
tst_test.c.
Quoted 2 lines
Thinking of possible solutions I guess that the easiest would be to add a special value that would tell the library to set the pool size to 0.
Yes
Quoted 21 lines
Something as:
include/tst_test.h +2
-0@@ -125,6 +125,8 @@ struct tst_tag {extern unsigned int tst_variant; +#define TST_NO_HUGEPAGES ((unsigned long)-1) +struct tst_test {/* number of tests available in test() function */ unsigned int tcnt;lib/tst_hugepage.c +0
-0
lib/tst_hugepage.c unsigned long tst_request_hugepages(unsigned long hpages) · line 41
Quoted 8 lines
lib/tst_hugepage.c +5
-0@@ -34,6 +34,11 @@ unsigned long tst_request_hugepages(unsigned long hpages)else tst_hugepages = hpages; +if (hpages ==TST_NO_HUGEPAGES ) { + hpages =0 ; + goto set_hugepages; + } +
It should use tst_hugepages because set_hugepages will set by this. I will send a patch to fix this.
I think the reason of introduced problem is that we don't add library test for 0 hugepage. Also will add it.
Quoted 13 lines
lib/tst_hugepage.c +2
-0SAFE_FILE_PRINTF ("/proc/sys/vm/drop_caches" ,"3" ); max_hpages =SAFE_READ_MEMINFO ("MemFree:" ) /SAFE_READ_MEMINFO ("Hugepagesize:" );@@ -47,6 +52,8 @@ unsigned long tst_request_hugepages(unsigned long hpages) goto out; } +set_hugepages: +tst_sys_conf_save ("?/proc/sys/vm/nr_hugepages" );SAFE_FILE_PRINTF (PATH_NR_HPAGES ,"%lu" , tst_hugepages);SAFE_FILE_SCANF (PATH_NR_HPAGES ,"%lu" ,&val);
PATCH v3 1/3 lib: Add SAFE_SETGROUPS() and SAFE_GETGROUPS() function to LTP library
In reply to Yang XuHi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]