All of lore.kernel.org
 help / color / mirror / Atom feed
* [BUG - HRT patch] nanosleep returns 0 on failure
@ 2003-01-08 16:41 Fleischer, Julie N
  2003-01-08 19:38 ` george anzinger
  0 siblings, 1 reply; 4+ messages in thread
From: Fleischer, Julie N @ 2003-01-08 16:41 UTC (permalink / raw)
  To: 'george@mvista.com'; +Cc: high-res-timers-discourse, linux-kernel

George -
In the latest 2.5.54-bk1 high-res-timers patches, it appears that
nanosleep() is returning 0 (success) and not setting errno when an rqtp
argument is sent that specifies a nsec value < 0 or >= 1000 million.  In
this instance, the POSIX System Interfaces doc states that errno is supposed
to be set to EINVAL, and nanosleep should return -1.

In the 2.5.50 high-res-timers patches, behavior was as expected (i.e.,
returned -1 and set errno=EINVAL).  Unfortunately, I haven't looked at any
patches since then to know exactly which patch stopped behaving as expected.
A plain 2.5.54-bk1 kernel also behaves as expected (returns -1, sets
errno=EINVAL).

The tests I am using to reproduce this issue are part of the POSIX Test
Suite at http://posixtest.sf.net under
posixtestsuite/conformance/interfaces/nanosleep.  5-1.c (sending -1 nsec),
6-1.c (sending multiple nsec values < 0 and >= 1,000 million), and 10000-1.c
(sending other nsec values < 0 and >= 1,000 million) are failing.  I've
included 5-1.c below.

Additional information is below:
kernel used = 2.5.54-bk1
HRT patches applied = 
 hrtimers-core-2.5.54-bk1-1.0.patch
 hrtimers-hrposix-2.5.54-bk1-1.0.patch
 hrtimers-i386-2.5.54-bk1-1.0.patch
 hrtimers-posix-2.5.54-bk1-1.0.patch
 hrtimers-support-2.5.52-1.0.patch

Thanks.
- Julie Fleischer

----
test 5-1.c below
(Output was:  nanosleep() did not return -1 on failure)

/*   
 * Copyright (c) 2002, Intel Corporation. All rights reserved.
 * Created by:  julie.n.fleischer REMOVE-THIS AT intel DOT com
 * This file is licensed under the GPL license.  For the full content
 * of this license, see the COPYING file at the top level of this 
 * source tree.

 * Test that nanosleep() returns -1 on failure.
 * Simulate failure condition by sending -1 as the nsec to sleep for.
 */
#include <stdio.h>
#include <time.h>

#define PTS_PASS        0
#define PTS_FAIL        1
#define PTS_UNRESOLVED  2

int main(int argc, char *argv[])
{
	struct timespec tssleepfor, tsstorage;
	int sleepnsec = -1;

	tssleepfor.tv_sec=0;
	tssleepfor.tv_nsec=sleepnsec;
	if (nanosleep(&tssleepfor, &tsstorage) == -1) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else {
		printf("nanosleep() did not return -1 on failure\n");
		return PTS_FAIL;
	}

	printf("This code should not be executed.\n");
	return PTS_UNRESOLVED;
}

**These views are not necessarily those of my employer.**

^ permalink raw reply	[flat|nested] 4+ messages in thread
* RE: [BUG - HRT patch] nanosleep returns 0 on failure
@ 2003-01-08 20:53 Fleischer, Julie N
  2003-01-08 20:14 ` george anzinger
  0 siblings, 1 reply; 4+ messages in thread
From: Fleischer, Julie N @ 2003-01-08 20:53 UTC (permalink / raw)
  To: 'george anzinger', Fleischer, Julie N
  Cc: high-res-timers-discourse, linux-kernel

> george anzinger wrote:
> If you don't mind, I will add your test code to my
> clock_nanosleep test code so this does not creep back in.

Sure.  It's all GPL.  The 6-1.c test case (attached below) probably has the
best test because it does multiple values, some < 0, some >= 1000 million.

One other thing I forgot to write in my previous report is that
clock_nanosleep() appeared to behave as expected, just nanosleep() showed
the issue of returning 0 on failure.

Thanks.
- Julie

----
test 6-1.c
/*   
 * Copyright (c) 2002, Intel Corporation. All rights reserved.
 * Created by:  julie.n.fleischer REMOVE-THIS AT intel DOT com
 * This file is licensed under the GPL license.  For the full content
 * of this license, see the COPYING file at the top level of this 
 * source tree.

 * Test that nanosleep() sets errno to EINVAL if rqtp contained a 
 * nanosecond value < 0 or >= 1,000 million
 */
#include <stdio.h>
#include <time.h>
#include <errno.h>

#define PTS_PASS        0
#define PTS_FAIL        1
#define PTS_UNRESOLVED  2

#define NUMTESTS 7

int main(int argc, char *argv[])
{
	struct timespec tssleepfor, tsstorage;
	int sleepnsec[NUMTESTS] = {-1, -5, -1000000000, 1000000000, 
		1000000001, 2000000000, 2000000000 };
	int i;
	int failure = 0;

	tssleepfor.tv_sec=0;

	for (i=0; i<NUMTESTS;i++) {
		tssleepfor.tv_nsec=sleepnsec[i];
		printf("sleep %d\n", sleepnsec[i]);
		if (nanosleep(&tssleepfor, &tsstorage) == -1) {
			if (EINVAL != errno) {
				printf("errno != EINVAL\n");
				failure = 1;
			}
		} else {
			printf("nanosleep() did not return -1 on
failure\n");
			return PTS_UNRESOLVED;
		}
	}

	if (failure) {
		printf("At least one test FAILED\n");
		return PTS_FAIL;
	} else {
		printf("All tests PASSED\n");
		return PTS_PASS;
	}
}
**These views are not necessarily those of my employer.**

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-01-08 21:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-08 16:41 [BUG - HRT patch] nanosleep returns 0 on failure Fleischer, Julie N
2003-01-08 19:38 ` george anzinger
  -- strict thread matches above, loose matches on Subject: below --
2003-01-08 20:53 Fleischer, Julie N
2003-01-08 20:14 ` george anzinger

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.