|
From: Joseph S. M. <jo...@co...> - 2006-05-21 22:03:47
|
Various Open POSIX tests test _POSIX_CPUTIME or _POSIX_THREAD_CPUTIME with #ifdef and presume that if defined then the relevant option is present. This is not correct handling of these macros. If defined to a value > 0 then the option is present; if defined to -1 it is not; if defined to 0 or undefined, the tests need to use sysconf. To quote <http://www.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html>: The following symbolic constants, if defined in <unistd.h>, shall have a value of -1, 0, or greater, unless otherwise specified below. If these are undefined, the fpathconf(), pathconf(), or sysconf() functions can be used to determine whether the option is provided for a particular invocation of the application. If a symbolic constant is defined with the value -1, the option is not supported. Headers, data types, and function interfaces required only for the option need not be supplied. An application that attempts to use anything associated only with the option is considered to be requiring an extension. If a symbolic constant is defined with a value greater than zero, the option shall always be supported when the application is executed. All headers, data types, and functions shall be present and shall operate as specified. If a symbolic constant is defined with the value zero, all headers, data types, and functions shall be present. The application can check at runtime to see whether the option is supported by calling fpathconf(), pathconf(), or sysconf() with the indicated name parameter. In the case of these two macros, glibc does sometimes use the option of defining to 0 then determining at runtime whether it supports the option on that hardware and kernel. This patch changes the #ifdef conditionals and adds appropriate runtime sysconf checks. Index: conformance/interfaces/clock_getcpuclockid/1-1.c =================================================================== RCS file: /cvsroot/posixtest/posixtestsuite/conformance/interfaces/clock_getcpuclockid/1-1.c,v retrieving revision 1.10 diff -u -r1.10 1-1.c --- conformance/interfaces/clock_getcpuclockid/1-1.c 8 Apr 2004 08:41:02 -0000 1.10 +++ conformance/interfaces/clock_getcpuclockid/1-1.c 21 May 2006 21:21:09 -0000 @@ -32,13 +32,18 @@ int main(int argc, char *argv[]) { -#ifndef _POSIX_CPUTIME +#if _POSIX_CPUTIME == -1 printf("_POSIX_CPUTIME unsupported\n"); return PTS_UNSUPPORTED; #else clockid_t clockid; struct timespec tp1 = {.tv_sec = 0, .tv_nsec = 0}; + if (sysconf(_SC_CPUTIME) == -1) { + printf("_POSIX_CPUTIME unsupported\n"); + return PTS_UNSUPPORTED; + } + dosomething(); if (clock_getcpuclockid(getpid(), &clockid) != 0) { Index: conformance/interfaces/clock_getcpuclockid/2-1.c =================================================================== RCS file: /cvsroot/posixtest/posixtestsuite/conformance/interfaces/clock_getcpuclockid/2-1.c,v retrieving revision 1.1 diff -u -r1.1 2-1.c --- conformance/interfaces/clock_getcpuclockid/2-1.c 8 Apr 2004 08:39:29 -0000 1.1 +++ conformance/interfaces/clock_getcpuclockid/2-1.c 21 May 2006 21:21:09 -0000 @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) { -#ifndef _POSIX_CPUTIME +#if _POSIX_CPUTIME == -1 printf("_POSIX_CPUTIME unsupported\n"); return PTS_UNSUPPORTED; #else @@ -27,6 +27,11 @@ clockid_t clockid_1, clockid_2; struct timespec tp1, tp2; + if (sysconf(_SC_CPUTIME) == -1) { + printf("_POSIX_CPUTIME unsupported\n"); + return PTS_UNSUPPORTED; + } + if (clock_getcpuclockid(getpid(), &clockid_1) != 0) { printf("clock_getcpuclockid(getpid(), ) failed\n"); return PTS_FAIL; Index: conformance/interfaces/clock_getres/7-1.c =================================================================== RCS file: /cvsroot/posixtest/posixtestsuite/conformance/interfaces/clock_getres/7-1.c,v retrieving revision 1.2 diff -u -r1.2 7-1.c --- conformance/interfaces/clock_getres/7-1.c 2 Jun 2004 08:31:12 -0000 1.2 +++ conformance/interfaces/clock_getres/7-1.c 21 May 2006 21:21:09 -0000 @@ -18,8 +18,14 @@ #define LARGENUM 100000 int main(int argc, char *argv[]) { -#ifdef _POSIX_CPUTIME +#if _POSIX_CPUTIME != -1 struct timespec res; + + if (sysconf(_SC_CPUTIME) == -1) { + printf("_POSIX_CPUTIME not supported\n"); + return PTS_UNSUPPORTED; + } + /* Initialize res to a number much larger than the resolution * could possibly be */ Index: conformance/interfaces/clock_getres/8-1.c =================================================================== RCS file: /cvsroot/posixtest/posixtestsuite/conformance/interfaces/clock_getres/8-1.c,v retrieving revision 1.4 diff -u -r1.4 8-1.c --- conformance/interfaces/clock_getres/8-1.c 2 Jun 2004 08:31:12 -0000 1.4 +++ conformance/interfaces/clock_getres/8-1.c 21 May 2006 21:21:09 -0000 @@ -18,8 +18,14 @@ #define LARGENUM 100000 int main(int argc, char *argv[]) { -#ifdef _POSIX_THREAD_CPUTIME +#if _POSIX_THREAD_CPUTIME != -1 struct timespec res; + + if (sysconf(_SC_THREAD_CPUTIME) == -1) { + printf("_POSIX_THREAD_CPUTIME not supported\n"); + return PTS_UNSUPPORTED; + } + /* Initialize res to a number much larger than the resolution * could possibly be */ Index: conformance/interfaces/clock_gettime/4-1.c =================================================================== RCS file: /cvsroot/posixtest/posixtestsuite/conformance/interfaces/clock_gettime/4-1.c,v retrieving revision 1.5 diff -u -r1.5 4-1.c --- conformance/interfaces/clock_gettime/4-1.c 4 Jun 2003 22:01:20 -0000 1.5 +++ conformance/interfaces/clock_gettime/4-1.c 21 May 2006 21:21:09 -0000 @@ -29,13 +29,18 @@ int main(int argc, char *argv[]) { -#ifndef _POSIX_CPUTIME +#if _POSIX_CPUTIME == -1 printf("_POSIX_CPUTIME unsupported\n"); return PTS_UNSUPPORTED; #else #ifdef CLOCK_PROCESS_CPUTIME_ID struct timespec ts1, ts2, ts3, ts4; + if (sysconf(_SC_CPUTIME) == -1) { + printf("_POSIX_CPUTIME unsupported\n"); + return PTS_UNSUPPORTED; + } + if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts1) != 0) { printf("clock_gettime() failed: errno %d\n", errno); return PTS_UNRESOLVED; Index: conformance/interfaces/pthread_condattr_setclock/1-3.c =================================================================== RCS file: /cvsroot/posixtest/posixtestsuite/conformance/interfaces/pthread_condattr_setclock/1-3.c,v retrieving revision 1.1 diff -u -r1.1 1-3.c --- conformance/interfaces/pthread_condattr_setclock/1-3.c 23 Jun 2003 21:00:02 -0000 1.1 +++ conformance/interfaces/pthread_condattr_setclock/1-3.c 21 May 2006 21:21:12 -0000 @@ -30,7 +30,7 @@ int main() { - #ifndef _POSIX_CPUTIME + #if _POSIX_CPUTIME == -1 printf("_POSIX_CPUTIME unsupported\n"); return PTS_UNSUPPORTED; #endif @@ -39,6 +39,11 @@ clockid_t clockid; int rc; + if (sysconf(_SC_CPUTIME) == -1) { + printf("_POSIX_CPUTIME unsupported\n"); + return PTS_UNSUPPORTED; + } + /* Initialize a cond attributes object */ if((rc=pthread_condattr_init(&condattr)) != 0) { Index: conformance/interfaces/pthread_create/11-1.c =================================================================== RCS file: /cvsroot/posixtest/posixtestsuite/conformance/interfaces/pthread_create/11-1.c,v retrieving revision 1.1 diff -u -r1.1 11-1.c --- conformance/interfaces/pthread_create/11-1.c 9 Apr 2004 07:01:03 -0000 1.1 +++ conformance/interfaces/pthread_create/11-1.c 21 May 2006 21:21:12 -0000 @@ -41,12 +41,17 @@ int main() { -#ifndef _POSIX_THREAD_CPUTIME +#if _POSIX_THREAD_CPUTIME == -1 printf("_POSIX_THREAD_CPUTIME not supported\n"); return PTS_UNSUPPORTED; #endif pthread_t new_th; + if (sysconf(_SC_THREAD_CPUTIME) == -1) { + printf("_POSIX_THREAD_CPUTIME not supported\n"); + return PTS_UNSUPPORTED; + } + if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); Index: conformance/interfaces/timer_create/10-1.c =================================================================== RCS file: /cvsroot/posixtest/posixtestsuite/conformance/interfaces/timer_create/10-1.c,v retrieving revision 1.3 diff -u -r1.3 10-1.c --- conformance/interfaces/timer_create/10-1.c 1 Jun 2004 03:31:17 -0000 1.3 +++ conformance/interfaces/timer_create/10-1.c 21 May 2006 21:21:17 -0000 @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) { -#ifndef _POSIX_CPUTIME +#if _POSIX_CPUTIME == -1 printf("_POSIX_CPUTIME not defined\n"); return PTS_UNSUPPORTED; #else Index: conformance/interfaces/timer_create/11-1.c =================================================================== RCS file: /cvsroot/posixtest/posixtestsuite/conformance/interfaces/timer_create/11-1.c,v retrieving revision 1.2 diff -u -r1.2 11-1.c --- conformance/interfaces/timer_create/11-1.c 1 Jun 2004 03:31:17 -0000 1.2 +++ conformance/interfaces/timer_create/11-1.c 21 May 2006 21:21:17 -0000 @@ -33,13 +33,18 @@ rc = sysconf(_SC_THREAD_CPUTIME); printf("rc = %d\n", rc); -#ifdef _POSIX_THREAD_CPUTIME +#if _POSIX_THREAD_CPUTIME != -1 struct sigevent ev; struct sigaction act; timer_t tid; struct itimerspec its; struct timespec ts, tsleft; + if (rc == -1) { + printf("_POSIX_THREAD_CPUTIME unsupported\n"); + return PTS_UNSUPPORTED; + } + ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; -- Joseph S. Myers jo...@co... |