shmget03: don't depend on existed shared resources
PATCH v2 1/2 shmget03: don't depend on existed shared resources
It's unlikely, but still possible that some of them could be created/released during the test as well, so the patch only checks errno.
---
v2: * Move the loop to the test run function and try to get
ENOSPC errno there.
* Rename queues* to segments*
.../kernel/syscalls/ipc/shmget/shmget03.c | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-)
testcases/kernel/syscalls/ipc/shmget/shmget03.c +22 -20
@@ -21,47 +21,49 @@#include "tst_safe_sysv_ipc.h" #include "libnewipc.h" -static int *queues; -static int maxshms, queue_cnt; +static int *segments; +static int maxshms, segments_cnt;static key_t shmkey;static void verify_shmget (void ) { -TST_EXP_FAIL2 (shmget (shmkey + maxshms,SHM_SIZE ,IPC_CREAT |IPC_EXCL |SHM_RW ),ENOSPC , -"shmget(%i, %i, %i)" , shmkey + maxshms,SHM_SIZE ,IPC_CREAT |IPC_EXCL |SHM_RW ); +int res =0 , num; + + errno =0 ; +for (num =0 ; num <= maxshms; ++num) { + res =shmget (shmkey + num,SHM_SIZE ,IPC_CREAT |IPC_EXCL |SHM_RW ); +if (res ==-1 ) +break ; + segments[segments_cnt++] = res; + } + +if (res !=-1 || errno !=ENOSPC ) +tst_brk (TFAIL |TERRNO ,"Failed to trigger ENOSPC error" ); + +tst_res (TPASS ,"Maximum number of segments reached (%d), used by test %d" , + maxshms, segments_cnt); }static void setup (void ) { -int res, num; - shmkey =GETIPCKEY ();SAFE_FILE_SCANF ("/proc/sys/kernel/shmmni" ,"%i" , &maxshms); - queues =SAFE_MALLOC (maxshms *sizeof (int )); -for (num =0 ; num < maxshms; num++) { - res =shmget (shmkey + num,SHM_SIZE ,IPC_CREAT |IPC_EXCL |SHM_RW ); -if (res ==-1 ) -tst_brk (TBROK |TERRNO ,"shmget failed unexpectedly" ); - - queues[queue_cnt++] = res; - } -tst_res (TINFO ,"The maximum number of memory segments (%d) has been reached" , - maxshms); + segments =SAFE_MALLOC ((maxshms +1 ) *sizeof (int )); }static void cleanup (void ) {int num; -if (!queues) +if (!segments)return ; -for (num =0 ; num < queue_cnt; num++) -SAFE_SHMCTL (queues[num],IPC_RMID ,NULL ); +for (num =0 ; num < segments_cnt; num++) +SAFE_SHMCTL (segments[num],IPC_RMID ,NULL ); -free (queues); +free (segments); }static struct tst_test test = {
Signature · 1 line
2.25.1
PATCH v2 2/2 msgget03: don't depend on existed shared resources
It's unlikely, but still possible that some of them could be created/released during the test as well, so the patch only checks errno.
---
v2: * Move the loop to the test run function and try to get
ENOSPC errno there.
.../kernel/syscalls/ipc/msgget/msgget03.c | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-)
testcases/kernel/syscalls/ipc/msgget/msgget03.c +16 -15
@@ -26,29 +26,30 @@ static key_t msgkey;static void verify_msgget (void ) { -TST_EXP_FAIL2 (msgget (msgkey + maxmsgs,IPC_CREAT |IPC_EXCL ),ENOSPC , -"msgget(%i, %i)" , msgkey + maxmsgs,IPC_CREAT |IPC_EXCL ); +int res =0 , num; + + errno =0 ; +for (num =0 ; num <= maxmsgs; ++num) { + res =msgget (msgkey + num,IPC_CREAT |IPC_EXCL ); +if (res ==-1 ) +break ; + queues[queue_cnt++] = res; + } + +if (res !=-1 || errno !=ENOSPC ) +tst_brk (TFAIL |TERRNO ,"Failed to trigger ENOSPC error" ); + +tst_res (TPASS ,"Maximum number of queues reached (%d), used by test %d" , + maxmsgs, queue_cnt); }static void setup (void ) { -int res, num; - msgkey =GETIPCKEY ();SAFE_FILE_SCANF ("/proc/sys/kernel/msgmni" ,"%i" , &maxmsgs); - queues =SAFE_MALLOC (maxmsgs *sizeof (int )); - -for (num =0 ; num < maxmsgs; num++) { - res =msgget (msgkey + num,IPC_CREAT |IPC_EXCL ); -if (res ==-1 ) -tst_brk (TBROK |TERRNO ,"msgget failed unexpectedly" ); - queues[queue_cnt++] = res; - } - -tst_res (TINFO ,"The maximum number of message queues (%d) reached" , - maxmsgs); + queues =SAFE_MALLOC ((maxmsgs +1 ) *sizeof (int )); }static void cleanup (void )
Signature · 1 line
2.25.1
PATCH v2 2/2 msgget03: don't depend on existed shared resources
Hi Alexey, Li,
Quoted 17 lines
It's unlikely, but still possible that some of them could be created/released during the test as well, so the patch only checks errno.
Signed-off-by Alexey Kodanev <[email protected]>---
v2: * Move the loop to the test run function and try to get
ENOSPC errno there..../kernel/syscalls/ipc/msgget/msgget03.c | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-)testcases/kernel/syscalls/ipc/msgget/msgget03.c +0
-0
testcases/kernel/syscalls/ipc/msgget/msgget03.c static key_t msgkey; · line 32
Quoted 9 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +4
-2@@ -26,29 +26,30 @@ static key_t msgkey;static void verify_msgget (void ) { -TST_EXP_FAIL2 (msgget (msgkey + maxmsgs,IPC_CREAT |IPC_EXCL ),ENOSPC , -"msgget(%i, %i)" , msgkey + maxmsgs,IPC_CREAT |IPC_EXCL ); +int res =0 , num; + + errno =0 ; +for (num =0 ; num <= maxmsgs; ++num) {
In different patch [1] (I forget you already send patches to fix this) I counted items in /proc/sysvipc/shm. Not sure what is safer: <= looks a bit drastic (how about bug which reports ENOSPC much earlier than it should be?), but obviously new mapping from other program created in the middle of testing.
Kind regards,
Petr
[1] https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
Quoted 12 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +11
-0+ res =msgget (msgkey + num,IPC_CREAT |IPC_EXCL ); +if (res ==-1 ) +break ; + queues[queue_cnt++] = res; + } + +if (res !=-1 || errno !=ENOSPC ) +tst_brk (TFAIL |TERRNO ,"Failed to trigger ENOSPC error" ); + +tst_res (TPASS ,"Maximum number of queues reached (%d), used by test %d" , + maxmsgs, queue_cnt); }
...
PATCH v2 2/2 msgget03: don't depend on existed shared resources
Hi!
Quoted 4 lines
In different patch [1] (I forget you already send patches to fix this) I counted items in
/proc/sysvipc/shm. Not sure what is safer: <= looks a bit drastic (how about bug which reports ENOSPC much earlier than it should be?), but obviously new mapping from other program created in the middle of testing.
I think that we allready discussed this in another thread:
https://lists.linux.it/pipermail/ltp/2021-July/023831.html
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/2 msgget03: don't depend on existed shared resources
Quoted 9 lines
Hi!
Quoted 4 lines
In different patch [1] (I forget you already send patches to fix this) I counted items in
/proc/sysvipc/shm. Not sure what is safer: <= looks a bit drastic (how about bug which reports ENOSPC much earlier than it should be?), but obviously new mapping from other program created in the middle of testing.I think that we allready discussed this in another thread:
Thanks, I forgot this. In that case my approach (not using <=, but count segments in /proc/sysvipc/shm before testing) might be more precise. But no strong feeling about that, both solutions fix the test, let's chose one and merge.
Kind regards,
Petr
PATCH v2 2/2 msgget03: don't depend on existed shared resources
Hi!
Quoted 8 lines
Quoted 3 lines
I think that we allready discussed this in another thread:
Thanks, I forgot this. In that case my approach (not using <=, but count segments in
/proc/sysvipc/shmbefore testing) might be more precise. But no strong feeling about that, both solutions fix the test, let's chose one and merge.
As I said previously, there are many SysV IPC tests that do expect that nobody will add/remove IPC shm/queue/semaphores during the testrun and some of the testcases cannot even be implemented without this expectation.
Hence I wouldn't complicate the test here and just count how many segments are there at the start and be done with it.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/2 msgget03: don't depend on existed shared resources
Hi Cyril, Petr
Quoted 10 lines
Hi!
Quoted 8 lines
Quoted 3 lines
I think that we allready discussed this in another thread:
Thanks, I forgot this. In that case my approach (not using<=, but count segments in
/proc/sysvipc/shmbefore testing) might be more precise. But no strong feeling about that, both solutions fix the test, let's chose one and merge.
Quoted 7 lines
As I said previously, there are many SysV IPC tests that do expect that nobody will add/remove IPC shm/queue/semaphores during the testrun and some of the testcases cannot even be implemented without this expectation.
Hence I wouldn't complicate the test here and just count how many segments are there at the start and be done with it.
Agree.
A possible solution(alter get_used_queues api in new ipc lib and add file parametrers, so we can use this api for msgget03) I have mentioned in the previous email, the url as below:
https://lists.linux.it/pipermail/ltp/2021-July/023653.html
Quoted 1 line
PATCH v2 2/2 msgget03: don't depend on existed shared resources
Hi all,
Quoted 16 lines
Hi Cyril, Petr
Quoted 14 lines
Hi!
Quoted 8 lines
Quoted 3 lines
I think that we allready discussed this in another thread:
Thanks, I forgot this. In that case my approach (not using<=, but count segments in
/proc/sysvipc/shmbefore testing) might be more precise. But no strong feeling about that, both solutions fix the test, let's chose one and merge.As I said previously, there are many SysV IPC tests that do expect that nobody will add/remove IPC shm/queue/semaphores during the testrun and some of the testcases cannot even be implemented without this expectation.
Quoted 8 lines
Quoted 2 lines
Hence I wouldn't complicate the test here and just count how many segments are there at the start and be done with it.
Agree.
A possible solution(alter
get_used_queuesapi in new ipc lib and add file parametrers, so we can use this api for msgget03) I have mentioned in the previous email, the url as below:
https://lists.linux.it/pipermail/ltp/2021-July/023653.html
LGTM. Or use /proc/sysvipc/shm instead of /proc/sysvipc/msg in get_used_queues() as you noted get_used_queues() has not been used yet.
BTW searching where get_used_queues() appeared, I see [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API [1], but if I'm not mistaken get_used_queues() was not used even there, maybe it was in some previous versions.
Kind regards,
Petr
[1] https://lists.linux.it/pipermail/ltp/2016-December/003239.html
PATCH v2 2/2 msgget03: don't depend on existed shared resources
Hi Petr
Quoted 20 lines
Hi all,
Quoted 18 lines
Hi Cyril, Petr
Quoted 17 lines
Hi!
Quoted 8 lines
Quoted 3 lines
I think that we allready discussed this in another thread:
Thanks, I forgot this. In that case my approach (not using<=, but count segments in
/proc/sysvipc/shmbefore testing) might be more precise. But no strong feeling about that, both solutions fix the test, let's chose one and merge.As I said previously, there are many SysV IPC tests that do expect that nobody will add/remove IPC shm/queue/semaphores during the testrun and some of the testcases cannot even be implemented without this expectation.
Hence I wouldn't complicate the test here and just count how many segments are there at the start and be done with it.
Quoted 8 lines
Quoted 6 lines
Agree.
A possible solution(alter
get_used_queuesapi in new ipc lib and add file parametrers, so we can use this api for msgget03) I have mentioned in the previous email, the url as below:
https://lists.linux.it/pipermail/ltp/2021-July/023653.htmlLGTM. Or use
/proc/sysvipc/shminstead of/proc/sysvipc/msginget_used_queues()as you notedget_used_queues()has not been used yet.
I rename get_used_queues to get_used_sysvipc_cnt. see attached patch.
Quoted 5 lines
BTW searching where
get_used_queues()appeared, I see [LTP] [PATCH v3 1/4] syscalls/ipc: add newipc library for new API [1], but if I'm not mistakenget_used_queues()was not used even there, maybe it was in some previous versions.
Yes, no new api case use GET_USED_QUEUES api.
Quoted 5 lines
Kind regards,
Petr[1] https://lists.linux.it/pipermail/ltp/2016-December/003239.html
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0001-libs-libnewipc-Rename-get_used_queues-as-get_used_sy.patch
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210727/401bfffc/attachment.ksh>
PATCH v2 2/2 msgget03: don't depend on existed shared resources
Hi Cyril, Petr
Quoted 25 lines
Hi Petr
Quoted 24 lines
Hi all,
Quoted 21 lines
Hi Cyril, Petr
Quoted 12 lines
Hi!
Quoted 10 lines
Quoted 3 lines
I think that we allready discussed this in another thread:
Thanks, I forgot this. In that case my approach (not using<=, but count
segments in/proc/sysvipc/shmbefore testing) might be more precise. But no strong feeling about that, both solutions fix the test, let's chose one
and merge.Quoted 7 lines
As I said previously, there are many SysV IPC tests that do expect that nobody will add/remove IPC shm/queue/semaphores during the testrun and some of the testcases cannot even be implemented without this expectation.
Hence I wouldn't complicate the test here and just count how many segments are there at the start and be done with it.
Agree.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
A possible solution(alter
get_used_queuesapi in new ipc lib and add file parametrers, so we can use this api for msgget03) I have mentioned in the previous email, the url as below:
https://lists.linux.it/pipermail/ltp/2021-July/023653.htmlLGTM. Or use
/proc/sysvipc/shminstead of/proc/sysvipc/msginget_used_queues()
as you notedget_used_queues()has not been used yet.I rename
get_used_queuestoget_used_sysvipc_cnt. see attached patch.
Any idea about the attached patch(it was in previous eamil)?
ps:more and more people sent patch to fix this problme, I don't want to see many patches for this problem. Let's choose a solution to fix this problem.
Best Regards
Yang Xu
Quoted 13 lines
Quoted 6 lines
BTW searching where
get_used_queues()appeared, I see [LTP] [PATCH v3 1/4]
syscalls/ipc: add newipc library for new API [1], but if I'm not mistakenget_used_queues()was not used even there, maybe it was in some previous versions.Yes, no new api case use
GET_USED_QUEUESapi.Quoted 5 lines
Kind regards,
Petr[1] https://lists.linux.it/pipermail/ltp/2016-December/003239.html
PATCH v2 2/2 msgget03: don't depend on existed shared resources
In reply to [email protected]Hi!
Quoted 29 lines
From
2772f8f0bbc1526389cb2090895dded41e2c43dcMon Sep 17 00:00:00 2001
From: Yang Xu <[email protected]>
Date: Tue, 27 Jul 2021 16:22:42 +0800
Subject: [PATCH] libs/libnewipc:Renameget_used_queuesasget_used_sysvipc_cntRename
get_used_queuesasget_used_sysvipc_cnt, so we can useGET_USED_QUEQUES()andGET_USED_SEGMENTS()to get the corresponding used sysvipc resource total.Then we can use them in shmget03/msgget03, so we can trigger the ENOSPC error correctly even current environment has consume some sysvipc resource.
I don't use this api in verify function since we don't support run cases in parallel and we should assume this situation that this case is the only case to use(free or alloc) sysv ipc resource at that time.
Fixes #842Signed-off-by Yang Xu <[email protected]>--- include/libnewipc.h | 6 ++++-- libs/libltpnewipc/libnewipc.c | 16 ++++++++-------- testcases/kernel/syscalls/ipc/msgget/msgget03.c | 10 +++++++--- testcases/kernel/syscalls/ipc/shmget/shmget03.c | 10 ++++++---- 4 files changed, 25 insertions(+), 17 deletions(-)include/libnewipc.h +0
-0
include/libnewipc.h key_t getipckey(const char *file, const int lineno); · line 56
Quoted 10 lines
include/libnewipc.h +4
-2@@ -49,9 +49,11 @@ key_t getipckey(const char *file, const int lineno);#define GETIPCKEY () \ getipckey(__FILE__, __LINE__) -int get_used_queues (const char *file,const int lineno); +int get_used_sysvipc_cnt (const char *file,const int lineno,const char *sysvipc_file);#define GET_USED_QUEUES () \ - get_used_queues(__FILE__, __LINE__) + get_used_sysvipc_cnt(__FILE__, __LINE__, "/proc/sysvipc/msg") +#define GET_USED_SEGMENTS () \ + get_used_sysvipc_cnt(__FILE__, __LINE__, "/proc/sysvipc/shm")
I would just call it get_used_sysvipc()
Quoted 7 lines
include/libnewipc.h +0
-0void *probe_free_addr (const char *file,const int lineno);#define PROBE_FREE_ADDR () \libs/libltpnewipc/libnewipc.c +0
-0
libs/libltpnewipc/libnewipc.c key_t getipckey(const char *file, const int lineno) · line 54
Quoted 9 lines
libs/libltpnewipc/libnewipc.c +2
-2@@ -48,25 +48,25 @@ key_t getipckey(const char *file, const int lineno)return key; } -int get_used_queues (const char *file,const int lineno) +int get_used_sysvipc_cnt (const char *file,const int lineno,const char *sysvipc_file) {FILE *fp; -int used_queues =-1 ; +int used_cnt =-1 ;
And here as well the _cnt is not adding any value over I would say.
Quoted 29 lines
libs/libltpnewipc/libnewipc.c +6
-6char buf[BUFSIZE ]; - fp =safe_fopen (file, lineno,NULL ,"/proc/sysvipc/msg" ,"r" ); + fp =safe_fopen (file, lineno,NULL , sysvipc_file,"r" );while (fgets (buf,BUFSIZE , fp) !=NULL ) - used_queues++; + used_cnt++;fclose (fp); -if (used_queues <0 ) { -tst_brk (TBROK ,"can't read /proc/sysvipc/msg to get " -"used message queues at %s:%d" , file, lineno); +if (used_cnt <0 ) { +tst_brk (TBROK ,"can't read %s to get used message queues " +"at %s:%d" , sysvipc_file, file, lineno); } -return used_queues; +return used_cnt; }void *probe_free_addr (const char *file,const int lineno)testcases/kernel/syscalls/ipc/msgget/msgget03.c +0
-0
testcases/kernel/syscalls/ipc/msgget/msgget03.c line 24
Quoted 5 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +1
-1@@ -21,7 +21,7 @@#include "tst_safe_sysv_ipc.h" #include "libnewipc.h" -static int maxmsgs, queue_cnt; +static int maxmsgs, queue_cnt, existed_cnt;
^
Why not 'used_cnt' ?
Quoted 26 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +6
-2static int *queues;static key_t msgkey;@@ -37,11 +37,15 @@ static void setup(void) msgkey =GETIPCKEY (); + existed_cnt =GET_USED_QUEUES (); +tst_res (TINFO ,"Current environment %d message queues are already in use" , + existed_cnt); +SAFE_FILE_SCANF ("/proc/sys/kernel/msgmni" ,"%i" , &maxmsgs); - queues =SAFE_MALLOC (maxmsgs *sizeof (int )); + queues =SAFE_MALLOC ((maxmsgs - existed_cnt) *sizeof (int )); -for (num =0 ; num < maxmsgs; num++) { +for (num =0 ; num < maxmsgs - existed_cnt; num++) { res =msgget (msgkey + num,IPC_CREAT |IPC_EXCL );if (res ==-1 )tst_brk (TBROK |TERRNO ,"msgget failed unexpectedly" );testcases/kernel/syscalls/ipc/shmget/shmget03.c +0
-0
testcases/kernel/syscalls/ipc/shmget/shmget03.c line 25
Quoted 5 lines
testcases/kernel/syscalls/ipc/shmget/shmget03.c +1
-1@@ -22,7 +22,7 @@#include "libnewipc.h" static int *queues; -static int maxshms, queue_cnt; +static int maxshms, queue_cnt, existed_cnt;
^
Here as well.
Quoted 10 lines
testcases/kernel/syscalls/ipc/shmget/shmget03.c +2
-1static key_t shmkey;static void verify_shmget (void )@@ -36,11 +36,13 @@ static void setup(void)int res, num; shmkey =GETIPCKEY (); - + existed_cnt =GET_USED_SEGMENTS (); + tst_res(TINFO, "Current environment %d shared memory segments are already in use",
testcases/kernel/syscalls/ipc/shmget/shmget03.c static void setup(void) · line 48
Quoted 10 lines
testcases/kernel/syscalls/ipc/shmget/shmget03.c +3
-2+ existed_cnt);SAFE_FILE_SCANF ("/proc/sys/kernel/shmmni" ,"%i" , &maxshms); - queues =SAFE_MALLOC (maxshms *sizeof (int )); -for (num =0 ; num < maxshms; num++) { + queues =SAFE_MALLOC ((maxshms - existed_cnt) *sizeof (int )); +for (num =0 ; num < maxshms - existed_cnt; num++) { res =shmget (shmkey + num,SHM_SIZE ,IPC_CREAT |IPC_EXCL |SHM_RW );if (res ==-1 )tst_brk (TBROK |TERRNO ,"shmget failed unexpectedly" );
Other than the very minor differencies I would do in naming the variables and function this looks good to me.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/2 msgget03: don't depend on existed shared resources
Hi Xu, Cyril,
Quoted 2 lines
Other than the very minor differencies I would do in naming the variables and function this looks good to me.
Agree with all Cyril's suggestions for rename.
I suppose you just merge it fixed version, right?
Because now we discuss under Alexey's "[v2,2/2] msgget03: don't depend on existed shared resources" patch.
Kind regards,
Petr
PATCH v2 2/2 msgget03: don't depend on existed shared resources
In reply to Cyril HrubisHi Cyril, Petr
Quoted 33 lines
Hi!
Quoted 32 lines
From
2772f8f0bbc1526389cb2090895dded41e2c43dcMon Sep 17 00:00:00 2001
From: Yang Xu<[email protected]>
Date: Tue, 27 Jul 2021 16:22:42 +0800
Subject: [PATCH] libs/libnewipc:Renameget_used_queuesasget_used_sysvipc_cntRename
get_used_queuesasget_used_sysvipc_cnt, so we can useGET_USED_QUEQUES()andGET_USED_SEGMENTS()to get the corresponding used sysvipc resource total.Then we can use them in shmget03/msgget03, so we can trigger the ENOSPC error correctly even current environment has consume some sysvipc resource.
I don't use this api in verify function since we don't support run cases in parallel and we should assume this situation that this case is the only case to use(free or alloc) sysv ipc resource at that time.
Fixes #842Signed-off-by Yang Xu<[email protected]>--- include/libnewipc.h | 6 ++++-- libs/libltpnewipc/libnewipc.c | 16 ++++++++-------- testcases/kernel/syscalls/ipc/msgget/msgget03.c | 10 +++++++--- testcases/kernel/syscalls/ipc/shmget/shmget03.c | 10 ++++++---- 4 files changed, 25 insertions(+), 17 deletions(-)include/libnewipc.h +0
-0@@ -49,9 +49,11 @@ key_t getipckey(const char *file, const int lineno);#define GETIPCKEY () \ getipckey(__FILE__, __LINE__)
Quoted 9 lines
include/libnewipc.h key_t getipckey(const char *file, const int lineno); · line 56
Quoted 7 lines
include/libnewipc.h +4
-2-int get_used_queues (const char *file,const int lineno); +int get_used_sysvipc_cnt (const char *file,const int lineno,const char *sysvipc_file);#define GET_USED_QUEUES () \ - get_used_queues(__FILE__, __LINE__) + get_used_sysvipc_cnt(__FILE__, __LINE__, "/proc/sysvipc/msg") +#define GET_USED_SEGMENTS () \ + get_used_sysvipc_cnt(__FILE__, __LINE__, "/proc/sysvipc/shm")I would just call it
get_used_sysvipc()
OK.
Quoted 11 lines
Quoted 11 lines
include/libnewipc.h +0
-0void *probe_free_addr (const char *file,const int lineno);#define PROBE_FREE_ADDR () \libs/libltpnewipc/libnewipc.c +0
-0@@ -48,25 +48,25 @@ key_t getipckey(const char *file, const int lineno)return key; }
Quoted 8 lines
libs/libltpnewipc/libnewipc.c key_t getipckey(const char *file, const int lineno) · line 54
Quoted 6 lines
libs/libltpnewipc/libnewipc.c +2
-2-int get_used_queues (const char *file,const int lineno) +int get_used_sysvipc_cnt (const char *file,const int lineno,const char *sysvipc_file) {FILE *fp; -int used_queues =-1 ; +int used_cnt =-1 ;And here as well the
_cntis not adding any value over I would say.
OK.
Quoted 12 lines
Quoted 12 lines
libs/libltpnewipc/libnewipc.c +2
-2char buf[BUFSIZE ]; - fp =safe_fopen (file, lineno,NULL ,"/proc/sysvipc/msg" ,"r" ); + fp =safe_fopen (file, lineno,NULL , sysvipc_file,"r" );while (fgets (buf,BUFSIZE , fp) !=NULL ) - used_queues++; + used_cnt++;fclose (fp);
Quoted 7 lines
libs/libltpnewipc/libnewipc.c key_t getipckey(const char *file, const int lineno) · line 67
Quoted 7 lines
libs/libltpnewipc/libnewipc.c +3
-3-if (used_queues<0 ) { -tst_brk (TBROK ,"can't read /proc/sysvipc/msg to get " -"used message queues at %s:%d" , file, lineno); +if (used_cnt<0 ) { +tst_brk (TBROK ,"can't read %s to get used message queues " +"at %s:%d" , sysvipc_file, file, lineno); }
I also modify this info.
message queues => sysvipc resource total
Quoted 14 lines
Quoted 14 lines
libs/libltpnewipc/libnewipc.c +1
-1-return used_queues; +return used_cnt; }void *probe_free_addr (const char *file,const int lineno)testcases/kernel/syscalls/ipc/msgget/msgget03.c +0
-0@@ -21,7 +21,7 @@#include "tst_safe_sysv_ipc.h" #include "libnewipc.h"
Quoted 4 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c line 24
Quoted 2 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +1
-1-static int maxmsgs, queue_cnt; +static int maxmsgs, queue_cnt, existed_cnt;^
Why not 'used_cnt' ?
Yes.
Quoted 28 lines
Quoted 28 lines
testcases/kernel/syscalls/ipc/msgget/msgget03.c +6
-2static int *queues;static key_t msgkey;@@ -37,11 +37,15 @@ static void setup(void) msgkey =GETIPCKEY (); + existed_cnt =GET_USED_QUEUES (); +tst_res (TINFO ,"Current environment %d message queues are already in use" , + existed_cnt); +SAFE_FILE_SCANF ("/proc/sys/kernel/msgmni" ,"%i" ,&maxmsgs); - queues =SAFE_MALLOC (maxmsgs *sizeof (int )); + queues =SAFE_MALLOC ((maxmsgs - existed_cnt) *sizeof (int )); -for (num =0 ; num< maxmsgs; num++) { +for (num =0 ; num< maxmsgs - existed_cnt; num++) { res =msgget (msgkey + num,IPC_CREAT |IPC_EXCL );if (res ==-1 )tst_brk (TBROK |TERRNO ,"msgget failed unexpectedly" );testcases/kernel/syscalls/ipc/shmget/shmget03.c +0
-0@@ -22,7 +22,7 @@#include "libnewipc.h"
Quoted 5 lines
testcases/kernel/syscalls/ipc/shmget/shmget03.c line 25
Quoted 3 lines
testcases/kernel/syscalls/ipc/shmget/shmget03.c +1
-1static int *queues; -static int maxshms, queue_cnt; +static int maxshms, queue_cnt, existed_cnt;^
Here as well.
OK.
Quoted 24 lines
Quoted 10 lines
testcases/kernel/syscalls/ipc/shmget/shmget03.c +2
-1static key_t shmkey;static void verify_shmget (void )@@ -36,11 +36,13 @@ static void setup(void)int res, num; shmkey =GETIPCKEY (); - + existed_cnt =GET_USED_SEGMENTS (); + tst_res(TINFO, "Current environment %d shared memory segments are already in use",testcases/kernel/syscalls/ipc/shmget/shmget03.c static void setup(void) · line 48
Quoted 10 lines
testcases/kernel/syscalls/ipc/shmget/shmget03.c +3
-2+ existed_cnt);SAFE_FILE_SCANF ("/proc/sys/kernel/shmmni" ,"%i" ,&maxshms); - queues =SAFE_MALLOC (maxshms *sizeof (int )); -for (num =0 ; num< maxshms; num++) { + queues =SAFE_MALLOC ((maxshms - existed_cnt) *sizeof (int )); +for (num =0 ; num< maxshms - existed_cnt; num++) { res =shmget (shmkey + num,SHM_SIZE ,IPC_CREAT |IPC_EXCL |SHM_RW );if (res ==-1 )tst_brk (TBROK |TERRNO ,"shmget failed unexpectedly" );Other than the very minor differencies I would do in naming the variables and function this looks good to me.
Quoted 1 line
Reviewed-by Cyril Hrubis<[email protected]>
Thanks for your review. I spilt this patch into a patchset because it is more friendly for user or tester.
Best Regards
Yang Xu
Quoted 2 lines
PATCH v2 2/2 msgget03: don't depend on existed shared resources
Hi Xu,
Quoted 9 lines
Quoted 7 lines
Review
Quoted 7 lines
(quoted diff) +3
-3- if (used_queues< 0) { - tst_brk(TBROK, "can't read /proc/sysvipc/msg to get " - "used message queues at %s:%d", file, lineno); + if (used_cnt< 0) { + tst_brk(TBROK, "can't read %s to get used message queues " + "at %s:%d", sysvipc_file, file, lineno); }I also modify this info.
message queues => sysvipc resource total
+1. nit: I'd also move "at" at the previous line (better for grep).
Kind regards,
Petr
PATCH v2 2/2 msgget03: don't depend on existed shared resources
Hi Petr
Quoted 11 lines
Hi Xu,
Quoted 9 lines
Quoted 7 lines
Review
Quoted 7 lines
(quoted diff) +3
-3- if (used_queues< 0) { - tst_brk(TBROK, "can't read /proc/sysvipc/msg to get " - "used message queues at %s:%d", file, lineno); + if (used_cnt< 0) { + tst_brk(TBROK, "can't read %s to get used message queues " + "at %s:%d", sysvipc_file, file, lineno); }I also modify this info.
message queues => sysvipc resource total
Quoted 1 line
+1. nit: I'd also move "at" at the previous line (better for grep).
Sounds reasonable. Thanks.
Best Regards
Yang Xu
Quoted 4 lines
Kind regards,
Petr
PATCH v2 2/2 msgget03: don't depend on existed shared resources
In reply to Cyril HrubisHi Cyril, all,
Quoted 10 lines
Hi!
Quoted 8 lines
Quoted 3 lines
I think that we allready discussed this in another thread:
Thanks, I forgot this. In that case my approach (not using <=, but count segments in
/proc/sysvipc/shmbefore testing) might be more precise. But no strong feeling about that, both solutions fix the test, let's chose one and merge.
Quoted 7 lines
As I said previously, there are many SysV IPC tests that do expect that nobody will add/remove IPC shm/queue/semaphores during the testrun and some of the testcases cannot even be implemented without this expectation.
Hence I wouldn't complicate the test here and just count how many segments are there at the start and be done with it.
Yes, that's what's done in "my approach" [1].
Kind regards,
Petr
[1] https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
PATCH v2 1/2 shmget03: don't depend on existed shared resources
In reply to Alexey KodanevQuoted 9 lines · Alexey Kodanev
It's unlikely, but still possible that some of them could be created/released during the test as well, so the patch only checks errno.
Signed-off-by Alexey Kodanev <[email protected]>---
v2: * Move the loop to the test run function and try to get
ENOSPC errno there.
I'm fine to go with this but move the loop to test run without any limit will bring new fail if running with parameter '-i 2'.
We have to handle that situation (maybe add a judgment to skip test for run more times) in case someone uses it like:
# ./shmget03 -i 2 tst_test.c:1344: TINFO: Timeout per run is 0h 05m 00s shmget03.c:44: TPASS: Maximum number of segments reached (4096), used by test 4096 shmget03.c:41: TFAIL: Failed to trigger ENOSPC error: EEXIST (17)
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20210712/20653694/attachment.htm>
PATCH v2 1/2 shmget03: don't depend on existed shared resources
Quoted 14 lines · Li Wang
On Mon, Jul 12, 2021 at 3:54 PM Alexey Kodanev <[email protected] <mailto:[email protected]>> wrote:
It's unlikely, but still possible that some of them could be created/released during the test as well, so the patch only checks errno.
Signed-off-by Alexey Kodanev <[email protected] <mailto:[email protected]>>---
v2: * Move the loop to the test run function and try to get ? ? ? ENOSPC errno there.
Quoted 5 lines
I'm fine to go with this but move?the loop to test run without any limit will bring new fail if running with parameter '-i 2'.
We have to handle that situation (maybe add a judgment to skip test for run?more times) in case someone uses it like:
Or just release them asap after tpass?
Quoted 9 lines
# ./shmget03 -i 2 tst_test.c:1344: TINFO: Timeout per run is 0h 05m 00s shmget03.c:44: TPASS: Maximum number of segments reached (4096), used by test 4096 shmget03.c:41: TFAIL: Failed to trigger ENOSPC error: EEXIST (17)Signature · 2 lines
Regards, Li Wang
PATCH v2 1/2 shmget03: don't depend on existed shared resources
Quoted 17 lines · Alexey Kodanev
Quoted 3 lines · Li Wang
On Mon, Jul 12, 2021 at 3:54 PM Alexey Kodanev <
Quoted 6 lines · [email protected] <mailto:[email protected]>> wrote:
It's unlikely, but still possible that some of them could be created/released during the test as well, so the patch only checks errno.
Signed-off-by Alexey Kodanev <[email protected] <mailto:Quoted 5 lines
---
v2: * Move the loop to the test run function and try to get
ENOSPC errno there.
Quoted 7 lines
Quoted 5 lines
I'm fine to go with this but move the loop to test run without any limit will bring new fail if running with parameter '-i 2'.
We have to handle that situation (maybe add a judgment to skip test for run more times) in case someone uses it like:
Or just release them asap after tpass?
Sure, but looks a bit redundant.
Or we can just adding a global varible for saving num:
testcases/kernel/syscalls/ipc/shmget/shmget03.c +2 -2
@@ -22,7 +22,7 @@#include "libnewipc.h" static int *segments; -static int maxshms, segments_cnt; +static int number =0 , maxshms, segments_cnt;static key_t shmkey;static void verify_shmget (void )
@@ -30,7 +30,7 @@ static void verify_shmget(void)int res =0 , num; errno =0 ; -for (num =0 ; num <= maxshms; ++num) { +for (num = number; num <= maxshms; ++num) { res = shmget(shmkey + num, SHM_SIZE, IPC_CREAT | IPC_EXCL |
SHM_RW);
if (res == -1)
break;@@ -42,6 +42,8 @@ static void verify_shmget(void)
tst_res(TPASS, "Maximum number of segments reached (%d), used by
test %d",
maxshms, segments_cnt);
+
+ number = num;
}
static void setup(void)
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20210712/22e4fe29/attachment.htm>
PATCH v2 1/2 shmget03: don't depend on existed shared resources
Quoted 47 lines · Li Wang
Quoted 17 lines · Alexey Kodanev
Quoted 3 lines · Li Wang
On Mon, Jul 12, 2021 at 3:54 PM Alexey Kodanev <
Quoted 6 lines · [email protected] <mailto:[email protected]>> wrote:
It's unlikely, but still possible that some of them could be created/released during the test as well, so the patch only checks errno.
Signed-off-by Alexey Kodanev <[email protected] <mailto:Quoted 5 lines
---
v2: * Move the loop to the test run function and try to get
ENOSPC errno there.Quoted 7 lines
Quoted 5 lines
I'm fine to go with this but move the loop to test run without any limit will bring new fail if running with parameter '-i 2'.
We have to handle that situation (maybe add a judgment to skip test for run more times) in case someone uses it like:
Or just release them asap after tpass?
Sure, but looks a bit redundant.
Or we can just adding a global varible for saving num:
testcases/kernel/syscalls/ipc/shmget/shmget03.c +1
-1@@ -22,7 +22,7 @@#include "libnewipc.h" static int *segments; -static int maxshms, segments_cnt; +static int number =0 , maxshms, segments_cnt;static key_t shmkey;static void verify_shmget (void )
testcases/kernel/syscalls/ipc/shmget/shmget03.c static void verify_shmget(void) · line 34
Quoted 6 lines
testcases/kernel/syscalls/ipc/shmget/shmget03.c +1
-1@@ -30,7 +30,7 @@ static void verify_shmget(void)int res =0 , num; errno =0 ; -for (num =0 ; num <= maxshms; ++num) { +for (num = number; num <= maxshms; ++num) {
Oh, this method is thoughtless, because if the test gets ENOSPC at the last looping time, which means num == maxshms, then the global number will be larger than maxshms, so the test won't fall into for() loop next time and report FAIL again.
So, let's go with your way: release them after TPASS. This is safer.
Quoted 20 lines
testcases/kernel/syscalls/ipc/shmget/shmget03.c +0
-0res =shmget (shmkey + num,SHM_SIZE ,IPC_CREAT |IPC_EXCL |SHM_RW );if (res == -1) break;testcases/kernel/syscalls/ipc/shmget/shmget03.c +2
-0@@ -42,6 +42,8 @@ static void verify_shmget(void) tst_res(TPASS, "Maximum number of segments reached (%d), used by test %d", maxshms, segments_cnt); + + number = num; }static void setup(void)
--
Regards,
Li Wang
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20210712/fa877490/attachment-0001.htm>