Merge "More <limits.h> fixes."

am: 8f57fd4179

Change-Id: I5d917d4b142fa6a04b13c019c00fa3690771065e
This commit is contained in:
Elliott Hughes 2017-10-18 23:26:14 +00:00 committed by android-build-merger
commit 4dd32e00f7
4 changed files with 118 additions and 79 deletions

View file

@ -70,7 +70,7 @@
#define _POSIX_SHELL 1 /* system. */
#define _POSIX_SPAWN __BIONIC_POSIX_FEATURE_SINCE(28) /* <spawn.h> */
#define _POSIX_SPIN_LOCKS __BIONIC_POSIX_FEATURE_SINCE(24) /* pthread_spin_*. */
#define _POSIX_SPORADIC_SERVER _POSIX_VERSION /* sched_setparam/sched_setscheduler. */
#define _POSIX_SPORADIC_SERVER __BIONIC_POSIX_FEATURE_MISSING /* No SCHED_SPORADIC. */
#define _POSIX_SYNCHRONIZED_IO _POSIX_VERSION
#define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION /* Strictly, we're missing the deprecated pthread_attr_getstackaddr/pthread_attr_setstackaddr, but we do have pthread_attr_getstack/pthread_attr_setstack. */
#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION /* pthread_attr_getstack/pthread_attr_getstacksize/pthread_attr_setstack/pthread_attr_setstacksize. */
@ -82,7 +82,7 @@
#define _POSIX_THREAD_ROBUST_PRIO_INHERIT __BIONIC_POSIX_FEATURE_MISSING
#define _POSIX_THREAD_ROBUST_PRIO_PROTECT __BIONIC_POSIX_FEATURE_MISSING
#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION
#define _POSIX_THREAD_SPORADIC_SERVER _POSIX_VERSION /* sched_setparam/sched_setscheduler. */
#define _POSIX_THREAD_SPORADIC_SERVER __BIONIC_POSIX_FEATURE_MISSING /* No SCHED_SPORADIC. */
#define _POSIX_THREADS _POSIX_VERSION /* Strictly, pthread_cancel/pthread_testcancel are missing. */
#define _POSIX_TIMEOUTS __BIONIC_POSIX_FEATURE_SINCE(21) /* pthread_mutex_timedlock arrived late. */
#define _POSIX_TIMERS _POSIX_VERSION /* clock_getres/clock_gettime/clock_settime/nanosleep/timer_create/timer_delete/timer_gettime/timer_getoverrun/timer_settime. */
@ -94,6 +94,15 @@
#define _POSIX_VDISABLE '\0'
#define _POSIX2_C_BIND _POSIX_VERSION
#define _POSIX2_C_DEV __BIONIC_POSIX_FEATURE_MISSING
#define _POSIX2_CHAR_TERM _POSIX_VERSION
#define _POSIX2_FORT_DEV __BIONIC_POSIX_FEATURE_MISSING
#define _POSIX2_FORT_RUN __BIONIC_POSIX_FEATURE_MISSING
#define _POSIX2_LOCALEDEF __BIONIC_POSIX_FEATURE_MISSING
#define _POSIX2_SW_DEV __BIONIC_POSIX_FEATURE_MISSING
#define _POSIX2_UPE __BIONIC_POSIX_FEATURE_MISSING
#if defined(__LP64__)
#define _POSIX_V7_ILP32_OFF32 -1
#define _POSIX_V7_ILP32_OFFBIG -1
@ -106,16 +115,26 @@
#define _POSIX_V7_LPBIG_OFFBIG -1
#endif
#define _XOPEN_CRYPT __BIONIC_POSIX_FEATURE_MISSING
#define _XOPEN_ENH_I18N 1
#define _XOPEN_LEGACY __BIONIC_POSIX_FEATURE_MISSING
#define _XOPEN_REALTIME 1
#define _XOPEN_REALTIME_THREADS 1
#define _XOPEN_SHM 1
#define _XOPEN_STREAMS __BIONIC_POSIX_FEATURE_MISSING
#define _XOPEN_UNIX 1
/* Minimum values for other maxima. These numbers are simply lower bounds mandated by POSIX. */
/* Any constant values here other than -1 or 200809L are explicitly specified by POSIX.1-2008. */
/* The constant values here are explicitly specified by POSIX, not implementation dependent. */
#define _POSIX_AIO_LISTIO_MAX 2
#define _POSIX_AIO_MAX 1
#define _POSIX_ARG_MAX 4096
#define _POSIX_CHILD_MAX 25
#define _POSIX_CLOCKRES_MIN 20000000
#define _POSIX_DELAYTIMER_MAX 32
#define _POSIX_HOST_NAME_MAX 255
#define _POSIX_LINK_MAX 8
#define _POSIX_LOGIN_NAME_MAX 9 /* includes trailing NUL */
#define _POSIX_LOGIN_NAME_MAX 9
#define _POSIX_MAX_CANON 255
#define _POSIX_MAX_INPUT 255
#define _POSIX_MQ_OPEN_MAX 8
@ -126,45 +145,36 @@
#define _POSIX_PATH_MAX 256
#define _POSIX_PIPE_BUF 512
#define _POSIX_RE_DUP_MAX 255
#define _POSIX_RTSIG_MAX 8
#define _POSIX_SEM_NSEMS_MAX 256
#define _POSIX_SEM_VALUE_MAX 32767
#define _POSIX_SIGQUEUE_MAX 32
#define _POSIX_SSIZE_MAX 32767
#define _POSIX_STREAM_MAX 8
#define _POSIX_SS_REPL_MAX 4
#define _POSIX_SYMLINK_MAX 255
#define _POSIX_SYMLOOP_MAX 8
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
#define _POSIX_THREAD_KEYS_MAX 128
#define _POSIX_THREAD_THREADS_MAX 64
#define _POSIX_TIMER_MAX 32
#define _POSIX_TRACE_EVENT_NAME_MAX 30
#define _POSIX_TRACE_NAME_MAX 8
#define _POSIX_TRACE_SYS_MAX 8
#define _POSIX_TRACE_USER_EVENT_MAX 32
#define _POSIX_TTY_NAME_MAX 9 /* includes trailing NUL */
#define _POSIX_TTY_NAME_MAX 9
#define _POSIX_TZNAME_MAX 6
#define _POSIX2_BC_BASE_MAX 99
#define _POSIX2_BC_DIM_MAX 2048
#define _POSIX2_BC_SCALE_MAX 99
#define _POSIX2_BC_STRING_MAX 1000
#define _POSIX2_CHARCLASS_NAME_MAX 14
#define _POSIX2_CHAR_TERM -1 /* not implemented */
#define _POSIX2_COLL_WEIGHTS_MAX 2
#define _POSIX2_C_BIND _POSIX_VERSION
#define _POSIX2_C_DEV -1 /* c dev utilities not implemented */
#define _POSIX2_EXPR_NEST_MAX 32
#define _POSIX2_LINE_MAX 2048
#define _POSIX2_LOCALEDEF -1 /* localedef utilitiy not implemented */
#define _POSIX2_RE_DUP_MAX _POSIX_RE_DUP_MAX
#define _POSIX2_SW_DEV -1 /* software dev utilities not implemented */
#define _POSIX2_UPE -1 /* user portability utilities not implemented */
#define _XOPEN_ENH_I18N -1 /* we don't support internationalization in the C library */
#define _XOPEN_CRYPT -1 /* don't support X/Open Encryption */
#define _POSIX2_RE_DUP_MAX 255
#define _XOPEN_IOV_MAX 16
#define _XOPEN_LEGACY -1 /* not support all */
#define _XOPEN_REALTIME -1 /* we don't support all these functions */
#define _XOPEN_REALTIME_THREADS -1 /* same here */
#define _XOPEN_SHM -1
#define _XOPEN_UNIX 1
#define _XOPEN_NAME_MAX 255
#define _XOPEN_PATH_MAX 1024
#endif

View file

@ -61,6 +61,7 @@
#else
# define LONG_BIT 32
#endif
#define WORD_BIT 32
#define SCHAR_MAX 0x7f /* max value for a signed char */
#define SCHAR_MIN (-0x7f-1) /* min value for a signed char */
@ -130,6 +131,8 @@
#define MB_LEN_MAX 4
#define NZERO 20
#define IOV_MAX 1024
#define SEM_VALUE_MAX 0x3fffffff

View file

@ -19,9 +19,9 @@
#include <limits.h>
TEST(limits, macros) {
#if CHAR_BIT != 8
#error Insane CHAR_BIT
#endif
ASSERT_EQ(8, CHAR_BIT);
ASSERT_EQ(static_cast<int>(sizeof(int)), WORD_BIT);
ASSERT_EQ(20, NZERO);
#if !defined(MB_LEN_MAX)
#error MB_LEN_MAX
#endif

View file

@ -686,104 +686,131 @@ TEST(UNISTD_TEST, pathconf_fpathconf) {
ASSERT_TRUE(rc > 0 && powerof2(rc));
}
TEST(UNISTD_TEST, _POSIX_macros_smoke) {
TEST(UNISTD_TEST, _POSIX_constants) {
// Make a tight verification of _POSIX_* / _POSIX2_* / _XOPEN_* macros, to prevent change by mistake.
// Verify according to POSIX.1-2008.
EXPECT_EQ(200809L, _POSIX_VERSION);
EXPECT_EQ(2, _POSIX_AIO_LISTIO_MAX);
EXPECT_EQ(1, _POSIX_AIO_MAX);
EXPECT_EQ(4096, _POSIX_ARG_MAX);
EXPECT_EQ(25, _POSIX_CHILD_MAX);
EXPECT_EQ(20000000, _POSIX_CLOCKRES_MIN);
EXPECT_EQ(32, _POSIX_DELAYTIMER_MAX);
EXPECT_EQ(255, _POSIX_HOST_NAME_MAX);
EXPECT_EQ(8, _POSIX_LINK_MAX);
EXPECT_EQ(9, _POSIX_LOGIN_NAME_MAX);
EXPECT_EQ(255, _POSIX_MAX_CANON);
EXPECT_EQ(255, _POSIX_MAX_INPUT);
EXPECT_EQ(8, _POSIX_MQ_OPEN_MAX);
EXPECT_EQ(32, _POSIX_MQ_PRIO_MAX);
EXPECT_EQ(14, _POSIX_NAME_MAX);
EXPECT_EQ(8, _POSIX_NGROUPS_MAX);
EXPECT_EQ(20, _POSIX_OPEN_MAX);
EXPECT_EQ(256, _POSIX_PATH_MAX);
EXPECT_EQ(512, _POSIX_PIPE_BUF);
EXPECT_EQ(255, _POSIX_RE_DUP_MAX);
EXPECT_EQ(8, _POSIX_RTSIG_MAX);
EXPECT_EQ(256, _POSIX_SEM_NSEMS_MAX);
EXPECT_EQ(32767, _POSIX_SEM_VALUE_MAX);
EXPECT_EQ(32, _POSIX_SIGQUEUE_MAX);
EXPECT_EQ(32767, _POSIX_SSIZE_MAX);
EXPECT_EQ(8, _POSIX_STREAM_MAX);
#if !defined(__GLIBC__)
EXPECT_EQ(4, _POSIX_SS_REPL_MAX);
#endif
EXPECT_EQ(255, _POSIX_SYMLINK_MAX);
EXPECT_EQ(8, _POSIX_SYMLOOP_MAX);
EXPECT_EQ(4, _POSIX_THREAD_DESTRUCTOR_ITERATIONS);
EXPECT_EQ(128, _POSIX_THREAD_KEYS_MAX);
EXPECT_EQ(64, _POSIX_THREAD_THREADS_MAX);
EXPECT_EQ(32, _POSIX_TIMER_MAX);
#if !defined(__GLIBC__)
EXPECT_EQ(30, _POSIX_TRACE_EVENT_NAME_MAX);
EXPECT_EQ(8, _POSIX_TRACE_NAME_MAX);
EXPECT_EQ(8, _POSIX_TRACE_SYS_MAX);
EXPECT_EQ(32, _POSIX_TRACE_USER_EVENT_MAX);
#endif
EXPECT_EQ(9, _POSIX_TTY_NAME_MAX);
EXPECT_EQ(6, _POSIX_TZNAME_MAX);
EXPECT_EQ(99, _POSIX2_BC_BASE_MAX);
EXPECT_EQ(2048, _POSIX2_BC_DIM_MAX);
EXPECT_EQ(99, _POSIX2_BC_SCALE_MAX);
EXPECT_EQ(1000, _POSIX2_BC_STRING_MAX);
EXPECT_EQ(14, _POSIX2_CHARCLASS_NAME_MAX);
EXPECT_EQ(2, _POSIX2_COLL_WEIGHTS_MAX);
EXPECT_EQ(32, _POSIX2_EXPR_NEST_MAX);
EXPECT_EQ(2048, _POSIX2_LINE_MAX);
EXPECT_EQ(255, _POSIX2_RE_DUP_MAX);
EXPECT_EQ(16, _XOPEN_IOV_MAX);
#if !defined(__GLIBC__)
EXPECT_EQ(255, _XOPEN_NAME_MAX);
EXPECT_EQ(1024, _XOPEN_PATH_MAX);
#endif
}
TEST(UNISTD_TEST, _POSIX_options) {
EXPECT_EQ(_POSIX_VERSION, _POSIX_ADVISORY_INFO);
EXPECT_GT(_POSIX_AIO_LISTIO_MAX, 0);
EXPECT_GT(_POSIX_AIO_MAX, 0);
EXPECT_GT(_POSIX_ARG_MAX, 0);
EXPECT_GT(_POSIX_BARRIERS, 0);
EXPECT_GT(_POSIX_SPIN_LOCKS, 0);
EXPECT_GT(_POSIX_CHILD_MAX, 0);
EXPECT_NE(_POSIX_CHOWN_RESTRICTED, -1);
EXPECT_EQ(_POSIX_VERSION, _POSIX_CLOCK_SELECTION);
#if !defined(__GLIBC__) // glibc supports ancient kernels.
EXPECT_EQ(_POSIX_VERSION, _POSIX_CPUTIME);
EXPECT_GT(_POSIX_DELAYTIMER_MAX, 0);
#endif
EXPECT_EQ(_POSIX_VERSION, _POSIX_FSYNC);
EXPECT_GT(_POSIX_HOST_NAME_MAX, 0);
EXPECT_EQ(_POSIX_VERSION, _POSIX_IPV6);
EXPECT_GT(_POSIX_JOB_CONTROL, 0);
EXPECT_GT(_POSIX_LINK_MAX, 0);
EXPECT_GT(_POSIX_LOGIN_NAME_MAX, 0);
EXPECT_EQ(_POSIX_VERSION, _POSIX_MAPPED_FILES);
EXPECT_GT(_POSIX_MAX_CANON, 0);
EXPECT_GT(_POSIX_MAX_INPUT, 0);
EXPECT_EQ(_POSIX_VERSION, _POSIX_MEMLOCK);
EXPECT_EQ(_POSIX_VERSION, _POSIX_MEMLOCK_RANGE);
EXPECT_EQ(_POSIX_VERSION, _POSIX_MEMORY_PROTECTION);
#if !defined(__GLIBC__) // glibc supports ancient kernels.
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);
EXPECT_GT(_POSIX_NGROUPS_MAX, 0);
#endif
EXPECT_GT(_POSIX_NO_TRUNC, 0);
EXPECT_GT(_POSIX_OPEN_MAX, 0);
EXPECT_GT(_POSIX_PATH_MAX, 0);
EXPECT_GT(_POSIX_PIPE_BUF, 0);
EXPECT_EQ(_POSIX_VERSION, _POSIX_PRIORITY_SCHEDULING);
EXPECT_EQ(_POSIX_VERSION, _POSIX_RAW_SOCKETS);
EXPECT_EQ(_POSIX_VERSION, _POSIX_READER_WRITER_LOCKS);
EXPECT_EQ(_POSIX_VERSION, _POSIX_REALTIME_SIGNALS);
EXPECT_GT(_POSIX_REGEXP, 0);
EXPECT_GT(_POSIX_RE_DUP_MAX, 0);
EXPECT_GT(_POSIX_SAVED_IDS, 0);
EXPECT_EQ(_POSIX_VERSION, _POSIX_SEMAPHORES);
EXPECT_GT(_POSIX_SEM_NSEMS_MAX, 0);
EXPECT_GT(_POSIX_SEM_VALUE_MAX, 0);
EXPECT_GT(_POSIX_SHELL, 0);
EXPECT_GT(_POSIX_SIGQUEUE_MAX, 0);
EXPECT_EQ(_POSIX_VERSION, _POSIX_SPAWN);
EXPECT_EQ(_POSIX_VERSION, _POSIX_SPORADIC_SERVER);
EXPECT_GT(_POSIX_SSIZE_MAX, 0);
EXPECT_GT(_POSIX_STREAM_MAX, 0);
EXPECT_GT(_POSIX_SYMLINK_MAX, 0);
EXPECT_GT(_POSIX_SYMLOOP_MAX, 0);
EXPECT_EQ(-1, _POSIX_SPORADIC_SERVER);
EXPECT_EQ(_POSIX_VERSION, _POSIX_SYNCHRONIZED_IO);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREADS);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_ATTR_STACKADDR);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_ATTR_STACKSIZE);
#if !defined(__GLIBC__) // glibc supports ancient kernels.
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_CPUTIME);
EXPECT_GT(_POSIX_THREAD_DESTRUCTOR_ITERATIONS, 0);
EXPECT_EQ(_POSIX_THREAD_KEYS_MAX, 128);
#endif
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_PRIORITY_SCHEDULING);
EXPECT_EQ(-1, _POSIX_THREAD_PRIO_INHERIT);
EXPECT_EQ(-1, _POSIX_THREAD_PRIO_PROTECT);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_PROCESS_SHARED);
EXPECT_EQ(-1, _POSIX_THREAD_ROBUST_PRIO_PROTECT);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_SAFE_FUNCTIONS);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_SPORADIC_SERVER);
EXPECT_GT(_POSIX_THREAD_THREADS_MAX, 0);
EXPECT_EQ(-1, _POSIX_THREAD_SPORADIC_SERVER);
EXPECT_EQ(_POSIX_VERSION, _POSIX_TIMEOUTS);
EXPECT_EQ(_POSIX_VERSION, _POSIX_TIMERS);
EXPECT_GT(_POSIX_TIMER_MAX, 0);
EXPECT_EQ(-1, _POSIX_TRACE);
EXPECT_EQ(-1, _POSIX_TRACE_EVENT_FILTER);
EXPECT_EQ(-1, _POSIX_TRACE_INHERIT);
EXPECT_EQ(-1, _POSIX_TRACE_LOG);
EXPECT_GT(_POSIX_TTY_NAME_MAX, 0);
EXPECT_EQ(-1, _POSIX_TYPED_MEMORY_OBJECTS);
EXPECT_GT(_POSIX_TZNAME_MAX, 0);
EXPECT_NE(-1, _POSIX_VDISABLE);
EXPECT_EQ(_POSIX_VERSION, _POSIX2_VERSION);
EXPECT_GT(_POSIX2_BC_BASE_MAX, 0);
EXPECT_GT(_POSIX2_BC_DIM_MAX, 0);
EXPECT_GT(_POSIX2_BC_SCALE_MAX, 0);
EXPECT_GT(_POSIX2_BC_STRING_MAX, 0);
EXPECT_GT(_POSIX2_CHARCLASS_NAME_MAX, 0);
EXPECT_GT(_POSIX2_COLL_WEIGHTS_MAX, 0);
EXPECT_EQ(_POSIX_VERSION, _POSIX2_C_BIND);
EXPECT_GT(_POSIX2_EXPR_NEST_MAX, 0);
EXPECT_GT(_POSIX2_LINE_MAX, 0);
EXPECT_GT(_POSIX2_RE_DUP_MAX, 0);
EXPECT_EQ(_POSIX_VERSION, _POSIX2_CHAR_TERM);
EXPECT_EQ(700, _XOPEN_VERSION);
EXPECT_GT(_XOPEN_IOV_MAX, 0);
EXPECT_GT(_XOPEN_UNIX, 0);
EXPECT_EQ(1, _XOPEN_ENH_I18N);
EXPECT_EQ(1, _XOPEN_REALTIME);
EXPECT_EQ(1, _XOPEN_REALTIME_THREADS);
EXPECT_EQ(1, _XOPEN_SHM);
EXPECT_EQ(1, _XOPEN_UNIX);
#if defined(__BIONIC__)
// These tests only pass on bionic, as bionic and glibc has different support on these macros.
@ -792,21 +819,20 @@ TEST(UNISTD_TEST, _POSIX_macros_smoke) {
EXPECT_EQ(-1, _POSIX_MESSAGE_PASSING);
EXPECT_EQ(-1, _POSIX_PRIORITIZED_IO);
EXPECT_EQ(-1, _POSIX_SHARED_MEMORY_OBJECTS);
EXPECT_EQ(-1, _POSIX_THREAD_PRIO_INHERIT);
EXPECT_EQ(-1, _POSIX_THREAD_PRIO_PROTECT);
EXPECT_EQ(-1, _POSIX_THREAD_ROBUST_PRIO_INHERIT);
EXPECT_EQ(-1, _POSIX2_CHAR_TERM);
EXPECT_EQ(-1, _POSIX2_C_DEV);
EXPECT_EQ(-1, _POSIX2_FORT_DEV);
EXPECT_EQ(-1, _POSIX2_FORT_RUN);
EXPECT_EQ(-1, _POSIX2_LOCALEDEF);
EXPECT_EQ(-1, _POSIX2_SW_DEV);
EXPECT_EQ(-1, _POSIX2_UPE);
EXPECT_EQ(-1, _XOPEN_ENH_I18N);
EXPECT_EQ(-1, _XOPEN_CRYPT);
EXPECT_EQ(-1, _XOPEN_LEGACY);
EXPECT_EQ(-1, _XOPEN_REALTIME);
EXPECT_EQ(-1, _XOPEN_REALTIME_THREADS);
EXPECT_EQ(-1, _XOPEN_SHM);
EXPECT_EQ(-1, _XOPEN_STREAMS);
#endif // defined(__BIONIC__)
}
@ -916,11 +942,11 @@ TEST(UNISTD_TEST, sysconf) {
VERIFY_SYSCONF_POSITIVE(_SC_REGEXP);
VERIFY_SYSCONF_POSITIVE(_SC_SHELL);
VERIFY_SYSCONF_POSIX_VERSION(_SC_SPAWN);
VERIFY_SYSCONF_POSIX_VERSION(_SC_SPORADIC_SERVER);
VERIFY_SYSCONF_UNSUPPORTED(_SC_SPORADIC_SERVER);
VERIFY_SYSCONF_POSITIVE(_SC_SYMLOOP_MAX);
VERIFY_SYSCONF_POSIX_VERSION(_SC_THREAD_CPUTIME);
VERIFY_SYSCONF_POSIX_VERSION(_SC_THREAD_PROCESS_SHARED);
VERIFY_SYSCONF_POSIX_VERSION(_SC_THREAD_SPORADIC_SERVER);
VERIFY_SYSCONF_UNSUPPORTED(_SC_THREAD_SPORADIC_SERVER);
VERIFY_SYSCONF_POSIX_VERSION(_SC_TIMEOUTS);
VERIFY_SYSCONF_UNSUPPORTED(_SC_TRACE);
VERIFY_SYSCONF_UNSUPPORTED(_SC_TRACE_EVENT_FILTER);