Skip to content

Commit

Permalink
Merge "Add clone() test."
Browse files Browse the repository at this point in the history
  • Loading branch information
digit-android authored and Android (Google) Code Review committed Jan 29, 2010
2 parents 1dd402f + 84a66d0 commit 4529c93
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/bionic/libc/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ define device-test
$(eval LOCAL_SRC_FILES := $(file)) \
$(eval LOCAL_MODULE := $(notdir $(file:%.c=%))) \
$(eval LOCAL_MODULE := $(LOCAL_MODULE:%.cpp=%)) \
$(eval $(info LOCAL_MODULE=$(LOCAL_MODULE))) \
$(eval LOCAL_CFLAGS += $(EXTRA_CFLAGS)) \
$(eval LOCAL_MODULE_TAGS := tests) \
$(eval include $(BUILD_EXECUTABLE)) \
Expand All @@ -48,7 +47,6 @@ define host-test
$(eval LOCAL_SRC_FILES := $(file)) \
$(eval LOCAL_MODULE := $(notdir $(file:%.c=%))) \
$(eval LOCAL_MODULE := $(LOCAL_MODULE:%.cpp=%)) \
$(eval $(info LOCAL_MODULE=$(LOCAL_MODULE) file=$(file))) \
$(eval LOCAL_CFLAGS += $(EXTRA_CFLAGS)) \
$(eval LOCAL_LDLIBS += $(EXTRA_LDLIBS)) \
$(eval LOCAL_MODULE_TAGS := tests) \
Expand Down Expand Up @@ -148,6 +146,19 @@ LOCAL_MODULE := test_static_init
LOCAL_SHARED_LIBRARIES := libtest_static_init
include $(BUILD_EXECUTABLE)

# Testing 'clone' is only possible on Linux systems
include $(CLEAR_VARS)
LOCAL_SRC_FILES := common/test_clone.c
LOCAL_MODULE := test_clone
include $(BUILD_EXECUTABLE)

ifeq ($(HOST_OS),linux)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := common/test_clone.c
LOCAL_MODULE := test_clone
include $(BUILD_HOST_EXECUTABLE)
endif

# TODO: Add a variety of GLibc test programs too...

# Hello World to test libstdc++ support
Expand Down
5 changes: 5 additions & 0 deletions tests/bionic/libc/bionic/lib_static_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ class Foo {
public:
virtual int getValue();
Foo();
virtual ~Foo();
};

Foo::~Foo()
{
}

extern Foo theFoo;

#endif /* _lib_static_init_h */
56 changes: 56 additions & 0 deletions tests/bionic/libc/common/test_clone.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Check that clone() is implemented and properly works
*/
#define __GNU_SOURCE 1
#include <stdio.h>
#include <errno.h>
#include <sched.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <stdarg.h>
#include <string.h>

static int
clone_child (void *arg)
{
errno = 0;
ptrace (PTRACE_TRACEME, 0, 0, 0);
if (errno != 0)
perror ("ptrace");
if (kill (getpid (), SIGSTOP) < 0)
perror ("kill");
return 0;
}

#define PAGE_SIZE 4096
#define STACK_SIZE (4 * PAGE_SIZE)

char clone_stack[STACK_SIZE] __attribute__ ((aligned (PAGE_SIZE)));

int
main ()
{
int pid,child;
int status;

pid = clone (clone_child, clone_stack + 3 * PAGE_SIZE,
CLONE_VM | SIGCHLD, NULL);
if (pid < 0)
{
perror ("clone");
exit (1);
}
printf ("child pid %d\n", pid);

//sleep(20);
child = waitpid (pid, &status, 0);
printf("waitpid returned %d\n", child);
if (child < 0) {
perror ("waitpid");
return 1;
}
printf ("child %d, status 0x%x\n", child, status);
return 0;
}
6 changes: 6 additions & 0 deletions tests/bionic/libc/common/test_static_cpp_mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Foo {
public:
virtual int getValue();
Foo();
virtual ~Foo();
};

Foo::Foo()
Expand All @@ -50,6 +51,11 @@ Foo::Foo()
fprintf(stderr, "recursive lock initialized and locked\n" );
}

Foo::~Foo()
{
pthread_mutex_unlock(&mMutex);
}

int Foo::getValue()
{
return 0;
Expand Down

0 comments on commit 4529c93

Please sign in to comment.