Merge "POSIX clock cleanup." am: 0a451314b0

am: 71830bea01

Change-Id: Ie9df0f6b0db3e93a608df383381dcf72be42d835
This commit is contained in:
Elliott Hughes 2017-10-05 20:57:11 +00:00 committed by android-build-merger
commit 4fc3146765
5 changed files with 40 additions and 15 deletions

View file

@ -148,7 +148,7 @@ long sysconf(int name) {
case _SC_THREAD_PRIO_INHERIT: return _POSIX_THREAD_PRIO_INHERIT;
case _SC_THREAD_PRIO_PROTECT: return _POSIX_THREAD_PRIO_PROTECT;
case _SC_THREAD_SAFE_FUNCTIONS: return _POSIX_THREAD_SAFE_FUNCTIONS;
case _SC_MONOTONIC_CLOCK: return _POSIX_VERSION;
case _SC_MONOTONIC_CLOCK: return _POSIX_MONOTONIC_CLOCK;
case _SC_2_PBS: return -1; // Obsolescent in POSIX.1-2008.
case _SC_2_PBS_ACCOUNTING: return -1; // Obsolescent in POSIX.1-2008.
@ -159,7 +159,7 @@ long sysconf(int name) {
case _SC_ADVISORY_INFO: return _POSIX_ADVISORY_INFO;
case _SC_BARRIERS: return _POSIX_BARRIERS;
case _SC_CLOCK_SELECTION: return _POSIX_CLOCK_SELECTION;
case _SC_CPUTIME: return _POSIX_VERSION;
case _SC_CPUTIME: return _POSIX_CPUTIME;
case _SC_HOST_NAME_MAX: return _POSIX_HOST_NAME_MAX; // Minimum requirement.
case _SC_IPV6: return _POSIX_IPV6;
@ -172,7 +172,7 @@ long sysconf(int name) {
case _SC_SPORADIC_SERVER: return _POSIX_SPORADIC_SERVER;
case _SC_SS_REPL_MAX: return -1;
case _SC_SYMLOOP_MAX: return _POSIX_SYMLOOP_MAX; // Minimum requirement.
case _SC_THREAD_CPUTIME: return _POSIX_VERSION;
case _SC_THREAD_CPUTIME: return _POSIX_THREAD_CPUTIME;
case _SC_THREAD_PROCESS_SHARED: return _POSIX_THREAD_PROCESS_SHARED;
case _SC_THREAD_ROBUST_PRIO_INHERIT: return _POSIX_THREAD_ROBUST_PRIO_INHERIT;

View file

@ -31,7 +31,11 @@
#include <sys/cdefs.h>
#define __BIONIC_POSIX_FEATURE_SINCE(level) (((__ANDROID_API__) >= level) ? 200809L : -1)
#define _POSIX_VERSION 200809L
#define _POSIX2_VERSION _POSIX_VERSION
#define _XOPEN_VERSION 700
#define __BIONIC_POSIX_FEATURE_SINCE(level) (((__ANDROID_API__) >= level) ? _POSIX_VERSION : -1)
/* Any constant values here other than -1 or 200809L are explicitly specified by POSIX.1-2008. */
/* Keep this list sorted by name. */
@ -43,8 +47,8 @@
#define _POSIX_BARRIERS __BIONIC_POSIX_FEATURE_SINCE(24)
#define _POSIX_CHILD_MAX 25
#define _POSIX_CHOWN_RESTRICTED 1 /* yes, chown requires appropriate privileges */
#define _POSIX_CLOCK_SELECTION 200809L
#define _POSIX_CPUTIME 0 /* Use sysconf to detect support at runtime. */
#define _POSIX_CLOCK_SELECTION __BIONIC_POSIX_FEATURE_SINCE(21) /* clock_nanosleep/pthread_condattr_getclock/pthread_condattr_setclock. */
#define _POSIX_CPUTIME _POSIX_VERSION /* CLOCK_PROCESS_CPUTIME_ID. */
#define _POSIX_DELAYTIMER_MAX 32
#define _POSIX_FSYNC 200809L
#define _POSIX_HOST_NAME_MAX 255
@ -59,7 +63,7 @@
#define _POSIX_MEMLOCK_RANGE 200809L /* mlock. */
#define _POSIX_MEMORY_PROTECTION 200809L
#define _POSIX_MESSAGE_PASSING -1 /* not implemented */
#define _POSIX_MONOTONIC_CLOCK 0 /* the monotonic clock may be available; ask sysconf */
#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION /* CLOCK_MONOTONIC. */
#define _POSIX_MQ_OPEN_MAX 8
#define _POSIX_MQ_PRIO_MAX 32
#define _POSIX_NAME_MAX 14
@ -93,7 +97,7 @@
#define _POSIX_THREADS 200809L /* we support threads */
#define _POSIX_THREAD_ATTR_STACKADDR 200809L
#define _POSIX_THREAD_ATTR_STACKSIZE 200809L
#define _POSIX_THREAD_CPUTIME 0 /* Use sysconf to detect support at runtime. */
#define _POSIX_THREAD_CPUTIME _POSIX_VERSION /* CLOCK_THREAD_CPUTIME_ID. */
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
#define _POSIX_THREAD_KEYS_MAX 128
#define _POSIX_THREAD_PRIORITY_SCHEDULING 200809L

View file

@ -140,10 +140,6 @@
#define LOGIN_NAME_MAX 256
#define TTY_NAME_MAX 32
#define _POSIX_VERSION 200809L
#define _POSIX2_VERSION _POSIX_VERSION
#define _XOPEN_VERSION 700 /* by Posix definition */
/* >= _POSIX_THREAD_DESTRUCTOR_ITERATIONS */
#define PTHREAD_DESTRUCTOR_ITERATIONS 4
/* >= _POSIX_THREAD_KEYS_MAX */

View file

@ -574,6 +574,31 @@ TEST(time, clock_gettime) {
ASSERT_LT(ts2.tv_nsec, 1000000);
}
TEST(time, clock_gettime_CLOCK_REALTIME) {
timespec ts;
ASSERT_EQ(0, clock_gettime(CLOCK_REALTIME, &ts));
}
TEST(time, clock_gettime_CLOCK_MONOTONIC) {
timespec ts;
ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &ts));
}
TEST(time, clock_gettime_CLOCK_PROCESS_CPUTIME_ID) {
timespec ts;
ASSERT_EQ(0, clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts));
}
TEST(time, clock_gettime_CLOCK_THREAD_CPUTIME_ID) {
timespec ts;
ASSERT_EQ(0, clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts));
}
TEST(time, clock_gettime_CLOCK_BOOTTIME) {
timespec ts;
ASSERT_EQ(0, clock_gettime(CLOCK_BOOTTIME, &ts));
}
TEST(time, clock) {
// clock(3) is hard to test, but a 1s sleep should cost less than 1ms.
clock_t t0 = clock();

View file

@ -701,7 +701,7 @@ TEST(UNISTD_TEST, _POSIX_macros_smoke) {
EXPECT_GT(_POSIX_CHILD_MAX, 0);
EXPECT_NE(_POSIX_CHOWN_RESTRICTED, -1);
EXPECT_EQ(_POSIX_VERSION, _POSIX_CLOCK_SELECTION);
EXPECT_EQ(0, _POSIX_CPUTIME); // Use sysconf to detect support at runtime.
EXPECT_EQ(_POSIX_VERSION, _POSIX_CPUTIME);
EXPECT_GT(_POSIX_DELAYTIMER_MAX, 0);
EXPECT_EQ(_POSIX_VERSION, _POSIX_FSYNC);
EXPECT_GT(_POSIX_HOST_NAME_MAX, 0);
@ -715,7 +715,7 @@ TEST(UNISTD_TEST, _POSIX_macros_smoke) {
EXPECT_EQ(_POSIX_VERSION, _POSIX_MEMLOCK);
EXPECT_EQ(_POSIX_VERSION, _POSIX_MEMLOCK_RANGE);
EXPECT_EQ(_POSIX_VERSION, _POSIX_MEMORY_PROTECTION);
EXPECT_EQ(0, _POSIX_MONOTONIC_CLOCK);
EXPECT_EQ(_POSIX_VERSION, _POSIX_MONOTONIC_CLOCK);
EXPECT_GT(_POSIX_MQ_OPEN_MAX, 0);
EXPECT_GT(_POSIX_MQ_PRIO_MAX, 0);
EXPECT_GT(_POSIX_NAME_MAX, 0);
@ -745,7 +745,7 @@ TEST(UNISTD_TEST, _POSIX_macros_smoke) {
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREADS);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_ATTR_STACKADDR);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_ATTR_STACKSIZE);
EXPECT_EQ(0, _POSIX_THREAD_CPUTIME); // Use sysconf to detect support at runtime.
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_CPUTIME);
EXPECT_GT(_POSIX_THREAD_DESTRUCTOR_ITERATIONS, 0);
EXPECT_EQ(_POSIX_THREAD_KEYS_MAX, 128);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_PRIORITY_SCHEDULING);