* [LTP] [PATCH] sched_getaffinity: fix possible fail in negative case
@ 2012-03-09 5:28 Caspar Zhang
2012-03-09 5:48 ` Caspar Zhang
2012-03-09 7:19 ` Garrett Cooper
0 siblings, 2 replies; 6+ messages in thread
From: Caspar Zhang @ 2012-03-09 5:28 UTC (permalink / raw)
To: LTP List
[-- Attachment #1: Type: text/plain, Size: 559 bytes --]
in negative case:
QUICK_TEST(sched_getaffinity(getpid()+1, len, mask));
sometimes getpid()+1 will exist if there're other processes running.
This patch uses a different way to make sure the required pid doesn't
exist by forking a child and terminating it. The pid of the terminated
child will not be used for a short time and it's enough for the test to
continue.
Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
---
.../sched_getaffinity/sched_getaffinity01.c | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-sched_getaffinity-fix-possible-fail-in-negative-case.patch --]
[-- Type: text/x-patch; name="0001-sched_getaffinity-fix-possible-fail-in-negative-case.patch", Size: 1125 bytes --]
diff --git a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
index 97cf90f..80dea9a 100644
--- a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
+++ b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c
@@ -94,7 +94,7 @@ int main(int ac, char **av)
static void do_test(void)
{
- int i;
+ int i, status;
cpu_set_t *mask;
int nrcpus = 1024;
pid_t pid;
@@ -153,10 +153,24 @@ realloc:
#else
CPU_ZERO(mask);
#endif
+
/* negative tests */
+
QUICK_TEST(sched_getaffinity(0, len, (cpu_set_t *)-1));
+
QUICK_TEST(sched_getaffinity(0, 0, mask));
- QUICK_TEST(sched_getaffinity(getpid() + 1, len, mask));
+
+ switch (pid = fork()) {
+ case -1:
+ tst_brkm(TBROK|TERRNO, cleanup, "fork");
+ case 0:
+ exit(0);
+ default:
+ if (waitpid(pid, &status, WUNTRACED|WCONTINUED) == -1)
+ tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
+ }
+ QUICK_TEST(sched_getaffinity(pid, len, mask));
+
/*
* pid_t -> int -- the actual kernel limit is lower
* though, but this is a negative test, not a positive
[-- Attachment #3: Type: text/plain, Size: 317 bytes --]
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
[-- Attachment #4: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [LTP] [PATCH] sched_getaffinity: fix possible fail in negative case
2012-03-09 5:28 [LTP] [PATCH] sched_getaffinity: fix possible fail in negative case Caspar Zhang
@ 2012-03-09 5:48 ` Caspar Zhang
2012-03-09 5:53 ` Wanlong Gao
2012-03-09 7:19 ` Garrett Cooper
1 sibling, 1 reply; 6+ messages in thread
From: Caspar Zhang @ 2012-03-09 5:48 UTC (permalink / raw)
To: Garrett Cooper; +Cc: LTP List
On 03/09/2012 01:28 PM, Caspar Zhang wrote:
>
> in negative case:
>
> QUICK_TEST(sched_getaffinity(getpid()+1, len, mask));
>
> sometimes getpid()+1 will exist if there're other processes running.
> This patch uses a different way to make sure the required pid doesn't
> exist by forking a child and terminating it. The pid of the terminated
> child will not be used for a short time and it's enough for the test to
> continue.
>
> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
> ---
> .../sched_getaffinity/sched_getaffinity01.c | 18 ++++++++++++++++--
> 1 files changed, 16 insertions(+), 2 deletions(-)
>
Hmmm, I took a look at commit c8319c8 and found that Garrett added a
similar non-exist-pid case already. I guess we can simply remove the one
I tried to fix...
Thanks,
Caspar
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] sched_getaffinity: fix possible fail in negative case
2012-03-09 5:48 ` Caspar Zhang
@ 2012-03-09 5:53 ` Wanlong Gao
0 siblings, 0 replies; 6+ messages in thread
From: Wanlong Gao @ 2012-03-09 5:53 UTC (permalink / raw)
To: Caspar Zhang; +Cc: LTP List
On 03/09/2012 01:48 PM, Caspar Zhang wrote:
> On 03/09/2012 01:28 PM, Caspar Zhang wrote:
>>
>> in negative case:
>>
>> QUICK_TEST(sched_getaffinity(getpid()+1, len, mask));
>>
>> sometimes getpid()+1 will exist if there're other processes running.
>> This patch uses a different way to make sure the required pid doesn't
>> exist by forking a child and terminating it. The pid of the terminated
>> child will not be used for a short time and it's enough for the test to
>> continue.
>>
>> Signed-off-by: Caspar Zhang <caspar@casparzhang.com>
>> ---
>> .../sched_getaffinity/sched_getaffinity01.c | 18 ++++++++++++++++--
>> 1 files changed, 16 insertions(+), 2 deletions(-)
>>
>
> Hmmm, I took a look at commit c8319c8 and found that Garrett added a
> similar non-exist-pid case already. I guess we can simply remove the one
> I tried to fix...
Yes, agree, please remove this one.
Thanks,
Wanlong Gao
>
> Thanks,
> Caspar
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list
>
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] sched_getaffinity: fix possible fail in negative case
2012-03-09 5:28 [LTP] [PATCH] sched_getaffinity: fix possible fail in negative case Caspar Zhang
2012-03-09 5:48 ` Caspar Zhang
@ 2012-03-09 7:19 ` Garrett Cooper
2012-03-09 8:59 ` Caspar Zhang
2012-05-02 12:27 ` Cyril Hrubis
1 sibling, 2 replies; 6+ messages in thread
From: Garrett Cooper @ 2012-03-09 7:19 UTC (permalink / raw)
To: Caspar Zhang; +Cc: LTP List
On Mar 8, 2012, at 9:28 PM, Caspar Zhang wrote:
>
> in negative case:
>
> QUICK_TEST(sched_getaffinity(getpid()+1, len, mask));
>
> sometimes getpid()+1 will exist if there're other processes running.
> This patch uses a different way to make sure the required pid doesn't
> exist by forking a child and terminating it. The pid of the terminated
> child will not be used for a short time and it's enough for the test to
> continue.
pid_t is signed on FreeBSD and Linux, so it's safe to assume that a pid of -1 won't work. It all depends on what you're trying to achieve (the EINVAL or the ESRCH requirement).
Testing to make sure that a pid isn't running via kill(pid, 0) is another semi-viable method, but it's also racy.
Cheers,
-Garrett
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] sched_getaffinity: fix possible fail in negative case
2012-03-09 7:19 ` Garrett Cooper
@ 2012-03-09 8:59 ` Caspar Zhang
2012-05-02 12:27 ` Cyril Hrubis
1 sibling, 0 replies; 6+ messages in thread
From: Caspar Zhang @ 2012-03-09 8:59 UTC (permalink / raw)
To: Garrett Cooper; +Cc: LTP List
On 03/09/2012 03:19 PM, Garrett Cooper wrote:
> On Mar 8, 2012, at 9:28 PM, Caspar Zhang wrote:
>
>>
>> in negative case:
>>
>> QUICK_TEST(sched_getaffinity(getpid()+1, len, mask));
>>
>> sometimes getpid()+1 will exist if there're other processes running.
>> This patch uses a different way to make sure the required pid doesn't
>> exist by forking a child and terminating it. The pid of the terminated
>> child will not be used for a short time and it's enough for the test to
>> continue.
>
> pid_t is signed on FreeBSD and Linux, so it's safe to assume that a pid of -1 won't work. It all depends on what you're trying to achieve (the EINVAL or the ESRCH requirement).
> Testing to make sure that a pid isn't running via kill(pid, 0) is another semi-viable method, but it's also racy.
> Cheers,
> -Garrett
I'll keep your test case and remove the getpid()+1 one.
Thanks,
Caspar
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH] sched_getaffinity: fix possible fail in negative case
2012-03-09 7:19 ` Garrett Cooper
2012-03-09 8:59 ` Caspar Zhang
@ 2012-05-02 12:27 ` Cyril Hrubis
1 sibling, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2012-05-02 12:27 UTC (permalink / raw)
To: Garrett Cooper; +Cc: LTP List
Hi!
> > in negative case:
> >
> > QUICK_TEST(sched_getaffinity(getpid()+1, len, mask));
> >
> > sometimes getpid()+1 will exist if there're other processes running.
> > This patch uses a different way to make sure the required pid doesn't
> > exist by forking a child and terminating it. The pid of the terminated
> > child will not be used for a short time and it's enough for the test to
> > continue.
>
> pid_t is signed on FreeBSD and Linux, so it's safe to assume that a pid of -1 won't work. It all depends on what you're trying to achieve (the EINVAL or the ESRCH requirement).
> Testing to make sure that a pid isn't running via kill(pid, 0) is another semi-viable method, but it's also racy.
On Linux we could use /proc/sys/kernel/pid_max value + 1 value too. But
that would probably lead to EINVAL as well as -1.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-05-02 12:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-09 5:28 [LTP] [PATCH] sched_getaffinity: fix possible fail in negative case Caspar Zhang
2012-03-09 5:48 ` Caspar Zhang
2012-03-09 5:53 ` Wanlong Gao
2012-03-09 7:19 ` Garrett Cooper
2012-03-09 8:59 ` Caspar Zhang
2012-05-02 12:27 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox