Merge "Fix 32-bit issues in tests, and add a trivial test for the FD_* macros."
This commit is contained in:
commit
00a816e587
@ -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 \
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
43
tests/sys_select_test.cpp
Normal file
43
tests/sys_select_test.cpp
Normal file
@ -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));
|
||||
}
|
Loading…
Reference in New Issue
Block a user