summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2014-12-13 02:51:27 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-12-13 02:51:27 +0000
commit0e32e39df0e487ec86d86627f1d4b43d1c8c524d (patch)
tree8bd99549e9cd7ff8d30742864b86ecc2dcb0ec36 /tests
parent732d65c1b1d33b2eadb5d6f2b1771c6fc536e23f (diff)
parent6c238f2926e69a950f0671ae5519584c20d84196 (diff)
downloadbionic-0e32e39df0e487ec86d86627f1d4b43d1c8c524d.zip
bionic-0e32e39df0e487ec86d86627f1d4b43d1c8c524d.tar.gz
bionic-0e32e39df0e487ec86d86627f1d4b43d1c8c524d.tar.bz2
Merge "Fix pthread key num calculation."
Diffstat (limited to 'tests')
-rw-r--r--tests/pthread_test.cpp25
-rw-r--r--tests/unistd_test.cpp2
2 files changed, 13 insertions, 14 deletions
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index f63d1ee..4fc5bed 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -42,19 +42,19 @@ TEST(pthread, pthread_key_create) {
}
TEST(pthread, pthread_keys_max) {
- // POSIX says PTHREAD_KEYS_MAX should be at least 128.
- ASSERT_GE(PTHREAD_KEYS_MAX, 128);
+ // POSIX says PTHREAD_KEYS_MAX should be at least _POSIX_THREAD_KEYS_MAX.
+ ASSERT_GE(PTHREAD_KEYS_MAX, _POSIX_THREAD_KEYS_MAX);
}
-TEST(pthread, _SC_THREAD_KEYS_MAX_big_enough_for_POSIX) {
- // sysconf shouldn't return a smaller value.
+TEST(pthread, sysconf_SC_THREAD_KEYS_MAX_eq_PTHREAD_KEYS_MAX) {
int sysconf_max = sysconf(_SC_THREAD_KEYS_MAX);
- ASSERT_GE(sysconf_max, PTHREAD_KEYS_MAX);
+ ASSERT_EQ(sysconf_max, PTHREAD_KEYS_MAX);
}
TEST(pthread, pthread_key_many_distinct) {
- // We should be able to allocate at least this many keys.
- int nkeys = sysconf(_SC_THREAD_KEYS_MAX) / 2;
+ // As gtest uses pthread keys, we can't allocate exactly PTHREAD_KEYS_MAX
+ // pthread keys, but We should be able to allocate at least this many keys.
+ int nkeys = PTHREAD_KEYS_MAX / 2;
std::vector<pthread_key_t> keys;
auto scope_guard = make_scope_guard([&keys]{
@@ -80,14 +80,13 @@ TEST(pthread, pthread_key_many_distinct) {
}
}
-TEST(pthread, pthread_key_EAGAIN) {
- int sysconf_max = sysconf(_SC_THREAD_KEYS_MAX);
-
+TEST(pthread, pthread_key_not_exceed_PTHREAD_KEYS_MAX) {
std::vector<pthread_key_t> keys;
int rv = 0;
- // Two keys are used by gtest, so sysconf_max should be more than we are
- // allowed to allocate now.
- for (int i = 0; i < sysconf_max; i++) {
+
+ // Pthread keys are used by gtest, so PTHREAD_KEYS_MAX should
+ // be more than we are allowed to allocate now.
+ for (int i = 0; i < PTHREAD_KEYS_MAX; i++) {
pthread_key_t key;
rv = pthread_key_create(&key, NULL);
if (rv == EAGAIN) {
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index 96d66e4..f5c0524 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -576,7 +576,7 @@ TEST(unistd, _POSIX_macros_smoke) {
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_ATTR_STACKSIZE);
EXPECT_EQ(0, _POSIX_THREAD_CPUTIME); // Use sysconf to detect support at runtime.
EXPECT_GT(_POSIX_THREAD_DESTRUCTOR_ITERATIONS, 0);
- EXPECT_GT(_POSIX_THREAD_KEYS_MAX, 0);
+ EXPECT_EQ(_POSIX_THREAD_KEYS_MAX, 128);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_PRIORITY_SCHEDULING);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_PRIO_INHERIT);
EXPECT_EQ(_POSIX_VERSION, _POSIX_THREAD_PRIO_PROTECT);