summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-12-14 17:36:29 -0800
committerElliott Hughes <enh@google.com>2015-12-14 17:36:29 -0800
commit8d12a9010bc7f16837dbcb9db7695166d85fc09f (patch)
treec8870bbb89b95ef8fc3956945d3eb64742be1cab
parent076617a2001f80c3c06cd7eacffeeda1030a6fd0 (diff)
downloadextras-8d12a9010bc7f16837dbcb9db7695166d85fc09f.tar.gz
Remove system/extras/tests/bionic.
Everything is now tested better by bionic itself, and as part of CTS. Change-Id: Ie23e50b5ece911b650ad5abda8230bf7a8d3a452
-rw-r--r--tests/bionic/libc/Android.mk82
-rw-r--r--tests/bionic/libc/MODULE_LICENSE_BSD_AND_GPL0
-rw-r--r--tests/bionic/libc/README.TXT24
-rw-r--r--tests/bionic/libc/bionic/test_cond.c97
-rw-r--r--tests/bionic/libc/bionic/test_pthread_cond.c83
-rw-r--r--tests/bionic/libc/common/test_pthread_mutex.c387
-rw-r--r--tests/bionic/libc/common/test_pthread_rwlock.c346
-rwxr-xr-xtests/bionic/libc/run-test.sh185
8 files changed, 0 insertions, 1204 deletions
diff --git a/tests/bionic/libc/Android.mk b/tests/bionic/libc/Android.mk
deleted file mode 100644
index 155a701a..00000000
--- a/tests/bionic/libc/Android.mk
+++ /dev/null
@@ -1,82 +0,0 @@
-# Copyright (C) 2008 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 control file for Bionic's test programs
-# define the BIONIC_TESTS environment variable to build the test programs
-#
-ifdef BIONIC_TESTS
-
-LOCAL_PATH:= $(call my-dir)
-
-# used to define a simple test program and build it as a standalone
-# device executable.
-#
-# you can use EXTRA_CFLAGS to indicate additional CFLAGS to use
-# in the build. the variable will be cleaned on exit
-#
-define device-test
- $(foreach file,$(1), \
- $(eval include $(CLEAR_VARS)) \
- $(eval LOCAL_SRC_FILES := $(file)) \
- $(eval LOCAL_MODULE := $(notdir $(file:%.c=%))) \
- $(eval LOCAL_MODULE := $(LOCAL_MODULE:%.cpp=%)) \
- $(eval LOCAL_CFLAGS += $(EXTRA_CFLAGS)) \
- $(eval LOCAL_LDFLAGS += $(EXTRA_LDLIBS)) \
- $(eval LOCAL_MODULE_TAGS := tests) \
- $(eval include $(BUILD_EXECUTABLE)) \
- ) \
- $(eval EXTRA_CFLAGS :=) \
- $(eval EXTRA_LDLIBS :=)
-endef
-
-# same as 'device-test' but builds a host executable instead
-# you can use EXTRA_LDLIBS to indicate additional linker flags
-#
-define host-test
- $(foreach file,$(1), \
- $(eval include $(CLEAR_VARS)) \
- $(eval LOCAL_SRC_FILES := $(file)) \
- $(eval LOCAL_MODULE := $(notdir $(file:%.c=%))) \
- $(eval LOCAL_MODULE := $(LOCAL_MODULE:%.cpp=%)) \
- $(eval LOCAL_CFLAGS += $(EXTRA_CFLAGS)) \
- $(eval LOCAL_LDLIBS += $(EXTRA_LDLIBS)) \
- $(eval LOCAL_MODULE_TAGS := tests) \
- $(eval include $(BUILD_HOST_EXECUTABLE)) \
- ) \
- $(eval EXTRA_CFLAGS :=) \
- $(eval EXTRA_LDLIBS :=)
-endef
-
-# First, the tests in 'common'
-
-sources := \
- common/test_pthread_mutex.c \
- common/test_pthread_rwlock.c \
-
-# _XOPEN_SOURCE=600 is needed to get pthread_mutexattr_settype() on GLibc
-#
-EXTRA_LDLIBS := -lpthread -lrt
-EXTRA_CFLAGS := -D_XOPEN_SOURCE=600 -DHOST
-$(call host-test, $(sources))
-$(call device-test, $(sources))
-
-# Second, the Bionic-specific tests
-
-sources := \
- bionic/test_cond.c \
- bionic/test_pthread_cond.c \
-
-$(call device-test, $(sources))
-
-endif # BIONIC_TESTS
diff --git a/tests/bionic/libc/MODULE_LICENSE_BSD_AND_GPL b/tests/bionic/libc/MODULE_LICENSE_BSD_AND_GPL
deleted file mode 100644
index e69de29b..00000000
--- a/tests/bionic/libc/MODULE_LICENSE_BSD_AND_GPL
+++ /dev/null
diff --git a/tests/bionic/libc/README.TXT b/tests/bionic/libc/README.TXT
deleted file mode 100644
index c43f93b5..00000000
--- a/tests/bionic/libc/README.TXT
+++ /dev/null
@@ -1,24 +0,0 @@
-This directory contains a set of tests for Android's Bionic C library.
-
-You must define the BIONIC_TESTS environment variable to build these
-test programs. For example, do:
-
- cd system/extras/tests/bionic/libc
- mm BIONIC_TESTS=1
-
-All test programs, except those in the 'other' directory, should exit
-with a status code of 0 in case of success, and 1 in case of failure.
-
-The directory layout is simple:
-
- common/
- Contains tests that can be compiled either with Bionic or another
- C library.
-
- bionic/
- Contains tests that can *only* be compiled against Bionic
-
- other/
- Other unrelated tests. These are not run by the test runner
- program but will be installed to your device nevertheless.
- Put benchmarks and various debug/info stuff there.
diff --git a/tests/bionic/libc/bionic/test_cond.c b/tests/bionic/libc/bionic/test_cond.c
deleted file mode 100644
index 62d96948..00000000
--- a/tests/bionic/libc/bionic/test_cond.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <pthread.h>
-#include <semaphore.h>
-#include <errno.h>
-#include <stdio.h>
-#include <time.h>
-#include <string.h>
-#include <unistd.h>
-
-static pthread_mutex_t lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-static pthread_cond_t wait = PTHREAD_COND_INITIALIZER;
-
-static void* _thread1(void *__u __attribute__((unused)))
-{
- printf("1: obtaining mutex\n");
- pthread_mutex_lock(&lock);
- printf("1: waiting on condition variable\n");
- pthread_cond_wait(&wait, &lock);
- printf("1: releasing mutex\n");
- pthread_mutex_unlock(&lock);
- printf("1: exiting\n");
- return NULL;
-}
-
-static void* _thread2(void *__u __attribute__((unused)))
-{
- int cnt = 2;
- while(cnt--) {
- printf("2: obtaining mutex\n");
- pthread_mutex_lock(&lock);
- printf("2: signaling\n");
- pthread_cond_signal(&wait);
- printf("2: releasing mutex\n");
- pthread_mutex_unlock(&lock);
- }
-
- printf("2: exiting\n");
- return NULL;
-}
-
-typedef void* (*thread_func)(void*);
-static const thread_func thread_routines[] =
-{
- &_thread1,
- &_thread2,
-};
-
-int main(void)
-{
- pthread_t t[2];
- int nn;
- int count = (int)(sizeof t/sizeof t[0]);
-
- for (nn = 0; nn < count; nn++) {
- printf("main: creating thread %d\n", nn+1);
- if (pthread_create( &t[nn], NULL, thread_routines[nn], NULL) < 0) {
- printf("main: could not create thread %d: %s\n", nn+1, strerror(errno));
- return -2;
- }
- }
-
- for (nn = 0; nn < count; nn++) {
- printf("main: joining thread %d\n", nn+1);
- if (pthread_join(t[nn], NULL)) {
- printf("main: could not join thread %d: %s\n", nn+1, strerror(errno));
- return -2;
- }
- }
-
- return 0;
-}
diff --git a/tests/bionic/libc/bionic/test_pthread_cond.c b/tests/bionic/libc/bionic/test_pthread_cond.c
deleted file mode 100644
index 6b13d77f..00000000
--- a/tests/bionic/libc/bionic/test_pthread_cond.c
+++ /dev/null
@@ -1,83 +0,0 @@
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-
-static pthread_cond_t cond1;
-static pthread_cond_t cond2;
-static pthread_mutex_t test_lock = PTHREAD_MUTEX_INITIALIZER;
-
-static void *
-thread1_func(void* arg)
-{
- printf("Thread 1 (arg=%p tid=%d) entered.\n", arg, gettid());
- printf("1 waiting for cond1\n");
- pthread_mutex_lock(&test_lock);
- pthread_cond_wait(&cond1, &test_lock );
- pthread_mutex_unlock(&test_lock);
- printf("Thread 1 done.\n");
- return 0;
-}
-
-static void *
-thread2_func(void* arg)
-{
- printf("Thread 2 (arg=%p tid=%d) entered.\n", arg, gettid());
- printf("2 waiting for cond2\n");
- pthread_mutex_lock(&test_lock);
- pthread_cond_wait(&cond2, &test_lock );
- pthread_mutex_unlock(&test_lock);
-
- printf("Thread 2 done.\n");
- return 0;
-}
-
-static void *
-thread3_func(void* arg)
-{
- printf("Thread 3 (arg=%p tid=%d) entered.\n", arg, gettid());
- printf("3 waiting for cond1\n");
- pthread_mutex_lock(&test_lock);
- pthread_cond_wait(&cond1, &test_lock );
- pthread_mutex_unlock(&test_lock);
- printf("3 Sleeping\n");
- sleep(2);
- printf("3 signal cond2\n");
- pthread_cond_signal(&cond2);
-
- printf("Thread 3 done.\n");
- return 0;
-}
-
-static void *
-thread4_func(void* arg)
-{
- printf("Thread 4 (arg=%p tid=%d) entered.\n", arg, gettid());
- printf("4 Sleeping\n");
- sleep(5);
-
- printf("4 broadcast cond1\n");
- pthread_cond_broadcast(&cond1);
- printf("Thread 4 done.\n");
- return 0;
-}
-
-int main(int argc __unused, const char *argv[] __unused)
-{
- pthread_t t[4];
-
- pthread_cond_init(&cond1, NULL);
- pthread_cond_init(&cond2, NULL);
- pthread_create( &t[0], NULL, thread1_func, (void *)1 );
- pthread_create( &t[1], NULL, thread2_func, (void *)2 );
- pthread_create( &t[2], NULL, thread3_func, (void *)3 );
- pthread_create( &t[3], NULL, thread4_func, (void *)4 );
-
- pthread_join(t[0], NULL);
- pthread_join(t[1], NULL);
- pthread_join(t[2], NULL);
- pthread_join(t[3], NULL);
- return 0;
-}
diff --git a/tests/bionic/libc/common/test_pthread_mutex.c b/tests/bionic/libc/common/test_pthread_mutex.c
deleted file mode 100644
index a84d5be0..00000000
--- a/tests/bionic/libc/common/test_pthread_mutex.c
+++ /dev/null
@@ -1,387 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <pthread.h>
-#include <errno.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-/* Posix states that EDEADLK should be returned in case a deadlock condition
- * is detected with a PTHREAD_MUTEX_ERRORCHECK lock() or trylock(), but
- * GLibc returns EBUSY instead.
- */
-#ifdef HOST
-# define ERRNO_PTHREAD_EDEADLK EBUSY
-#else
-# define ERRNO_PTHREAD_EDEADLK EDEADLK
-#endif
-
-static void __attribute__((noreturn))
-panic(const char* func, const char* format, ...)
-{
- va_list args;
- fprintf(stderr, "%s: ", func);
- va_start(args, format);
- vfprintf(stderr, format, args);
- va_end(args);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-#define PANIC(...) panic(__FUNCTION__,__VA_ARGS__)
-
-static void __attribute__((noreturn))
-error(int errcode, const char* func, const char* format, ...)
-{
- va_list args;
- fprintf(stderr, "%s: ", func);
- va_start(args, format);
- vfprintf(stderr, format, args);
- va_end(args);
- fprintf(stderr, " error=%d: %s\n", errcode, strerror(errcode));
- exit(1);
-}
-
-/* return current time in seconds as floating point value */
-static double
-time_now(void)
-{
- struct timespec ts[1];
-
- clock_gettime(CLOCK_MONOTONIC, ts);
- return (double)ts->tv_sec + ts->tv_nsec/1e9;
-}
-
-static void
-time_sleep(double delay)
-{
- struct timespec ts;
- int ret;
-
- ts.tv_sec = (time_t)delay;
- ts.tv_nsec = (long)((delay - ts.tv_sec)*1e9);
-
- do {
- ret = nanosleep(&ts, &ts);
- } while (ret < 0 && errno == EINTR);
-}
-
-#define ERROR(errcode,...) error((errcode),__FUNCTION__,__VA_ARGS__)
-
-#define TZERO(cond) \
- { int _ret = (cond); if (_ret != 0) ERROR(_ret,"%d:%s", __LINE__, #cond); }
-
-#define TTRUE(cond) \
- { if (!(cond)) PANIC("%d:%s", __LINE__, #cond); }
-
-#define TFALSE(cond) \
- { if (!!(cond)) PANIC("%d:%s", __LINE__, #cond); }
-
-#define TEXPECT_INT(cond,val) \
- { int _ret = (cond); if (_ret != (val)) PANIC("%d:%s returned %d (%d expected)", __LINE__, #cond, _ret, (val)); }
-
-/* perform a simple init/lock/unlock/destroy test on a mutex of given attributes */
-static void do_test_mutex_1(pthread_mutexattr_t *attr)
-{
- int ret;
- pthread_mutex_t lock[1];
-
- TZERO(pthread_mutex_init(lock, attr));
- TZERO(pthread_mutex_lock(lock));
- TZERO(pthread_mutex_unlock(lock));
- TZERO(pthread_mutex_destroy(lock));
-}
-
-static void set_mutexattr_type(pthread_mutexattr_t *attr, int type)
-{
- int newtype;
- TZERO(pthread_mutexattr_settype(attr, type));
- newtype = ~type;
- TZERO(pthread_mutexattr_gettype(attr, &newtype));
- TEXPECT_INT(newtype,type);
-}
-
-/* simple init/lock/unlock/destroy on all mutex types */
-static void do_test_1(void)
-{
- int ret, type;
- pthread_mutexattr_t attr[1];
-
- do_test_mutex_1(NULL);
-
- /* non-shared version */
-
- TZERO(pthread_mutexattr_init(attr));
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_NORMAL);
- do_test_mutex_1(attr);
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_RECURSIVE);
- do_test_mutex_1(attr);
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_ERRORCHECK);
- do_test_mutex_1(attr);
-
- TZERO(pthread_mutexattr_destroy(attr));
-
- /* shared version */
- TZERO(pthread_mutexattr_init(attr));
- TZERO(pthread_mutexattr_setpshared(attr, PTHREAD_PROCESS_SHARED));
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_NORMAL);
- do_test_mutex_1(attr);
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_RECURSIVE);
- do_test_mutex_1(attr);
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_ERRORCHECK);
- do_test_mutex_1(attr);
-
- TZERO(pthread_mutexattr_destroy(attr));
-}
-
-/* perform init/trylock/unlock/destroy then init/lock/trylock/destroy */
-static void do_test_mutex_2(pthread_mutexattr_t *attr)
-{
- pthread_mutex_t lock[1];
-
- TZERO(pthread_mutex_init(lock, attr));
- TZERO(pthread_mutex_trylock(lock));
- TZERO(pthread_mutex_unlock(lock));
- TZERO(pthread_mutex_destroy(lock));
-
- TZERO(pthread_mutex_init(lock, attr));
- TZERO(pthread_mutex_trylock(lock));
- TEXPECT_INT(pthread_mutex_trylock(lock),EBUSY);
- TZERO(pthread_mutex_unlock(lock));
- TZERO(pthread_mutex_destroy(lock));
-}
-
-static void do_test_mutex_2_rec(pthread_mutexattr_t *attr)
-{
- pthread_mutex_t lock[1];
-
- TZERO(pthread_mutex_init(lock, attr));
- TZERO(pthread_mutex_trylock(lock));
- TZERO(pthread_mutex_unlock(lock));
- TZERO(pthread_mutex_destroy(lock));
-
- TZERO(pthread_mutex_init(lock, attr));
- TZERO(pthread_mutex_trylock(lock));
- TZERO(pthread_mutex_trylock(lock));
- TZERO(pthread_mutex_unlock(lock));
- TZERO(pthread_mutex_unlock(lock));
- TZERO(pthread_mutex_destroy(lock));
-}
-
-static void do_test_mutex_2_chk(pthread_mutexattr_t *attr)
-{
- pthread_mutex_t lock[1];
-
- TZERO(pthread_mutex_init(lock, attr));
- TZERO(pthread_mutex_trylock(lock));
- TZERO(pthread_mutex_unlock(lock));
- TZERO(pthread_mutex_destroy(lock));
-
- TZERO(pthread_mutex_init(lock, attr));
- TZERO(pthread_mutex_trylock(lock));
- TEXPECT_INT(pthread_mutex_trylock(lock),ERRNO_PTHREAD_EDEADLK);
- TZERO(pthread_mutex_unlock(lock));
- TZERO(pthread_mutex_destroy(lock));
-}
-
-static void do_test_2(void)
-{
- pthread_mutexattr_t attr[1];
-
- do_test_mutex_2(NULL);
-
- /* non-shared version */
-
- TZERO(pthread_mutexattr_init(attr));
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_NORMAL);
- do_test_mutex_2(attr);
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_RECURSIVE);
- do_test_mutex_2_rec(attr);
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_ERRORCHECK);
- do_test_mutex_2_chk(attr);
-
- TZERO(pthread_mutexattr_destroy(attr));
-
- /* shared version */
- TZERO(pthread_mutexattr_init(attr));
- TZERO(pthread_mutexattr_setpshared(attr, PTHREAD_PROCESS_SHARED));
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_NORMAL);
- do_test_mutex_2(attr);
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_RECURSIVE);
- do_test_mutex_2_rec(attr);
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_ERRORCHECK);
- do_test_mutex_2_chk(attr);
-
- TZERO(pthread_mutexattr_destroy(attr));
-}
-
-/* This is more complex example to test contention of mutexes.
- * Essentially, what happens is this:
- *
- * - main thread creates a mutex and locks it
- * - it then creates thread 1 and thread 2
- *
- * - it then record the current time, sleep for a specific 'waitDelay'
- * then unlock the mutex.
- *
- * - thread 1 locks() the mutex. It shall be stopped for a least 'waitDelay'
- * seconds. It then unlocks the mutex.
- *
- * - thread 2 trylocks() the mutex. In case of failure (EBUSY), it waits
- * for a small amount of time (see 'spinDelay') and tries again, until
- * it succeeds. It then unlocks the mutex.
- *
- * The goal of this test is to verify that thread 1 has been stopped
- * for a sufficiently long time, and that thread 2 has been spinning for
- * the same minimum period. There is no guarantee as to which thread is
- * going to acquire the mutex first.
- */
-typedef struct {
- pthread_mutex_t mutex[1];
- double t0;
- double waitDelay;
- double spinDelay;
-} Test3State;
-
-static void* do_mutex_test_3_t1(void* arg)
-{
- Test3State *s = arg;
- double t1;
-
- TZERO(pthread_mutex_lock(s->mutex));
- t1 = time_now();
- //DEBUG ONLY: printf("t1-s->t0=%g waitDelay=%g\n", t1-s->t0, s->waitDelay);
- TTRUE((t1-s->t0) >= s->waitDelay);
- TZERO(pthread_mutex_unlock(s->mutex));
- return NULL;
-}
-
-static void* do_mutex_test_3_t2(void* arg)
-{
- Test3State *s = arg;
- double t1;
-
- for (;;) {
- int ret = pthread_mutex_trylock(s->mutex);
- if (ret == 0)
- break;
- if (ret == EBUSY) {
- time_sleep(s->spinDelay);
- continue;
- }
- }
- t1 = time_now();
- TTRUE((t1-s->t0) >= s->waitDelay);
- TZERO(pthread_mutex_unlock(s->mutex));
- return NULL;
-}
-
-
-static void do_test_mutex_3(pthread_mutexattr_t *attr, double delay)
-{
- Test3State s[1];
- pthread_t th1, th2;
- void* dummy;
-
- TZERO(pthread_mutex_init(s->mutex, attr));
- s->waitDelay = delay;
- s->spinDelay = delay/20.;
-
- TZERO(pthread_mutex_lock(s->mutex));
-
- pthread_create(&th1, NULL, do_mutex_test_3_t1, s);
- pthread_create(&th2, NULL, do_mutex_test_3_t2, s);
-
- s->t0 = time_now();
- time_sleep(delay);
-
- TZERO(pthread_mutex_unlock(s->mutex));
-
- TZERO(pthread_join(th1, &dummy));
- TZERO(pthread_join(th2, &dummy));
-}
-
-static void do_test_3(double delay)
-{
- pthread_mutexattr_t attr[1];
-
- do_test_mutex_3(NULL, delay);
-
- /* non-shared version */
-
- TZERO(pthread_mutexattr_init(attr));
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_NORMAL);
- do_test_mutex_3(attr, delay);
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_RECURSIVE);
- do_test_mutex_3(attr, delay);
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_ERRORCHECK);
- do_test_mutex_3(attr, delay);
-
- TZERO(pthread_mutexattr_destroy(attr));
-
- /* shared version */
- TZERO(pthread_mutexattr_init(attr));
- TZERO(pthread_mutexattr_setpshared(attr, PTHREAD_PROCESS_SHARED));
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_NORMAL);
- do_test_mutex_3(attr, delay);
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_RECURSIVE);
- do_test_mutex_3(attr, delay);
-
- set_mutexattr_type(attr, PTHREAD_MUTEX_ERRORCHECK);
- do_test_mutex_3(attr, delay);
-
- TZERO(pthread_mutexattr_destroy(attr));
-}
-
-
-int main(void)
-{
- do_test_1();
- do_test_2();
- do_test_3(0.1);
- return 0;
-}
diff --git a/tests/bionic/libc/common/test_pthread_rwlock.c b/tests/bionic/libc/common/test_pthread_rwlock.c
deleted file mode 100644
index 4687e018..00000000
--- a/tests/bionic/libc/common/test_pthread_rwlock.c
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-#include <pthread.h>
-#include <errno.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-/* Posix states that EDEADLK should be returned in case a deadlock condition
- * is detected with a PTHREAD_MUTEX_ERRORCHECK lock() or trylock(), but
- * GLibc returns EBUSY instead.
- */
-#ifdef HOST
-# define ERRNO_PTHREAD_EDEADLK EBUSY
-#else
-# define ERRNO_PTHREAD_EDEADLK EDEADLK
-#endif
-
-static void __attribute__((noreturn))
-panic(const char* func, const char* format, ...)
-{
- va_list args;
- fprintf(stderr, "%s: ", func);
- va_start(args, format);
- vfprintf(stderr, format, args);
- va_end(args);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-#define PANIC(...) panic(__FUNCTION__,__VA_ARGS__)
-
-static void __attribute__((noreturn))
-error(int errcode, const char* func, const char* format, ...)
-{
- va_list args;
- fprintf(stderr, "%s: ", func);
- va_start(args, format);
- vfprintf(stderr, format, args);
- va_end(args);
- fprintf(stderr, " error=%d: %s\n", errcode, strerror(errcode));
- exit(1);
-}
-
-/* return current time in seconds as floating point value */
-static double
-time_now(void)
-{
- struct timespec ts[1];
-
- clock_gettime(CLOCK_MONOTONIC, ts);
- return (double)ts->tv_sec + ts->tv_nsec/1e9;
-}
-
-static void
-time_sleep(double delay)
-{
- struct timespec ts;
- int ret;
-
- ts.tv_sec = (time_t)delay;
- ts.tv_nsec = (long)((delay - ts.tv_sec)*1e9);
-
- do {
- ret = nanosleep(&ts, &ts);
- } while (ret < 0 && errno == EINTR);
-}
-
-#define ERROR(errcode,...) error((errcode),__FUNCTION__,__VA_ARGS__)
-
-#define TZERO(cond) \
- { int _ret = (cond); if (_ret != 0) ERROR(_ret,"%d:%s", __LINE__, #cond); }
-
-#define TTRUE(cond) \
- { if (!(cond)) PANIC("%d:%s", __LINE__, #cond); }
-
-#define TFALSE(cond) \
- { if (!!(cond)) PANIC("%d:%s", __LINE__, #cond); }
-
-#define TEXPECT_INT(cond,val) \
- { int _ret = (cond); if (_ret != (val)) PANIC("%d:%s returned %d (%d expected)", __LINE__, #cond, _ret, (val)); }
-
-/* perform a simple init/lock/unlock/destroy test on a rwlock of given attributes */
-static void do_test_rwlock_rd1(pthread_rwlockattr_t *attr)
-{
- int ret;
- pthread_rwlock_t lock[1];
-
- TZERO(pthread_rwlock_init(lock, attr));
- TZERO(pthread_rwlock_rdlock(lock));
- TZERO(pthread_rwlock_unlock(lock));
- TZERO(pthread_rwlock_destroy(lock));
-}
-
-static void do_test_rwlock_wr1(pthread_rwlockattr_t *attr)
-{
- int ret;
- pthread_rwlock_t lock[1];
-
- TZERO(pthread_rwlock_init(lock, attr));
- TZERO(pthread_rwlock_wrlock(lock));
- TZERO(pthread_rwlock_unlock(lock));
- TZERO(pthread_rwlock_destroy(lock));
-}
-
-static void set_rwlockattr_shared(pthread_rwlockattr_t *attr, int shared)
-{
- int newshared;
- TZERO(pthread_rwlockattr_setpshared(attr, shared));
- newshared = ~shared;
- TZERO(pthread_rwlockattr_getpshared(attr, &newshared));
- TEXPECT_INT(newshared,shared);
-}
-
-/* simple init/lock/unlock/destroy on all rwlock types */
-static void do_test_1(void)
-{
- int ret, type;
- pthread_rwlockattr_t attr[1];
-
- do_test_rwlock_rd1(NULL);
- do_test_rwlock_wr1(NULL);
-
- /* non-shared version */
-
- TZERO(pthread_rwlockattr_init(attr));
-
- set_rwlockattr_shared(attr, PTHREAD_PROCESS_PRIVATE);
- do_test_rwlock_rd1(attr);
- do_test_rwlock_wr1(attr);
-
- set_rwlockattr_shared(attr, PTHREAD_PROCESS_SHARED);
- do_test_rwlock_rd1(attr);
- do_test_rwlock_wr1(attr);
-
- TZERO(pthread_rwlockattr_destroy(attr));
-}
-
-static void do_test_rwlock_rd2_rec(pthread_rwlockattr_t *attr)
-{
- pthread_rwlock_t lock[1];
-
- TZERO(pthread_rwlock_init(lock, attr));
- TZERO(pthread_rwlock_tryrdlock(lock));
- TZERO(pthread_rwlock_unlock(lock));
- TZERO(pthread_rwlock_destroy(lock));
-
- TZERO(pthread_rwlock_init(lock, attr));
- TZERO(pthread_rwlock_tryrdlock(lock));
- TZERO(pthread_rwlock_tryrdlock(lock));
- TZERO(pthread_rwlock_unlock(lock));
- TZERO(pthread_rwlock_unlock(lock));
- TZERO(pthread_rwlock_destroy(lock));
-}
-
-static void do_test_rwlock_wr2_rec(pthread_rwlockattr_t *attr)
-{
- pthread_rwlock_t lock[1];
-
- TZERO(pthread_rwlock_init(lock, attr));
- TZERO(pthread_rwlock_trywrlock(lock));
- TZERO(pthread_rwlock_unlock(lock));
- TZERO(pthread_rwlock_destroy(lock));
-
- TZERO(pthread_rwlock_init(lock, attr));
- TZERO(pthread_rwlock_trywrlock(lock));
-#ifdef HOST
- /* The host implementation (GLibc) does not support recursive
- * write locks */
- TEXPECT_INT(pthread_rwlock_trywrlock(lock),EBUSY);
-#else
- /* Our implementation supports recursive write locks ! */
- TZERO(pthread_rwlock_trywrlock(lock));
- TZERO(pthread_rwlock_unlock(lock));
-#endif
- TZERO(pthread_rwlock_unlock(lock));
- TZERO(pthread_rwlock_destroy(lock));
-}
-
-static void do_test_2(void)
-{
- pthread_rwlockattr_t attr[1];
-
- do_test_rwlock_rd2_rec(NULL);
- do_test_rwlock_wr2_rec(NULL);
-
- /* non-shared version */
-
- TZERO(pthread_rwlockattr_init(attr));
-
- set_rwlockattr_shared(attr, PTHREAD_PROCESS_PRIVATE);
- do_test_rwlock_rd2_rec(attr);
- do_test_rwlock_wr2_rec(attr);
-
- set_rwlockattr_shared(attr, PTHREAD_PROCESS_SHARED);
- do_test_rwlock_rd2_rec(attr);
- do_test_rwlock_wr2_rec(attr);
-
- TZERO(pthread_rwlockattr_destroy(attr));
-}
-
-/* This is more complex example to test contention of rwlockes.
- * Essentially, what happens is this:
- *
- * - main thread creates a rwlock and rdlocks it
- * - it then creates thread 1 and thread 2
- *
- * - it then record the current time, sleep for a specific 'waitDelay'
- * then unlock the rwlock.
- *
- * - thread 1 tryrdlocks() the rwlock. It shall acquire the lock
- * immediately, then release it, then wrlock().
- *
- * - thread 2 trywrlocks() the rwlock. In case of failure (EBUSY), it waits
- * for a small amount of time (see 'spinDelay') and tries again, until
- * it succeeds. It then unlocks the rwlock.
- *
- * The goal of this test is to verify that thread 1 has been stopped
- * for a sufficiently long time (in the wrlock), and that thread 2 has
- * been spinning for the same minimum period. There is no guarantee as
- * to which thread is going to acquire the rwlock first.
- */
-typedef struct {
- pthread_rwlock_t rwlock[1];
- double t0;
- double waitDelay;
- double spinDelay;
-} Test3State;
-
-static void* do_rwlock_test_rd3_t1(void* arg)
-{
- Test3State *s = arg;
- double t1;
-
- /* try-acquire the lock, should succeed immediately */
- TZERO(pthread_rwlock_tryrdlock(s->rwlock));
- TZERO(pthread_rwlock_unlock(s->rwlock));
-
- /* wrlock() the lock, now */
- TZERO(pthread_rwlock_wrlock(s->rwlock));
-
- t1 = time_now();
- //DEBUG ONLY: printf("t1-s->t0=%g waitDelay=%g\n", t1-s->t0, s->waitDelay);
- TTRUE((t1-s->t0) >= s->waitDelay);
- TZERO(pthread_rwlock_unlock(s->rwlock));
- return NULL;
-}
-
-static void* do_rwlock_test_rd3_t2(void* arg)
-{
- Test3State *s = arg;
- double t1;
-
- for (;;) {
- int ret = pthread_rwlock_trywrlock(s->rwlock);
- if (ret == 0)
- break;
- if (ret == EBUSY) {
- time_sleep(s->spinDelay);
- continue;
- }
- }
- t1 = time_now();
- TTRUE((t1-s->t0) >= s->waitDelay);
- TZERO(pthread_rwlock_unlock(s->rwlock));
- return NULL;
-}
-
-
-static void do_test_rwlock_rd3(pthread_rwlockattr_t *attr, double delay)
-{
- Test3State s[1];
- pthread_t th1, th2;
- void* dummy;
-
- TZERO(pthread_rwlock_init(s->rwlock, attr));
- s->waitDelay = delay;
- s->spinDelay = delay/20.;
-
- TZERO(pthread_rwlock_rdlock(s->rwlock));
-
- pthread_create(&th1, NULL, do_rwlock_test_rd3_t1, s);
- pthread_create(&th2, NULL, do_rwlock_test_rd3_t2, s);
-
- s->t0 = time_now();
- time_sleep(delay);
-
- TZERO(pthread_rwlock_unlock(s->rwlock));
-
- TZERO(pthread_join(th1, &dummy));
- TZERO(pthread_join(th2, &dummy));
-}
-
-static void do_test_3(double delay)
-{
- pthread_rwlockattr_t attr[1];
-
- do_test_rwlock_rd3(NULL, delay);
-
- /* non-shared version */
-
- TZERO(pthread_rwlockattr_init(attr));
-
- set_rwlockattr_shared(attr, PTHREAD_PROCESS_PRIVATE);
- do_test_rwlock_rd3(attr, delay);
-
- set_rwlockattr_shared(attr, PTHREAD_PROCESS_SHARED);
- do_test_rwlock_rd3(attr, delay);
-
- TZERO(pthread_rwlockattr_destroy(attr));
-}
-
-
-int main(void)
-{
- do_test_1();
- do_test_2();
- do_test_3(0.1);
- return 0;
-}
diff --git a/tests/bionic/libc/run-test.sh b/tests/bionic/libc/run-test.sh
deleted file mode 100755
index c88c6fe0..00000000
--- a/tests/bionic/libc/run-test.sh
+++ /dev/null
@@ -1,185 +0,0 @@
-#!/bin/sh
-#
-# Copyright (C) 2010 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.
-#
-# This shell script is used to run one test on a device emulator.
-#
-
-PROGDIR=`dirname $0`
-
-#
-# Parse options
-#
-VERBOSE=no
-VERBOSE2=no
-ADB_CMD=adb
-
-while [ -n "$1" ]; do
- opt="$1"
- optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
- case "$opt" in
- --help|-h|-\?)
- OPTION_HELP=yes
- ;;
- --verbose)
- if [ "$VERBOSE" = "yes" ] ; then
- VERBOSE2=yes
- else
- VERBOSE=yes
- fi
- ;;
- --adb=*)
- ADB_CMD="$optarg"
- ;;
- -*) # unknown options
- echo "ERROR: Unknown option '$opt', use --help for list of valid ones."
- exit 1
- ;;
- *) # Simply record parameter
- if [ -z "$PARAMETERS" ] ; then
- PARAMETERS="$opt"
- else
- PARAMETERS="$PARAMETERS $opt"
- fi
- ;;
- esac
- shift
-done
-
-if [ "$OPTION_HELP" = "yes" ] ; then
- echo "Usage: $PROGNAME [options] <test-name>"
- echo ""
- echo "Run one C library test on a device/emulator through ADB."
- echo ""
- echo "Valid options:"
- echo ""
- echo " --help|-h|-? Print this help"
- echo " --verbose Enable verbose mode"
- echo " --adb=<file> Specify adb executable for device tests"
- echo ""
- exit 0
-fi
-
-if [ -z "$ANDROID_PRODUCT_OUT" ] ; then
- echo "ERROR: ANDROID_PRODUCT_OUT not defined. Please run the 'lunch' command"
- exit 1
-fi
-
-if [ ! -f "$ANDROID_PRODUCT_OUT/system.img" ] ; then
- echo "ERROR: Missing file: $ANDROID_PRODUCT_OUT/system.img"
- echo "Are you sure you built the proper system image?"
- exit 1
-fi
-
-EXEC_ROOT_PATH="$ANDROID_PRODUCT_OUT/obj/EXECUTABLES"
-if [ ! -d "$EXEC_ROOT_PATH" ] ; then
- echo "ERROR: Missing directory: $EXEC_ROOT_PATH"
- echo "Are you sure you built the proper system image?"
- exit 1
-fi
-
-if [ -z "$PARAMETERS" ] ; then
- echo "ERROR: Please specify test name."
- echo "Must be one of the following:"
- for FILE in `cd $EXEC_ROOT_PATH && ls -d test_*`; do
- TEST=`echo "$FILE" | sed -e "s!test_\(.*\)_intermediates!\\1!g"`
- echo " $TEST"
- done
- exit 1
-fi
-
-TEST="$PARAMETERS"
-# Normalize test name, i.e. remove test_ prefix
-TEST=`echo "$TEST" | sed -e "s!^test_!!g"`
-
-TESTDIR="$EXEC_ROOT_PATH/test_${TEST}_intermediates"
-if [ ! -d "$TESTDIR" ] ; then
- echo "ERROR: No test by that name: test_$TEST!"
- exit 1
-fi
-
-TESTNAME="test_$TEST"
-TESTEXE="$TESTDIR/$TESTNAME"
-if [ ! -f "$TESTEXE" ] ; then
- echo "ERROR: Missing file: $TESTEXE"
- echo "Are you sure your last test build was complete?"
- exit 1
-fi
-
-# Run a command in ADB and return 0 in case of success, or 1 otherwise.
-# This is needed because "adb shell" does not return the proper status
-# of the launched command.
-#
-# NOTE: You must call set_adb_cmd_log before that to set the location
-# of the temporary log file that will be used.
-#
-adb_cmd ()
-{
- local RET
- if [ -z "$ADB_CMD_LOG" ] ; then
- dump "INTERNAL ERROR: ADB_CMD_LOG not set!"
- exit 1
- fi
- if [ $VERBOSE = "yes" ] ; then
- echo "$ADB_CMD shell $@"
- $ADB_CMD shell $@ "&&" echo OK "||" echo KO | tee $ADB_CMD_LOG
- else
- $ADB_CMD shell $@ "&&" echo OK "||" echo KO > $ADB_CMD_LOG
- fi
- # Get last line in log, should be OK or KO
- RET=`tail -n1 $ADB_CMD_LOG`
- # Get rid of \r at the end of lines
- RET=`echo "$RET" | sed -e 's![[:cntrl:]]!!g'`
- [ "$RET" = "OK" ]
-}
-
-set_adb_cmd_log ()
-{
- ADB_CMD_LOG="$1"
-}
-
-# Returns 0 if a variable containing one or more items separated
-# by spaces contains a given value.
-# $1: variable name (e.g. FOO)
-# $2: value to test
-var_list_contains ()
-{
- echo `var_value $1` | tr ' ' '\n' | fgrep -q -e "$2"
-}
-
-TMPDIR=/tmp/bionic-tests
-mkdir -p $TMPDIR
-set_adb_cmd_log $TMPDIR/adb.log.txt
-
-DEVICE_TEST_DIR=/data/local/bionic-test
-DEVICE_TEST=$DEVICE_TEST_DIR/$TESTNAME
-adb_cmd mkdir $DEVICE_TEST_DIR
-$ADB_CMD push $TESTEXE $DEVICE_TEST_DIR/
-if [ $? != 0 ] ; then
- echo "ERROR: Can't push test to device!"
- exit 1
-fi
-
-adb_cmd chmod 0755 $DEVICE_TEST &&
-adb_cmd $DEVICE_TEST
-RET=$?
-adb_cmd rm -r $DEVICE_TEST_DIR
-
-if [ "$RET" != 0 ] ; then
- echo "FAIL!"
-else
- echo "OK!"
-fi
-exit 0