summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-10-02 16:59:05 -0700
committerElliott Hughes <enh@google.com>2013-10-02 16:59:05 -0700
commit5b9310e502003e584bcb3a028ca3db7aa4d3f01b (patch)
tree5747ee180ec0d5c352758125487a2815d4eb3716 /tests
parentf741e1c2ed27f153e92a2a36c9db3b189f9a6388 (diff)
downloadbionic-5b9310e502003e584bcb3a028ca3db7aa4d3f01b.zip
bionic-5b9310e502003e584bcb3a028ca3db7aa4d3f01b.tar.gz
bionic-5b9310e502003e584bcb3a028ca3db7aa4d3f01b.tar.bz2
Fix 32-bit issues in tests, and add a trivial test for the FD_* macros.
Change-Id: Ia3f21ce1f0ed9236527fe44d36ccb7de6bf63113
Diffstat (limited to 'tests')
-rw-r--r--tests/Android.mk1
-rw-r--r--tests/fortify_test.cpp2
-rw-r--r--tests/pthread_test.cpp9
-rw-r--r--tests/sys_select_test.cpp43
4 files changed, 50 insertions, 5 deletions
diff --git a/tests/Android.mk b/tests/Android.mk
index e60b908..39c28a4 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -80,6 +80,7 @@ test_src_files = \
string_test.cpp \
strings_test.cpp \
stubs_test.cpp \
+ sys_select_test.cpp \
sys_sendfile_test.cpp \
sys_stat_test.cpp \
system_properties_test.cpp \
diff --git a/tests/fortify_test.cpp b/tests/fortify_test.cpp
index 3a1bb93..abe2cae 100644
--- a/tests/fortify_test.cpp
+++ b/tests/fortify_test.cpp
@@ -350,7 +350,7 @@ TEST(DEATHTEST, strlen_fortified) {
::testing::FLAGS_gtest_death_test_style = "threadsafe";
char buf[10];
memcpy(buf, "0123456789", sizeof(buf));
- ASSERT_EXIT(printf("%d", strlen(buf)), testing::KilledBySignal(SIGABRT), "");
+ ASSERT_EXIT(printf("%zd", strlen(buf)), testing::KilledBySignal(SIGABRT), "");
}
TEST(DEATHTEST, strchr_fortified) {
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index d4d38f5..d82921b 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -17,6 +17,7 @@
#include <gtest/gtest.h>
#include <errno.h>
+#include <inttypes.h>
#include <limits.h>
#include <pthread.h>
#include <unistd.h>
@@ -56,7 +57,7 @@ static void* IdFn(void* arg) {
}
static void* SleepFn(void* arg) {
- sleep(reinterpret_cast<unsigned int>(arg));
+ sleep(reinterpret_cast<uintptr_t>(arg));
return NULL;
}
@@ -140,7 +141,7 @@ TEST(pthread, pthread_no_op_detach_after_join) {
// ...but t2's join on t1 still goes ahead (which we can tell because our join on t2 finishes).
void* join_result;
ASSERT_EQ(0, pthread_join(t2, &join_result));
- ASSERT_EQ(0, reinterpret_cast<int>(join_result));
+ ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(join_result));
}
TEST(pthread, pthread_join_self) {
@@ -190,7 +191,7 @@ TEST(pthread, pthread_sigmask) {
void* join_result;
ASSERT_EQ(0, pthread_join(signal_thread, &join_result));
ASSERT_EQ(SIGUSR1, received_signal);
- ASSERT_EQ(0, reinterpret_cast<int>(join_result));
+ ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(join_result));
}
#if __BIONIC__
@@ -348,7 +349,7 @@ TEST(pthread, pthread_join__multijoin) {
// ...but t2's join on t1 still goes ahead (which we can tell because our join on t2 finishes).
void* join_result;
ASSERT_EQ(0, pthread_join(t2, &join_result));
- ASSERT_EQ(0, reinterpret_cast<int>(join_result));
+ ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(join_result));
}
static void* GetActualGuardSizeFn(void* arg) {
diff --git a/tests/sys_select_test.cpp b/tests/sys_select_test.cpp
new file mode 100644
index 0000000..36f01b3
--- /dev/null
+++ b/tests/sys_select_test.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/select.h>
+
+TEST(sys_select, fd_set_smoke) {
+ fd_set fds;
+ FD_ZERO(&fds);
+
+ for (size_t i = 0; i < 1024; ++i) {
+ EXPECT_FALSE(FD_ISSET(i, &fds));
+ }
+
+ FD_SET(0, &fds);
+ EXPECT_TRUE(FD_ISSET(0, &fds));
+ EXPECT_FALSE(FD_ISSET(1, &fds));
+ FD_SET(1, &fds);
+ EXPECT_TRUE(FD_ISSET(0, &fds));
+ EXPECT_TRUE(FD_ISSET(1, &fds));
+ FD_CLR(0, &fds);
+ EXPECT_FALSE(FD_ISSET(0, &fds));
+ EXPECT_TRUE(FD_ISSET(1, &fds));
+ FD_CLR(1, &fds);
+ EXPECT_FALSE(FD_ISSET(0, &fds));
+ EXPECT_FALSE(FD_ISSET(1, &fds));
+}