summaryrefslogtreecommitdiffstats
path: root/libutils
diff options
context:
space:
mode:
Diffstat (limited to 'libutils')
-rw-r--r--libutils/Android.mk28
-rw-r--r--libutils/FileMap.cpp53
-rw-r--r--libutils/String8.cpp2
-rw-r--r--libutils/SystemClock.cpp2
-rw-r--r--libutils/Threads.cpp98
-rw-r--r--libutils/Timers.cpp11
-rw-r--r--libutils/Tokenizer.cpp6
-rw-r--r--libutils/Unicode.cpp20
-rw-r--r--libutils/misc.cpp8
-rw-r--r--libutils/tests/Android.mk40
-rw-r--r--libutils/tests/BasicHashtable_test.cpp19
-rw-r--r--libutils/tests/LruCache_test.cpp15
12 files changed, 124 insertions, 178 deletions
diff --git a/libutils/Android.mk b/libutils/Android.mk
index 4127b99..d3b2284 100644
--- a/libutils/Android.mk
+++ b/libutils/Android.mk
@@ -14,9 +14,6 @@
LOCAL_PATH:= $(call my-dir)
-# libutils is a little unique: It's built twice, once for the host
-# and once for the device.
-
commonSources:= \
BasicHashtable.cpp \
BlobCache.cpp \
@@ -42,7 +39,7 @@ commonSources:= \
Tokenizer.cpp \
Unicode.cpp \
VectorImpl.cpp \
- misc.cpp
+ misc.cpp \
host_commonCflags := -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -Werror
@@ -53,13 +50,6 @@ host_commonCflags += -DMB_CUR_MAX=1
endif
endif
-host_commonLdlibs :=
-
-ifeq ($(TARGET_OS),linux)
-host_commonLdlibs += -lrt -ldl
-endif
-
-
# For the host
# =====================================================
include $(CLEAR_VARS)
@@ -67,6 +57,9 @@ LOCAL_SRC_FILES:= $(commonSources)
ifeq ($(HOST_OS), linux)
LOCAL_SRC_FILES += Looper.cpp
endif
+ifeq ($(HOST_OS),darwin)
+LOCAL_CFLAGS += -Wno-unused-parameter
+endif
LOCAL_MODULE:= libutils
LOCAL_STATIC_LIBRARIES := liblog
LOCAL_CFLAGS += $(host_commonCflags)
@@ -90,10 +83,6 @@ LOCAL_CFLAGS += -DALIGN_DOUBLE
endif
LOCAL_CFLAGS += -Werror
-LOCAL_C_INCLUDES += \
- bionic/libc \
- external/zlib
-
LOCAL_STATIC_LIBRARIES := \
libcutils
@@ -102,8 +91,6 @@ LOCAL_SHARED_LIBRARIES := \
liblog \
libdl
-include external/stlport/libstlport.mk
-
LOCAL_MODULE:= libutils
include $(BUILD_STATIC_LIBRARY)
@@ -119,8 +106,6 @@ LOCAL_SHARED_LIBRARIES := \
liblog
LOCAL_CFLAGS := -Werror
-include external/stlport/libstlport.mk
-
include $(BUILD_SHARED_LIBRARY)
# Include subdirectory makefiles
@@ -139,8 +124,5 @@ LOCAL_SHARED_LIBRARIES := liblog
LOCAL_SRC_FILES := SharedBufferTest.cpp
include $(BUILD_HOST_NATIVE_TEST)
-# If we're building with ONE_SHOT_MAKEFILE (mm, mmm), then what the framework
-# team really wants is to build the stuff defined by this makefile.
-ifeq (,$(ONE_SHOT_MAKEFILE))
+# Build the tests in the tests/ subdirectory.
include $(call first-makefiles-under,$(LOCAL_PATH))
-endif
diff --git a/libutils/FileMap.cpp b/libutils/FileMap.cpp
index f8d6bda..91e45d8 100644
--- a/libutils/FileMap.cpp
+++ b/libutils/FileMap.cpp
@@ -23,7 +23,7 @@
#include <utils/FileMap.h>
#include <utils/Log.h>
-#if defined(HAVE_WIN32_FILEMAP) && !defined(__USE_MINGW_ANSI_STDIO)
+#if defined(__MINGW32__) && !defined(__USE_MINGW_ANSI_STDIO)
# define PRId32 "I32d"
# define PRIx32 "I32x"
# define PRId64 "I64d"
@@ -33,7 +33,7 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef HAVE_POSIX_FILEMAP
+#if !defined(__MINGW32__)
#include <sys/mman.h>
#endif
@@ -48,7 +48,7 @@ using namespace android;
// Constructor. Create an empty object.
FileMap::FileMap(void)
- : mRefCount(1), mFileName(NULL), mBasePtr(NULL), mBaseLength(0),
+ : mFileName(NULL), mBasePtr(NULL), mBaseLength(0),
mDataPtr(NULL), mDataLength(0)
{
}
@@ -56,20 +56,10 @@ FileMap::FileMap(void)
// Destructor.
FileMap::~FileMap(void)
{
- assert(mRefCount == 0);
-
- //printf("+++ removing FileMap %p %zu\n", mDataPtr, mDataLength);
-
- mRefCount = -100; // help catch double-free
if (mFileName != NULL) {
free(mFileName);
}
-#ifdef HAVE_POSIX_FILEMAP
- if (mBasePtr && munmap(mBasePtr, mBaseLength) != 0) {
- ALOGD("munmap(%p, %zu) failed\n", mBasePtr, mBaseLength);
- }
-#endif
-#ifdef HAVE_WIN32_FILEMAP
+#if defined(__MINGW32__)
if (mBasePtr && UnmapViewOfFile(mBasePtr) == 0) {
ALOGD("UnmapViewOfFile(%p) failed, error = %" PRId32 "\n", mBasePtr,
GetLastError() );
@@ -77,6 +67,10 @@ FileMap::~FileMap(void)
if (mFileMapping != INVALID_HANDLE_VALUE) {
CloseHandle(mFileMapping);
}
+#else
+ if (mBasePtr && munmap(mBasePtr, mBaseLength) != 0) {
+ ALOGD("munmap(%p, %zu) failed\n", mBasePtr, mBaseLength);
+ }
#endif
}
@@ -90,7 +84,7 @@ FileMap::~FileMap(void)
bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t length,
bool readOnly)
{
-#ifdef HAVE_WIN32_FILEMAP
+#if defined(__MINGW32__)
int adjust;
off64_t adjOffset;
size_t adjLength;
@@ -128,35 +122,27 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le
mFileMapping = INVALID_HANDLE_VALUE;
return false;
}
-#endif
-#ifdef HAVE_POSIX_FILEMAP
+#else // !defined(__MINGW32__)
int prot, flags, adjust;
off64_t adjOffset;
size_t adjLength;
void* ptr;
- assert(mRefCount == 1);
assert(fd >= 0);
assert(offset >= 0);
assert(length > 0);
// init on first use
if (mPageSize == -1) {
-#if NOT_USING_KLIBC
mPageSize = sysconf(_SC_PAGESIZE);
if (mPageSize == -1) {
ALOGE("could not get _SC_PAGESIZE\n");
return false;
}
-#else
- // this holds for Linux, Darwin, Cygwin, and doesn't pain the ARM
- mPageSize = 4096;
-#endif
}
- adjust = offset % mPageSize;
-try_again:
+ adjust = offset % mPageSize;
adjOffset = offset - adjust;
adjLength = length + adjust;
@@ -167,19 +153,12 @@ try_again:
ptr = mmap(NULL, adjLength, prot, flags, fd, adjOffset);
if (ptr == MAP_FAILED) {
- // Cygwin does not seem to like file mapping files from an offset.
- // So if we fail, try again with offset zero
- if (adjOffset > 0) {
- adjust = offset;
- goto try_again;
- }
-
ALOGE("mmap(%lld,%zu) failed: %s\n",
(long long)adjOffset, adjLength, strerror(errno));
return false;
}
mBasePtr = ptr;
-#endif // HAVE_POSIX_FILEMAP
+#endif // !defined(__MINGW32__)
mFileName = origFileName != NULL ? strdup(origFileName) : NULL;
mBaseLength = adjLength;
@@ -196,9 +175,9 @@ try_again:
}
// Provide guidance to the system.
+#if !defined(_WIN32)
int FileMap::advise(MapAdvice advice)
{
-#if HAVE_MADVISE
int cc, sysAdvice;
switch (advice) {
@@ -216,7 +195,11 @@ int FileMap::advise(MapAdvice advice)
if (cc != 0)
ALOGW("madvise(%d) failed: %s\n", sysAdvice, strerror(errno));
return cc;
+}
+
#else
+int FileMap::advise(MapAdvice /* advice */)
+{
return -1;
-#endif // HAVE_MADVISE
}
+#endif
diff --git a/libutils/String8.cpp b/libutils/String8.cpp
index d4f5c78..ad65fdb 100644
--- a/libutils/String8.cpp
+++ b/libutils/String8.cpp
@@ -430,7 +430,7 @@ bool String8::removeAll(const char* other) {
next = len;
}
- memcpy(buf + tail, buf + index + skip, next - index - skip);
+ memmove(buf + tail, buf + index + skip, next - index - skip);
tail += next - index - skip;
index = next;
}
diff --git a/libutils/SystemClock.cpp b/libutils/SystemClock.cpp
index dbad581..ac3dd98 100644
--- a/libutils/SystemClock.cpp
+++ b/libutils/SystemClock.cpp
@@ -68,7 +68,7 @@ int64_t elapsedRealtime()
*/
#define DEBUG_TIMESTAMP 0
-#if DEBUG_TIMESTAMP && defined(ARCH_ARM)
+#if DEBUG_TIMESTAMP && defined(__arm__)
static inline void checkTimeStamps(int64_t timestamp,
int64_t volatile *prevTimestampPtr,
int volatile *prevMethodPtr,
diff --git a/libutils/Threads.cpp b/libutils/Threads.cpp
index b09d510..1e014c6 100644
--- a/libutils/Threads.cpp
+++ b/libutils/Threads.cpp
@@ -24,21 +24,18 @@
#include <stdlib.h>
#include <unistd.h>
-#if defined(HAVE_PTHREADS)
+#if !defined(_WIN32)
# include <pthread.h>
# include <sched.h>
# include <sys/resource.h>
-#ifdef HAVE_ANDROID_OS
-# include <private/bionic_pthread.h>
-#endif
-#elif defined(HAVE_WIN32_THREADS)
+#else
# include <windows.h>
# include <stdint.h>
# include <process.h>
# define HAVE_CREATETHREAD // Cygwin, vs. HAVE__BEGINTHREADEX for MinGW
#endif
-#if defined(HAVE_PRCTL)
+#if defined(__linux__)
#include <sys/prctl.h>
#endif
@@ -62,7 +59,7 @@
using namespace android;
// ----------------------------------------------------------------------------
-#if defined(HAVE_PTHREADS)
+#if !defined(_WIN32)
// ----------------------------------------------------------------------------
/*
@@ -93,7 +90,7 @@ struct thread_data_t {
} else {
set_sched_policy(0, SP_FOREGROUND);
}
-
+
if (name) {
androidSetThreadName(name);
free(name);
@@ -103,7 +100,7 @@ struct thread_data_t {
};
void androidSetThreadName(const char* name) {
-#if defined(HAVE_PRCTL)
+#if defined(__linux__)
// Mac OS doesn't have this, and we build libutil for the host too
int hasAt = 0;
int hasDot = 0;
@@ -130,7 +127,7 @@ int androidCreateRawThreadEtc(android_thread_func_t entryFunction,
size_t threadStackSize,
android_thread_id_t *threadId)
{
- pthread_attr_t attr;
+ pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
@@ -149,14 +146,14 @@ int androidCreateRawThreadEtc(android_thread_func_t entryFunction,
t->entryFunction = entryFunction;
t->userData = userData;
entryFunction = (android_thread_func_t)&thread_data_t::trampoline;
- userData = t;
+ userData = t;
}
#endif
if (threadStackSize) {
pthread_attr_setstacksize(&attr, threadStackSize);
}
-
+
errno = 0;
pthread_t thread;
int result = pthread_create(&thread, &attr,
@@ -191,7 +188,7 @@ android_thread_id_t androidGetThreadId()
}
// ----------------------------------------------------------------------------
-#elif defined(HAVE_WIN32_THREADS)
+#else // !defined(_WIN32)
// ----------------------------------------------------------------------------
/*
@@ -271,9 +268,7 @@ android_thread_id_t androidGetThreadId()
}
// ----------------------------------------------------------------------------
-#else
-#error "Threads not supported"
-#endif
+#endif // !defined(_WIN32)
// ----------------------------------------------------------------------------
@@ -306,21 +301,12 @@ void androidSetCreateThreadFunc(android_create_thread_fn func)
gCreateThreadFn = func;
}
-pid_t androidGetTid()
-{
-#ifdef HAVE_GETTID
- return gettid();
-#else
- return getpid();
-#endif
-}
-
#ifdef HAVE_ANDROID_OS
int androidSetThreadPriority(pid_t tid, int pri)
{
int rc = 0;
-
-#if defined(HAVE_PTHREADS)
+
+#if !defined(_WIN32)
int lasterr = 0;
if (pri >= ANDROID_PRIORITY_BACKGROUND) {
@@ -339,12 +325,12 @@ int androidSetThreadPriority(pid_t tid, int pri)
errno = lasterr;
}
#endif
-
+
return rc;
}
int androidGetThreadPriority(pid_t tid) {
-#if defined(HAVE_PTHREADS)
+#if !defined(_WIN32)
return getpriority(PRIO_PROCESS, tid);
#else
return ANDROID_PRIORITY_NORMAL;
@@ -361,9 +347,9 @@ namespace android {
* ===========================================================================
*/
-#if defined(HAVE_PTHREADS)
+#if !defined(_WIN32)
// implemented as inlines in threads.h
-#elif defined(HAVE_WIN32_THREADS)
+#else
Mutex::Mutex()
{
@@ -425,9 +411,7 @@ status_t Mutex::tryLock()
return (dwWaitResult == WAIT_OBJECT_0) ? 0 : -1;
}
-#else
-#error "Somebody forgot to implement threads for this platform."
-#endif
+#endif // !defined(_WIN32)
/*
@@ -436,9 +420,9 @@ status_t Mutex::tryLock()
* ===========================================================================
*/
-#if defined(HAVE_PTHREADS)
+#if !defined(_WIN32)
// implemented as inlines in threads.h
-#elif defined(HAVE_WIN32_THREADS)
+#else
/*
* Windows doesn't have a condition variable solution. It's possible
@@ -486,7 +470,7 @@ typedef struct WinCondition {
//printf("+++ wait: incr waitersCount to %d (tid=%ld)\n",
// condState->waitersCount, getThreadId());
LeaveCriticalSection(&condState->waitersCountLock);
-
+
DWORD timeout = INFINITE;
if (abstime) {
nsecs_t reltime = *abstime - systemTime();
@@ -494,27 +478,27 @@ typedef struct WinCondition {
reltime = 0;
timeout = reltime/1000000;
}
-
+
// Atomically release the external mutex and wait on the semaphore.
DWORD res =
SignalObjectAndWait(hMutex, condState->sema, timeout, FALSE);
-
+
//printf("+++ wait: awake (tid=%ld)\n", getThreadId());
-
+
// Reacquire lock to avoid race conditions.
EnterCriticalSection(&condState->waitersCountLock);
-
+
// No longer waiting.
condState->waitersCount--;
-
+
// Check to see if we're the last waiter after a broadcast.
bool lastWaiter = (condState->wasBroadcast && condState->waitersCount == 0);
-
+
//printf("+++ wait: lastWaiter=%d (wasBc=%d wc=%d)\n",
// lastWaiter, condState->wasBroadcast, condState->waitersCount);
-
+
LeaveCriticalSection(&condState->waitersCountLock);
-
+
// If we're the last waiter thread during this particular broadcast
// then signal broadcast() that we're all awake. It'll drop the
// internal mutex.
@@ -530,11 +514,11 @@ typedef struct WinCondition {
// Grab the internal mutex.
WaitForSingleObject(condState->internalMutex, INFINITE);
}
-
+
// Release the internal and grab the external.
ReleaseMutex(condState->internalMutex);
WaitForSingleObject(hMutex, INFINITE);
-
+
return res == WAIT_OBJECT_0 ? NO_ERROR : -1;
}
} WinCondition;
@@ -577,7 +561,7 @@ status_t Condition::wait(Mutex& mutex)
{
WinCondition* condState = (WinCondition*) mState;
HANDLE hMutex = (HANDLE) mutex.mState;
-
+
return ((WinCondition*)mState)->wait(condState, hMutex, NULL);
}
@@ -659,9 +643,7 @@ void Condition::broadcast()
ReleaseMutex(condState->internalMutex);
}
-#else
-#error "condition variables not supported on this platform"
-#endif
+#endif // !defined(_WIN32)
// ----------------------------------------------------------------------------
@@ -704,7 +686,7 @@ status_t Thread::run(const char* name, int32_t priority, size_t stack)
mStatus = NO_ERROR;
mExitPending = false;
mThread = thread_id_t(-1);
-
+
// hold a strong reference on ourself
mHoldSelf = this;
@@ -718,7 +700,7 @@ status_t Thread::run(const char* name, int32_t priority, size_t stack)
res = androidCreateRawThreadEtc(_threadLoop,
this, name, priority, stack, &mThread);
}
-
+
if (res == false) {
mStatus = UNKNOWN_ERROR; // something happened!
mRunning = false;
@@ -727,7 +709,7 @@ status_t Thread::run(const char* name, int32_t priority, size_t stack)
return UNKNOWN_ERROR;
}
-
+
// Do not refer to mStatus here: The thread is already running (may, in fact
// already have exited with a valid mStatus result). The NO_ERROR indication
// here merely indicates successfully starting the thread and does not
@@ -791,14 +773,14 @@ int Thread::_threadLoop(void* user)
break;
}
}
-
+
// Release our strong reference, to let a chance to the thread
// to die a peaceful death.
strong.clear();
// And immediately, re-acquire a strong reference for the next loop
strong = weak.promote();
} while(strong != 0);
-
+
return 0;
}
@@ -819,7 +801,7 @@ status_t Thread::requestExitAndWait()
return WOULD_BLOCK;
}
-
+
mExitPending = true;
while (mRunning == true) {
@@ -864,7 +846,7 @@ pid_t Thread::getTid() const
pid_t tid;
if (mRunning) {
pthread_t pthread = android_thread_id_t_to_pthread(mThread);
- tid = __pthread_gettid(pthread);
+ tid = pthread_gettid_np(pthread);
} else {
ALOGW("Thread (this=%p): getTid() is undefined before run()", this);
tid = -1;
diff --git a/libutils/Timers.cpp b/libutils/Timers.cpp
index 4687d4d..fb70e15 100644
--- a/libutils/Timers.cpp
+++ b/libutils/Timers.cpp
@@ -18,19 +18,10 @@
// Timer functions.
//
#include <utils/Timers.h>
-#include <utils/Log.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
+#include <limits.h>
#include <sys/time.h>
#include <time.h>
-#include <errno.h>
-#include <limits.h>
-
-#ifdef HAVE_WIN32_THREADS
-#include <windows.h>
-#endif
#if defined(HAVE_ANDROID_OS)
nsecs_t systemTime(int clock)
diff --git a/libutils/Tokenizer.cpp b/libutils/Tokenizer.cpp
index 7067533..610002f 100644
--- a/libutils/Tokenizer.cpp
+++ b/libutils/Tokenizer.cpp
@@ -43,9 +43,7 @@ Tokenizer::Tokenizer(const String8& filename, FileMap* fileMap, char* buffer,
}
Tokenizer::~Tokenizer() {
- if (mFileMap) {
- mFileMap->release();
- }
+ delete mFileMap;
if (mOwnBuffer) {
delete[] mBuffer;
}
@@ -74,7 +72,7 @@ status_t Tokenizer::open(const String8& filename, Tokenizer** outTokenizer) {
fileMap->advise(FileMap::SEQUENTIAL);
buffer = static_cast<char*>(fileMap->getDataPtr());
} else {
- fileMap->release();
+ delete fileMap;
fileMap = NULL;
// Fall back to reading into a buffer since we can't mmap files in sysfs.
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp
index 378d2a7..fb876c9 100644
--- a/libutils/Unicode.cpp
+++ b/libutils/Unicode.cpp
@@ -24,17 +24,10 @@
# undef nhtos
# undef htons
-# ifdef HAVE_LITTLE_ENDIAN
-# define ntohl(x) ( ((x) << 24) | (((x) >> 24) & 255) | (((x) << 8) & 0xff0000) | (((x) >> 8) & 0xff00) )
-# define htonl(x) ntohl(x)
-# define ntohs(x) ( (((x) << 8) & 0xff00) | (((x) >> 8) & 255) )
-# define htons(x) ntohs(x)
-# else
-# define ntohl(x) (x)
-# define htonl(x) (x)
-# define ntohs(x) (x)
-# define htons(x) (x)
-# endif
+# define ntohl(x) ( ((x) << 24) | (((x) >> 24) & 255) | (((x) << 8) & 0xff0000) | (((x) >> 8) & 0xff00) )
+# define htonl(x) ntohl(x)
+# define ntohs(x) ( (((x) << 8) & 0xff00) | (((x) >> 8) & 255) )
+# define htons(x) ntohs(x)
#else
# include <netinet/in.h>
#endif
@@ -47,8 +40,9 @@ static const char32_t kByteMark = 0x00000080;
// Surrogates aren't valid for UTF-32 characters, so define some
// constants that will let us screen them out.
static const char32_t kUnicodeSurrogateHighStart = 0x0000D800;
-static const char32_t kUnicodeSurrogateHighEnd = 0x0000DBFF;
-static const char32_t kUnicodeSurrogateLowStart = 0x0000DC00;
+// Unused, here for completeness:
+// static const char32_t kUnicodeSurrogateHighEnd = 0x0000DBFF;
+// static const char32_t kUnicodeSurrogateLowStart = 0x0000DC00;
static const char32_t kUnicodeSurrogateLowEnd = 0x0000DFFF;
static const char32_t kUnicodeSurrogateStart = kUnicodeSurrogateHighStart;
static const char32_t kUnicodeSurrogateEnd = kUnicodeSurrogateLowEnd;
diff --git a/libutils/misc.cpp b/libutils/misc.cpp
index 58eb499..ed1ba23 100644
--- a/libutils/misc.cpp
+++ b/libutils/misc.cpp
@@ -27,7 +27,7 @@
#include <errno.h>
#include <stdio.h>
-#if defined(HAVE_PTHREADS)
+#if !defined(_WIN32)
# include <pthread.h>
#endif
@@ -42,13 +42,13 @@ struct sysprop_change_callback_info {
int priority;
};
-#if defined(HAVE_PTHREADS)
+#if !defined(_WIN32)
static pthread_mutex_t gSyspropMutex = PTHREAD_MUTEX_INITIALIZER;
static Vector<sysprop_change_callback_info>* gSyspropList = NULL;
#endif
void add_sysprop_change_callback(sysprop_change_callback cb, int priority) {
-#if defined(HAVE_PTHREADS)
+#if !defined(_WIN32)
pthread_mutex_lock(&gSyspropMutex);
if (gSyspropList == NULL) {
gSyspropList = new Vector<sysprop_change_callback_info>();
@@ -72,7 +72,7 @@ void add_sysprop_change_callback(sysprop_change_callback cb, int priority) {
}
void report_sysprop_change() {
-#if defined(HAVE_PTHREADS)
+#if !defined(_WIN32)
pthread_mutex_lock(&gSyspropMutex);
Vector<sysprop_change_callback_info> listeners;
if (gSyspropList != NULL) {
diff --git a/libutils/tests/Android.mk b/libutils/tests/Android.mk
index caedaff..7cfad89 100644
--- a/libutils/tests/Android.mk
+++ b/libutils/tests/Android.mk
@@ -1,9 +1,27 @@
+#
+# Copyright (C) 2014 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.
+#
+
# Build the unit tests.
LOCAL_PATH := $(call my-dir)
+
include $(CLEAR_VARS)
-# Build the unit tests.
-test_src_files := \
+LOCAL_MODULE := libutils_tests
+
+LOCAL_SRC_FILES := \
BasicHashtable_test.cpp \
BlobCache_test.cpp \
BitSet_test.cpp \
@@ -11,24 +29,12 @@ test_src_files := \
LruCache_test.cpp \
String8_test.cpp \
Unicode_test.cpp \
- Vector_test.cpp
+ Vector_test.cpp \
-shared_libraries := \
+LOCAL_SHARED_LIBRARIES := \
libz \
liblog \
libcutils \
libutils \
- libstlport
-
-static_libraries := \
- libgtest \
- libgtest_main
-$(foreach file,$(test_src_files), \
- $(eval include $(CLEAR_VARS)) \
- $(eval LOCAL_SHARED_LIBRARIES := $(shared_libraries)) \
- $(eval LOCAL_STATIC_LIBRARIES := $(static_libraries)) \
- $(eval LOCAL_SRC_FILES := $(file)) \
- $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \
- $(eval include $(BUILD_NATIVE_TEST)) \
-)
+include $(BUILD_NATIVE_TEST)
diff --git a/libutils/tests/BasicHashtable_test.cpp b/libutils/tests/BasicHashtable_test.cpp
index a61b1e1..4b3a717 100644
--- a/libutils/tests/BasicHashtable_test.cpp
+++ b/libutils/tests/BasicHashtable_test.cpp
@@ -21,12 +21,12 @@
#include <gtest/gtest.h>
#include <unistd.h>
-namespace android {
+namespace {
typedef int SimpleKey;
typedef int SimpleValue;
-typedef key_value_pair_t<SimpleKey, SimpleValue> SimpleEntry;
-typedef BasicHashtable<SimpleKey, SimpleEntry> SimpleHashtable;
+typedef android::key_value_pair_t<SimpleKey, SimpleValue> SimpleEntry;
+typedef android::BasicHashtable<SimpleKey, SimpleEntry> SimpleHashtable;
struct ComplexKey {
int k;
@@ -56,10 +56,6 @@ struct ComplexKey {
ssize_t ComplexKey::instanceCount = 0;
-template<> inline hash_t hash_type(const ComplexKey& value) {
- return hash_type(value.k);
-}
-
struct ComplexValue {
int v;
@@ -80,9 +76,18 @@ struct ComplexValue {
ssize_t ComplexValue::instanceCount = 0;
+} // namespace
+
+
+namespace android {
+
typedef key_value_pair_t<ComplexKey, ComplexValue> ComplexEntry;
typedef BasicHashtable<ComplexKey, ComplexEntry> ComplexHashtable;
+template<> inline hash_t hash_type(const ComplexKey& value) {
+ return hash_type(value.k);
+}
+
class BasicHashtableTest : public testing::Test {
protected:
virtual void SetUp() {
diff --git a/libutils/tests/LruCache_test.cpp b/libutils/tests/LruCache_test.cpp
index bcbea32..6534211 100644
--- a/libutils/tests/LruCache_test.cpp
+++ b/libutils/tests/LruCache_test.cpp
@@ -20,7 +20,7 @@
#include <cutils/log.h>
#include <gtest/gtest.h>
-namespace android {
+namespace {
typedef int SimpleKey;
typedef const char* StringValue;
@@ -53,10 +53,6 @@ struct ComplexKey {
ssize_t ComplexKey::instanceCount = 0;
-template<> inline hash_t hash_type(const ComplexKey& value) {
- return hash_type(value.k);
-}
-
struct ComplexValue {
int v;
@@ -77,8 +73,17 @@ struct ComplexValue {
ssize_t ComplexValue::instanceCount = 0;
+} // namespace
+
+
+namespace android {
+
typedef LruCache<ComplexKey, ComplexValue> ComplexCache;
+template<> inline android::hash_t hash_type(const ComplexKey& value) {
+ return hash_type(value.k);
+}
+
class EntryRemovedCallback : public OnEntryRemoved<SimpleKey, StringValue> {
public:
EntryRemovedCallback() : callbackCount(0), lastKey(-1), lastValue(NULL) { }