diff options
Diffstat (limited to 'libutils')
-rw-r--r-- | libutils/Android.mk | 10 | ||||
-rw-r--r-- | libutils/CallStack.cpp | 97 | ||||
-rw-r--r-- | libutils/Looper.cpp | 40 | ||||
-rw-r--r-- | libutils/Printer.cpp | 1 | ||||
-rw-r--r-- | libutils/ProcessCallStack.cpp | 10 | ||||
-rw-r--r-- | libutils/SystemClock.cpp | 25 | ||||
-rw-r--r-- | libutils/VectorImpl.cpp | 16 | ||||
-rw-r--r-- | libutils/tests/Looper_test.cpp | 158 |
8 files changed, 149 insertions, 208 deletions
diff --git a/libutils/Android.mk b/libutils/Android.mk index 720443e..1710d36 100644 --- a/libutils/Android.mk +++ b/libutils/Android.mk @@ -116,10 +116,12 @@ LOCAL_STATIC_LIBRARIES := \ libcutils LOCAL_SHARED_LIBRARIES := \ - libcorkscrew \ + libbacktrace \ liblog \ libdl +include external/stlport/libstlport.mk + LOCAL_MODULE:= libutils include $(BUILD_STATIC_LIBRARY) @@ -129,10 +131,12 @@ include $(CLEAR_VARS) LOCAL_MODULE:= libutils LOCAL_WHOLE_STATIC_LIBRARIES := libutils LOCAL_SHARED_LIBRARIES := \ - liblog \ + libbacktrace \ libcutils \ libdl \ - libcorkscrew + liblog \ + +include external/stlport/libstlport.mk include $(BUILD_SHARED_LIBRARY) diff --git a/libutils/CallStack.cpp b/libutils/CallStack.cpp index 4ceaa7c..0bfb520 100644 --- a/libutils/CallStack.cpp +++ b/libutils/CallStack.cpp @@ -20,93 +20,33 @@ #include <utils/Printer.h> #include <utils/Errors.h> #include <utils/Log.h> -#include <corkscrew/backtrace.h> +#include <UniquePtr.h> + +#include <backtrace/Backtrace.h> namespace android { -CallStack::CallStack() : - mCount(0) { +CallStack::CallStack() { } -CallStack::CallStack(const char* logtag, int32_t ignoreDepth, int32_t maxDepth) { - this->update(ignoreDepth+1, maxDepth, CURRENT_THREAD); +CallStack::CallStack(const char* logtag, int32_t ignoreDepth) { + this->update(ignoreDepth+1); this->log(logtag); } -CallStack::CallStack(const CallStack& rhs) : - mCount(rhs.mCount) { - if (mCount) { - memcpy(mStack, rhs.mStack, mCount * sizeof(backtrace_frame_t)); - } -} - CallStack::~CallStack() { } -CallStack& CallStack::operator = (const CallStack& rhs) { - mCount = rhs.mCount; - if (mCount) { - memcpy(mStack, rhs.mStack, mCount * sizeof(backtrace_frame_t)); - } - return *this; -} - -bool CallStack::operator == (const CallStack& rhs) const { - if (mCount != rhs.mCount) - return false; - return !mCount || memcmp(mStack, rhs.mStack, mCount * sizeof(backtrace_frame_t)) == 0; -} - -bool CallStack::operator != (const CallStack& rhs) const { - return !operator == (rhs); -} - -bool CallStack::operator < (const CallStack& rhs) const { - if (mCount != rhs.mCount) - return mCount < rhs.mCount; - return memcmp(mStack, rhs.mStack, mCount * sizeof(backtrace_frame_t)) < 0; -} +void CallStack::update(int32_t ignoreDepth, pid_t tid) { + mFrameLines.clear(); -bool CallStack::operator >= (const CallStack& rhs) const { - return !operator < (rhs); -} - -bool CallStack::operator > (const CallStack& rhs) const { - if (mCount != rhs.mCount) - return mCount > rhs.mCount; - return memcmp(mStack, rhs.mStack, mCount * sizeof(backtrace_frame_t)) > 0; -} - -bool CallStack::operator <= (const CallStack& rhs) const { - return !operator > (rhs); -} - -const void* CallStack::operator [] (int index) const { - if (index >= int(mCount)) - return 0; - return reinterpret_cast<const void*>(mStack[index].absolute_pc); -} - -void CallStack::clear() { - mCount = 0; -} - -void CallStack::update(int32_t ignoreDepth, int32_t maxDepth, pid_t tid) { - if (maxDepth > MAX_DEPTH) { - maxDepth = MAX_DEPTH; + UniquePtr<Backtrace> backtrace(Backtrace::Create(BACKTRACE_CURRENT_PROCESS, tid)); + if (!backtrace->Unwind(ignoreDepth)) { + ALOGW("%s: Failed to unwind callstack.", __FUNCTION__); } - ssize_t count; - - if (tid >= 0) { - count = unwind_backtrace_thread(tid, mStack, ignoreDepth + 1, maxDepth); - } else if (tid == CURRENT_THREAD) { - count = unwind_backtrace(mStack, ignoreDepth + 1, maxDepth); - } else { - ALOGE("%s: Invalid tid specified (%d)", __FUNCTION__, tid); - count = 0; + for (size_t i = 0; i < backtrace->NumFrames(); i++) { + mFrameLines.push_back(String8(backtrace->FormatFrameData(i).c_str())); } - - mCount = count > 0 ? count : 0; } void CallStack::log(const char* logtag, android_LogPriority priority, const char* prefix) const { @@ -129,16 +69,9 @@ String8 CallStack::toString(const char* prefix) const { } void CallStack::print(Printer& printer) const { - backtrace_symbol_t symbols[mCount]; - - get_backtrace_symbols(mStack, mCount, symbols); - for (size_t i = 0; i < mCount; i++) { - char line[MAX_BACKTRACE_LINE_LENGTH]; - format_backtrace_line(i, &mStack[i], &symbols[i], - line, MAX_BACKTRACE_LINE_LENGTH); - printer.printLine(line); + for (size_t i = 0; i < mFrameLines.size(); i++) { + printer.printLine(mFrameLines[i]); } - free_backtrace_symbols(symbols, mCount); } }; // namespace android diff --git a/libutils/Looper.cpp b/libutils/Looper.cpp index c51df2d..9a2dd6c 100644 --- a/libutils/Looper.cpp +++ b/libutils/Looper.cpp @@ -43,7 +43,7 @@ void WeakMessageHandler::handleMessage(const Message& message) { // --- SimpleLooperCallback --- -SimpleLooperCallback::SimpleLooperCallback(ALooper_callbackFunc callback) : +SimpleLooperCallback::SimpleLooperCallback(Looper_callbackFunc callback) : mCallback(callback) { } @@ -139,7 +139,7 @@ sp<Looper> Looper::getForThread() { } sp<Looper> Looper::prepare(int opts) { - bool allowNonCallbacks = opts & ALOOPER_PREPARE_ALLOW_NON_CALLBACKS; + bool allowNonCallbacks = opts & PREPARE_ALLOW_NON_CALLBACKS; sp<Looper> looper = Looper::getForThread(); if (looper == NULL) { looper = new Looper(allowNonCallbacks); @@ -147,7 +147,7 @@ sp<Looper> Looper::prepare(int opts) { } if (looper->getAllowNonCallbacks() != allowNonCallbacks) { ALOGW("Looper already prepared for this thread with a different value for the " - "ALOOPER_PREPARE_ALLOW_NON_CALLBACKS option."); + "LOOPER_PREPARE_ALLOW_NON_CALLBACKS option."); } return looper; } @@ -212,7 +212,7 @@ int Looper::pollInner(int timeoutMillis) { } // Poll. - int result = ALOOPER_POLL_WAKE; + int result = POLL_WAKE; mResponses.clear(); mResponseIndex = 0; @@ -234,7 +234,7 @@ int Looper::pollInner(int timeoutMillis) { goto Done; } ALOGW("Poll failed with an unexpected error, errno=%d", errno); - result = ALOOPER_POLL_ERROR; + result = POLL_ERROR; goto Done; } @@ -243,7 +243,7 @@ int Looper::pollInner(int timeoutMillis) { #if DEBUG_POLL_AND_WAKE ALOGD("%p ~ pollOnce - timeout", this); #endif - result = ALOOPER_POLL_TIMEOUT; + result = POLL_TIMEOUT; goto Done; } @@ -265,10 +265,10 @@ int Looper::pollInner(int timeoutMillis) { ssize_t requestIndex = mRequests.indexOfKey(fd); if (requestIndex >= 0) { int events = 0; - if (epollEvents & EPOLLIN) events |= ALOOPER_EVENT_INPUT; - if (epollEvents & EPOLLOUT) events |= ALOOPER_EVENT_OUTPUT; - if (epollEvents & EPOLLERR) events |= ALOOPER_EVENT_ERROR; - if (epollEvents & EPOLLHUP) events |= ALOOPER_EVENT_HANGUP; + if (epollEvents & EPOLLIN) events |= EVENT_INPUT; + if (epollEvents & EPOLLOUT) events |= EVENT_OUTPUT; + if (epollEvents & EPOLLERR) events |= EVENT_ERROR; + if (epollEvents & EPOLLHUP) events |= EVENT_HANGUP; pushResponse(events, mRequests.valueAt(requestIndex)); } else { ALOGW("Ignoring unexpected epoll events 0x%x on fd %d that is " @@ -304,7 +304,7 @@ Done: ; mLock.lock(); mSendingMessage = false; - result = ALOOPER_POLL_CALLBACK; + result = POLL_CALLBACK; } else { // The last message left at the head of the queue determines the next wakeup time. mNextMessageUptime = messageEnvelope.uptime; @@ -318,7 +318,7 @@ Done: ; // Invoke all response callbacks. for (size_t i = 0; i < mResponses.size(); i++) { Response& response = mResponses.editItemAt(i); - if (response.request.ident == ALOOPER_POLL_CALLBACK) { + if (response.request.ident == POLL_CALLBACK) { int fd = response.request.fd; int events = response.events; void* data = response.request.data; @@ -333,7 +333,7 @@ Done: ; // Clear the callback reference in the response structure promptly because we // will not clear the response vector itself until the next poll. response.request.callback.clear(); - result = ALOOPER_POLL_CALLBACK; + result = POLL_CALLBACK; } } return result; @@ -344,7 +344,7 @@ int Looper::pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outDat int result; do { result = pollOnce(timeoutMillis, outFd, outEvents, outData); - } while (result == ALOOPER_POLL_CALLBACK); + } while (result == POLL_CALLBACK); return result; } else { nsecs_t endTime = systemTime(SYSTEM_TIME_MONOTONIC) @@ -352,14 +352,14 @@ int Looper::pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outDat for (;;) { int result = pollOnce(timeoutMillis, outFd, outEvents, outData); - if (result != ALOOPER_POLL_CALLBACK) { + if (result != POLL_CALLBACK) { return result; } nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); timeoutMillis = toMillisecondTimeoutDelay(now, endTime); if (timeoutMillis == 0) { - return ALOOPER_POLL_TIMEOUT; + return POLL_TIMEOUT; } } } @@ -401,7 +401,7 @@ void Looper::pushResponse(int events, const Request& request) { mResponses.push(response); } -int Looper::addFd(int fd, int ident, int events, ALooper_callbackFunc callback, void* data) { +int Looper::addFd(int fd, int ident, int events, Looper_callbackFunc callback, void* data) { return addFd(fd, ident, events, callback ? new SimpleLooperCallback(callback) : NULL, data); } @@ -422,12 +422,12 @@ int Looper::addFd(int fd, int ident, int events, const sp<LooperCallback>& callb return -1; } } else { - ident = ALOOPER_POLL_CALLBACK; + ident = POLL_CALLBACK; } int epollEvents = 0; - if (events & ALOOPER_EVENT_INPUT) epollEvents |= EPOLLIN; - if (events & ALOOPER_EVENT_OUTPUT) epollEvents |= EPOLLOUT; + if (events & EVENT_INPUT) epollEvents |= EPOLLIN; + if (events & EVENT_OUTPUT) epollEvents |= EPOLLOUT; { // acquire lock AutoMutex _l(mLock); diff --git a/libutils/Printer.cpp b/libutils/Printer.cpp index ac729e0..263e740 100644 --- a/libutils/Printer.cpp +++ b/libutils/Printer.cpp @@ -145,6 +145,7 @@ void String8Printer::printLine(const char* string) { return; } + mTarget->append(mPrefix); mTarget->append(string); mTarget->append("\n"); } diff --git a/libutils/ProcessCallStack.cpp b/libutils/ProcessCallStack.cpp index f9340c5..f837bcb 100644 --- a/libutils/ProcessCallStack.cpp +++ b/libutils/ProcessCallStack.cpp @@ -123,7 +123,7 @@ void ProcessCallStack::clear() { mTimeUpdated = tm(); } -void ProcessCallStack::update(int32_t maxDepth) { +void ProcessCallStack::update() { DIR *dp; struct dirent *ep; struct dirent entry; @@ -181,14 +181,13 @@ void ProcessCallStack::update(int32_t maxDepth) { int ignoreDepth = (selfPid == tid) ? IGNORE_DEPTH_CURRENT_THREAD : 0; // Update thread's call stacks - CallStack& cs = threadInfo.callStack; - cs.update(ignoreDepth, maxDepth, tid); + threadInfo.callStack.update(ignoreDepth, tid); // Read/save thread name threadInfo.threadName = getThreadName(tid); ALOGV("%s: Got call stack for tid %d (size %zu)", - __FUNCTION__, tid, cs.size()); + __FUNCTION__, tid, threadInfo.callStack.size()); } if (code != 0) { // returns positive error value on error ALOGE("%s: Failed to readdir from %s (errno = %d, '%s')", @@ -221,13 +220,12 @@ void ProcessCallStack::printInternal(Printer& printer, Printer& csPrinter) const for (size_t i = 0; i < mThreadMap.size(); ++i) { pid_t tid = mThreadMap.keyAt(i); const ThreadInfo& threadInfo = mThreadMap.valueAt(i); - const CallStack& cs = threadInfo.callStack; const String8& threadName = threadInfo.threadName; printer.printLine(""); printer.printFormatLine("\"%s\" sysTid=%d", threadName.string(), tid); - cs.print(csPrinter); + threadInfo.callStack.print(csPrinter); } dumpProcessFooter(printer, getpid()); diff --git a/libutils/SystemClock.cpp b/libutils/SystemClock.cpp index ac8da88..413250f 100644 --- a/libutils/SystemClock.cpp +++ b/libutils/SystemClock.cpp @@ -119,22 +119,6 @@ int64_t elapsedRealtimeNano() static volatile int prevMethod; #endif -#if 0 - /* - * b/7100774 - * clock_gettime appears to have clock skews and can sometimes return - * backwards values. Disable its use until we find out what's wrong. - */ - result = clock_gettime(CLOCK_BOOTTIME, &ts); - if (result == 0) { - timestamp = seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; - checkTimeStamps(timestamp, &prevTimestamp, &prevMethod, - METHOD_CLOCK_GETTIME); - return timestamp; - } -#endif - - // CLOCK_BOOTTIME doesn't exist, fallback to /dev/alarm static int s_fd = -1; if (s_fd == -1) { @@ -153,6 +137,15 @@ int64_t elapsedRealtimeNano() return timestamp; } + // /dev/alarm doesn't exist, fallback to CLOCK_BOOTTIME + result = clock_gettime(CLOCK_BOOTTIME, &ts); + if (result == 0) { + timestamp = seconds_to_nanoseconds(ts.tv_sec) + ts.tv_nsec; + checkTimeStamps(timestamp, &prevTimestamp, &prevMethod, + METHOD_CLOCK_GETTIME); + return timestamp; + } + // XXX: there was an error, probably because the driver didn't // exist ... this should return // a real error, like an exception! diff --git a/libutils/VectorImpl.cpp b/libutils/VectorImpl.cpp index 5a79647..30ca663 100644 --- a/libutils/VectorImpl.cpp +++ b/libutils/VectorImpl.cpp @@ -384,7 +384,11 @@ void* VectorImpl::_grow(size_t where, size_t amount) { const SharedBuffer* cur_sb = SharedBuffer::bufferFromData(mStorage); SharedBuffer* sb = cur_sb->editResize(new_capacity * mItemSize); - mStorage = sb->data(); + if (sb) { + mStorage = sb->data(); + } else { + return NULL; + } } else { SharedBuffer* sb = SharedBuffer::alloc(new_capacity * mItemSize); if (sb) { @@ -399,6 +403,8 @@ void* VectorImpl::_grow(size_t where, size_t amount) } release_storage(); mStorage = const_cast<void*>(array); + } else { + return NULL; } } } else { @@ -436,7 +442,11 @@ void VectorImpl::_shrink(size_t where, size_t amount) { const SharedBuffer* cur_sb = SharedBuffer::bufferFromData(mStorage); SharedBuffer* sb = cur_sb->editResize(new_capacity * mItemSize); - mStorage = sb->data(); + if (sb) { + mStorage = sb->data(); + } else { + return; + } } else { SharedBuffer* sb = SharedBuffer::alloc(new_capacity * mItemSize); if (sb) { @@ -451,6 +461,8 @@ void VectorImpl::_shrink(size_t where, size_t amount) } release_storage(); mStorage = const_cast<void*>(array); + } else{ + return; } } } else { diff --git a/libutils/tests/Looper_test.cpp b/libutils/tests/Looper_test.cpp index 8bf2ba2..00077e6 100644 --- a/libutils/tests/Looper_test.cpp +++ b/libutils/tests/Looper_test.cpp @@ -119,8 +119,8 @@ TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndNotAwoken_WaitsForTimeout) { EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. equal timeout"; - EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result) - << "pollOnce result should be ALOOPER_POLL_TIMEOUT"; + EXPECT_EQ(Looper::POLL_TIMEOUT, result) + << "pollOnce result should be LOOPER_POLL_TIMEOUT"; } TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndAwokenBeforeWaiting_ImmediatelyReturns) { @@ -132,8 +132,8 @@ TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndAwokenBeforeWaiting_Immediately EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. zero because wake() was called before waiting"; - EXPECT_EQ(ALOOPER_POLL_WAKE, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because loop was awoken"; + EXPECT_EQ(Looper::POLL_WAKE, result) + << "pollOnce result should be Looper::POLL_CALLBACK because loop was awoken"; } TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndAwokenWhileWaiting_PromptlyReturns) { @@ -146,8 +146,8 @@ TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndAwokenWhileWaiting_PromptlyRetu EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. equal wake delay"; - EXPECT_EQ(ALOOPER_POLL_WAKE, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because loop was awoken"; + EXPECT_EQ(Looper::POLL_WAKE, result) + << "pollOnce result should be Looper::POLL_CALLBACK because loop was awoken"; } TEST_F(LooperTest, PollOnce_WhenZeroTimeoutAndNoRegisteredFDs_ImmediatelyReturns) { @@ -157,15 +157,15 @@ TEST_F(LooperTest, PollOnce_WhenZeroTimeoutAndNoRegisteredFDs_ImmediatelyReturns EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should be approx. zero"; - EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result) - << "pollOnce result should be ALOOPER_POLL_TIMEOUT"; + EXPECT_EQ(Looper::POLL_TIMEOUT, result) + << "pollOnce result should be Looper::POLL_TIMEOUT"; } TEST_F(LooperTest, PollOnce_WhenZeroTimeoutAndNoSignalledFDs_ImmediatelyReturns) { Pipe pipe; StubCallbackHandler handler(true); - handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT); + handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT); StopWatch stopWatch("pollOnce"); int result = mLooper->pollOnce(0); @@ -173,8 +173,8 @@ TEST_F(LooperTest, PollOnce_WhenZeroTimeoutAndNoSignalledFDs_ImmediatelyReturns) EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should be approx. zero"; - EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result) - << "pollOnce result should be ALOOPER_POLL_TIMEOUT"; + EXPECT_EQ(Looper::POLL_TIMEOUT, result) + << "pollOnce result should be Looper::POLL_TIMEOUT"; EXPECT_EQ(0, handler.callbackCount) << "callback should not have been invoked because FD was not signalled"; } @@ -184,7 +184,7 @@ TEST_F(LooperTest, PollOnce_WhenZeroTimeoutAndSignalledFD_ImmediatelyInvokesCall StubCallbackHandler handler(true); ASSERT_EQ(OK, pipe.writeSignal()); - handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT); + handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT); StopWatch stopWatch("pollOnce"); int result = mLooper->pollOnce(0); @@ -192,21 +192,21 @@ TEST_F(LooperTest, PollOnce_WhenZeroTimeoutAndSignalledFD_ImmediatelyInvokesCall EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should be approx. zero"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because FD was signalled"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because FD was signalled"; EXPECT_EQ(1, handler.callbackCount) << "callback should be invoked exactly once"; EXPECT_EQ(pipe.receiveFd, handler.fd) << "callback should have received pipe fd as parameter"; - EXPECT_EQ(ALOOPER_EVENT_INPUT, handler.events) - << "callback should have received ALOOPER_EVENT_INPUT as events"; + EXPECT_EQ(Looper::EVENT_INPUT, handler.events) + << "callback should have received Looper::EVENT_INPUT as events"; } TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndNoSignalledFDs_WaitsForTimeoutAndReturns) { Pipe pipe; StubCallbackHandler handler(true); - handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT); + handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT); StopWatch stopWatch("pollOnce"); int result = mLooper->pollOnce(100); @@ -214,8 +214,8 @@ TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndNoSignalledFDs_WaitsForTimeoutA EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. equal timeout"; - EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result) - << "pollOnce result should be ALOOPER_POLL_TIMEOUT"; + EXPECT_EQ(Looper::POLL_TIMEOUT, result) + << "pollOnce result should be Looper::POLL_TIMEOUT"; EXPECT_EQ(0, handler.callbackCount) << "callback should not have been invoked because FD was not signalled"; } @@ -225,7 +225,7 @@ TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndSignalledFDBeforeWaiting_Immedi StubCallbackHandler handler(true); pipe.writeSignal(); - handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT); + handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT); StopWatch stopWatch("pollOnce"); int result = mLooper->pollOnce(100); @@ -235,14 +235,14 @@ TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndSignalledFDBeforeWaiting_Immedi << "signal should actually have been written"; EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should be approx. zero"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because FD was signalled"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because FD was signalled"; EXPECT_EQ(1, handler.callbackCount) << "callback should be invoked exactly once"; EXPECT_EQ(pipe.receiveFd, handler.fd) << "callback should have received pipe fd as parameter"; - EXPECT_EQ(ALOOPER_EVENT_INPUT, handler.events) - << "callback should have received ALOOPER_EVENT_INPUT as events"; + EXPECT_EQ(Looper::EVENT_INPUT, handler.events) + << "callback should have received Looper::EVENT_INPUT as events"; } TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndSignalledFDWhileWaiting_PromptlyInvokesCallbackAndReturns) { @@ -250,7 +250,7 @@ TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndSignalledFDWhileWaiting_Promptl StubCallbackHandler handler(true); sp<DelayedWriteSignal> delayedWriteSignal = new DelayedWriteSignal(100, & pipe); - handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT); + handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT); delayedWriteSignal->run(); StopWatch stopWatch("pollOnce"); @@ -261,21 +261,21 @@ TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndSignalledFDWhileWaiting_Promptl << "signal should actually have been written"; EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. equal signal delay"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because FD was signalled"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because FD was signalled"; EXPECT_EQ(1, handler.callbackCount) << "callback should be invoked exactly once"; EXPECT_EQ(pipe.receiveFd, handler.fd) << "callback should have received pipe fd as parameter"; - EXPECT_EQ(ALOOPER_EVENT_INPUT, handler.events) - << "callback should have received ALOOPER_EVENT_INPUT as events"; + EXPECT_EQ(Looper::EVENT_INPUT, handler.events) + << "callback should have received Looper::EVENT_INPUT as events"; } TEST_F(LooperTest, PollOnce_WhenCallbackAddedThenRemoved_CallbackShouldNotBeInvoked) { Pipe pipe; StubCallbackHandler handler(true); - handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT); + handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT); pipe.writeSignal(); // would cause FD to be considered signalled mLooper->removeFd(pipe.receiveFd); @@ -287,8 +287,8 @@ TEST_F(LooperTest, PollOnce_WhenCallbackAddedThenRemoved_CallbackShouldNotBeInvo << "signal should actually have been written"; EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. equal timeout because FD was no longer registered"; - EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result) - << "pollOnce result should be ALOOPER_POLL_TIMEOUT"; + EXPECT_EQ(Looper::POLL_TIMEOUT, result) + << "pollOnce result should be Looper::POLL_TIMEOUT"; EXPECT_EQ(0, handler.callbackCount) << "callback should not be invoked"; } @@ -297,7 +297,7 @@ TEST_F(LooperTest, PollOnce_WhenCallbackReturnsFalse_CallbackShouldNotBeInvokedA Pipe pipe; StubCallbackHandler handler(false); - handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT); + handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT); // First loop: Callback is registered and FD is signalled. pipe.writeSignal(); @@ -310,8 +310,8 @@ TEST_F(LooperTest, PollOnce_WhenCallbackReturnsFalse_CallbackShouldNotBeInvokedA << "signal should actually have been written"; EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. equal zero because FD was already signalled"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because FD was signalled"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because FD was signalled"; EXPECT_EQ(1, handler.callbackCount) << "callback should be invoked"; @@ -326,8 +326,8 @@ TEST_F(LooperTest, PollOnce_WhenCallbackReturnsFalse_CallbackShouldNotBeInvokedA << "signal should actually have been written"; EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. equal zero because timeout was zero"; - EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result) - << "pollOnce result should be ALOOPER_POLL_TIMEOUT"; + EXPECT_EQ(Looper::POLL_TIMEOUT, result) + << "pollOnce result should be Looper::POLL_TIMEOUT"; EXPECT_EQ(1, handler.callbackCount) << "callback should not be invoked this time"; } @@ -339,7 +339,7 @@ TEST_F(LooperTest, PollOnce_WhenNonCallbackFdIsSignalled_ReturnsIdent) { Pipe pipe; pipe.writeSignal(); - mLooper->addFd(pipe.receiveFd, expectedIdent, ALOOPER_EVENT_INPUT, NULL, expectedData); + mLooper->addFd(pipe.receiveFd, expectedIdent, Looper::EVENT_INPUT, NULL, expectedData); StopWatch stopWatch("pollOnce"); int fd; @@ -356,15 +356,15 @@ TEST_F(LooperTest, PollOnce_WhenNonCallbackFdIsSignalled_ReturnsIdent) { << "pollOnce result should be the ident of the FD that was signalled"; EXPECT_EQ(pipe.receiveFd, fd) << "pollOnce should have returned the received pipe fd"; - EXPECT_EQ(ALOOPER_EVENT_INPUT, events) - << "pollOnce should have returned ALOOPER_EVENT_INPUT as events"; + EXPECT_EQ(Looper::EVENT_INPUT, events) + << "pollOnce should have returned Looper::EVENT_INPUT as events"; EXPECT_EQ(expectedData, data) << "pollOnce should have returned the data"; } TEST_F(LooperTest, AddFd_WhenCallbackAdded_ReturnsOne) { Pipe pipe; - int result = mLooper->addFd(pipe.receiveFd, 0, ALOOPER_EVENT_INPUT, NULL, NULL); + int result = mLooper->addFd(pipe.receiveFd, 0, Looper::EVENT_INPUT, NULL, NULL); EXPECT_EQ(1, result) << "addFd should return 1 because FD was added"; @@ -372,7 +372,7 @@ TEST_F(LooperTest, AddFd_WhenCallbackAdded_ReturnsOne) { TEST_F(LooperTest, AddFd_WhenIdentIsNegativeAndCallbackIsNull_ReturnsError) { Pipe pipe; - int result = mLooper->addFd(pipe.receiveFd, -1, ALOOPER_EVENT_INPUT, NULL, NULL); + int result = mLooper->addFd(pipe.receiveFd, -1, Looper::EVENT_INPUT, NULL, NULL); EXPECT_EQ(-1, result) << "addFd should return -1 because arguments were invalid"; @@ -397,7 +397,7 @@ TEST_F(LooperTest, RemoveFd_WhenCallbackNotAdded_ReturnsZero) { TEST_F(LooperTest, RemoveFd_WhenCallbackAddedThenRemovedTwice_ReturnsOnceFirstTimeAndReturnsZeroSecondTime) { Pipe pipe; StubCallbackHandler handler(false); - handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT); + handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT); // First time. int result = mLooper->removeFd(pipe.receiveFd); @@ -417,8 +417,8 @@ TEST_F(LooperTest, PollOnce_WhenCallbackAddedTwice_OnlySecondCallbackShouldBeInv StubCallbackHandler handler1(true); StubCallbackHandler handler2(true); - handler1.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT); - handler2.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT); // replace it + handler1.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT); + handler2.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT); // replace it pipe.writeSignal(); // would cause FD to be considered signalled StopWatch stopWatch("pollOnce"); @@ -429,8 +429,8 @@ TEST_F(LooperTest, PollOnce_WhenCallbackAddedTwice_OnlySecondCallbackShouldBeInv << "signal should actually have been written"; EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. zero because FD was already signalled"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because FD was signalled"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because FD was signalled"; EXPECT_EQ(0, handler1.callbackCount) << "original handler callback should not be invoked because it was replaced"; EXPECT_EQ(1, handler2.callbackCount) @@ -447,8 +447,8 @@ TEST_F(LooperTest, SendMessage_WhenOneMessageIsEnqueue_ShouldInvokeHandlerDuring EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. zero because message was already sent"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because message was sent"; EXPECT_EQ(size_t(1), handler->messages.size()) << "handled message"; EXPECT_EQ(MSG_TEST1, handler->messages[0].what) @@ -469,8 +469,8 @@ TEST_F(LooperTest, SendMessage_WhenMultipleMessagesAreEnqueued_ShouldInvokeHandl EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. zero because message was already sent"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because message was sent"; EXPECT_EQ(size_t(3), handler1->messages.size()) << "handled message"; EXPECT_EQ(MSG_TEST1, handler1->messages[0].what) @@ -495,8 +495,8 @@ TEST_F(LooperTest, SendMessageDelayed_WhenSentToTheFuture_ShouldInvokeHandlerAft EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "first poll should end quickly because next message timeout was computed"; - EXPECT_EQ(ALOOPER_POLL_WAKE, result) - << "pollOnce result should be ALOOPER_POLL_WAKE due to wakeup"; + EXPECT_EQ(Looper::POLL_WAKE, result) + << "pollOnce result should be Looper::POLL_WAKE due to wakeup"; EXPECT_EQ(size_t(0), handler->messages.size()) << "no message handled yet"; @@ -509,16 +509,16 @@ TEST_F(LooperTest, SendMessageDelayed_WhenSentToTheFuture_ShouldInvokeHandlerAft << "handled message"; EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS) << "second poll should end around the time of the delayed message dispatch"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because message was sent"; result = mLooper->pollOnce(100); elapsedMillis = ns2ms(stopWatch.elapsedTime()); EXPECT_NEAR(100 + 100, elapsedMillis, TIMING_TOLERANCE_MS) << "third poll should timeout"; - EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result) - << "pollOnce result should be ALOOPER_POLL_TIMEOUT because there were no messages left"; + EXPECT_EQ(Looper::POLL_TIMEOUT, result) + << "pollOnce result should be Looper::POLL_TIMEOUT because there were no messages left"; } TEST_F(LooperTest, SendMessageDelayed_WhenSentToThePast_ShouldInvokeHandlerDuringNextPoll) { @@ -531,8 +531,8 @@ TEST_F(LooperTest, SendMessageDelayed_WhenSentToThePast_ShouldInvokeHandlerDurin EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. zero because message was already sent"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because message was sent"; EXPECT_EQ(size_t(1), handler->messages.size()) << "handled message"; EXPECT_EQ(MSG_TEST1, handler->messages[0].what) @@ -549,8 +549,8 @@ TEST_F(LooperTest, SendMessageDelayed_WhenSentToThePresent_ShouldInvokeHandlerDu EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. zero because message was already sent"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because message was sent"; EXPECT_EQ(size_t(1), handler->messages.size()) << "handled message"; EXPECT_EQ(MSG_TEST1, handler->messages[0].what) @@ -568,8 +568,8 @@ TEST_F(LooperTest, SendMessageAtTime_WhenSentToTheFuture_ShouldInvokeHandlerAfte EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "first poll should end quickly because next message timeout was computed"; - EXPECT_EQ(ALOOPER_POLL_WAKE, result) - << "pollOnce result should be ALOOPER_POLL_WAKE due to wakeup"; + EXPECT_EQ(Looper::POLL_WAKE, result) + << "pollOnce result should be Looper::POLL_WAKE due to wakeup"; EXPECT_EQ(size_t(0), handler->messages.size()) << "no message handled yet"; @@ -582,16 +582,16 @@ TEST_F(LooperTest, SendMessageAtTime_WhenSentToTheFuture_ShouldInvokeHandlerAfte << "handled message"; EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS) << "second poll should end around the time of the delayed message dispatch"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because message was sent"; result = mLooper->pollOnce(100); elapsedMillis = ns2ms(stopWatch.elapsedTime()); EXPECT_NEAR(100 + 100, elapsedMillis, TIMING_TOLERANCE_MS) << "third poll should timeout"; - EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result) - << "pollOnce result should be ALOOPER_POLL_TIMEOUT because there were no messages left"; + EXPECT_EQ(Looper::POLL_TIMEOUT, result) + << "pollOnce result should be Looper::POLL_TIMEOUT because there were no messages left"; } TEST_F(LooperTest, SendMessageAtTime_WhenSentToThePast_ShouldInvokeHandlerDuringNextPoll) { @@ -605,8 +605,8 @@ TEST_F(LooperTest, SendMessageAtTime_WhenSentToThePast_ShouldInvokeHandlerDuring EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. zero because message was already sent"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because message was sent"; EXPECT_EQ(size_t(1), handler->messages.size()) << "handled message"; EXPECT_EQ(MSG_TEST1, handler->messages[0].what) @@ -624,8 +624,8 @@ TEST_F(LooperTest, SendMessageAtTime_WhenSentToThePresent_ShouldInvokeHandlerDur EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. zero because message was already sent"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because message was sent"; EXPECT_EQ(size_t(1), handler->messages.size()) << "handled message"; EXPECT_EQ(MSG_TEST1, handler->messages[0].what) @@ -645,15 +645,15 @@ TEST_F(LooperTest, RemoveMessage_WhenRemovingAllMessagesForHandler_ShouldRemoveT EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. zero because message was sent so looper was awoken"; - EXPECT_EQ(ALOOPER_POLL_WAKE, result) - << "pollOnce result should be ALOOPER_POLL_WAKE because looper was awoken"; + EXPECT_EQ(Looper::POLL_WAKE, result) + << "pollOnce result should be Looper::POLL_WAKE because looper was awoken"; EXPECT_EQ(size_t(0), handler->messages.size()) << "no messages to handle"; result = mLooper->pollOnce(0); - EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result) - << "pollOnce result should be ALOOPER_POLL_TIMEOUT because there was nothing to do"; + EXPECT_EQ(Looper::POLL_TIMEOUT, result) + << "pollOnce result should be Looper::POLL_TIMEOUT because there was nothing to do"; EXPECT_EQ(size_t(0), handler->messages.size()) << "no messages to handle"; } @@ -673,8 +673,8 @@ TEST_F(LooperTest, RemoveMessage_WhenRemovingSomeMessagesForHandler_ShouldRemove EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS) << "elapsed time should approx. zero because message was sent so looper was awoken"; - EXPECT_EQ(ALOOPER_POLL_CALLBACK, result) - << "pollOnce result should be ALOOPER_POLL_CALLBACK because two messages were sent"; + EXPECT_EQ(Looper::POLL_CALLBACK, result) + << "pollOnce result should be Looper::POLL_CALLBACK because two messages were sent"; EXPECT_EQ(size_t(2), handler->messages.size()) << "no messages to handle"; EXPECT_EQ(MSG_TEST2, handler->messages[0].what) @@ -684,8 +684,8 @@ TEST_F(LooperTest, RemoveMessage_WhenRemovingSomeMessagesForHandler_ShouldRemove result = mLooper->pollOnce(0); - EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result) - << "pollOnce result should be ALOOPER_POLL_TIMEOUT because there was nothing to do"; + EXPECT_EQ(Looper::POLL_TIMEOUT, result) + << "pollOnce result should be Looper::POLL_TIMEOUT because there was nothing to do"; EXPECT_EQ(size_t(2), handler->messages.size()) << "no more messages to handle"; } |