diff options
author | Brian Carlstrom <bdc@google.com> | 2013-10-11 00:17:42 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2013-10-11 00:17:42 -0700 |
commit | 775c496f989f0e37d2e9a43274c0b55f201b4116 (patch) | |
tree | edfd801b7081aa06016b9a16517b09653dc849b2 /test | |
parent | 73fd3195bd1f8af54f5a6273775186974078068c (diff) | |
parent | b926b3c6821726bf24245478cf24788c57910f0c (diff) | |
download | art-775c496f989f0e37d2e9a43274c0b55f201b4116.tar.gz art-775c496f989f0e37d2e9a43274c0b55f201b4116.tar.bz2 art-775c496f989f0e37d2e9a43274c0b55f201b4116.zip |
resolved conflicts for merge of b926b3c6 to dalvik-dev
Change-Id: Ic56131b49ddfa1ffbc9b50f15e79a0210bd07a41
Diffstat (limited to 'test')
-rw-r--r-- | test/Android.mk | 1 | ||||
-rw-r--r-- | test/JniTest/JniTest.java | 24 | ||||
-rw-r--r-- | test/JniTest/jni_test.cc | 67 |
3 files changed, 92 insertions, 0 deletions
diff --git a/test/Android.mk b/test/Android.mk index 08ec03a01a..cdd61f0eef 100644 --- a/test/Android.mk +++ b/test/Android.mk @@ -44,6 +44,7 @@ TEST_OAT_DIRECTORIES := \ Main \ HelloWorld \ \ + JniTest \ NativeAllocations \ ParallelGC \ ReferenceMap \ diff --git a/test/JniTest/JniTest.java b/test/JniTest/JniTest.java new file mode 100644 index 0000000000..431056ae32 --- /dev/null +++ b/test/JniTest/JniTest.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class JniTest { + public static void main(String[] args) { + System.loadLibrary("arttest"); + testFindClassOnAttachedNativeThread(); + } + + private static native void testFindClassOnAttachedNativeThread(); +} diff --git a/test/JniTest/jni_test.cc b/test/JniTest/jni_test.cc new file mode 100644 index 0000000000..ed69d39d27 --- /dev/null +++ b/test/JniTest/jni_test.cc @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <assert.h> +#include <stdio.h> +#include <pthread.h> + +#include "jni.h" + +#if defined(NDEBUG) +#error test code compiled without NDEBUG +#endif + +static JavaVM* jvm = NULL; + +extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) { + assert(vm != NULL); + assert(jvm == NULL); + jvm = vm; + return JNI_VERSION_1_6; +} + +static void* testFindClassOnAttachedNativeThread(void*) { + assert(jvm != NULL); + + JNIEnv* env = NULL; + JavaVMAttachArgs args = { JNI_VERSION_1_6, __FUNCTION__, NULL }; + int attach_result = jvm->AttachCurrentThread(&env, &args); + assert(attach_result == 0); + + jclass clazz = env->FindClass("JniTest"); + assert(clazz != NULL); + assert(!env->ExceptionCheck()); + + jobjectArray array = env->NewObjectArray(0, clazz, NULL); + assert(array != NULL); + assert(!env->ExceptionCheck()); + + int detach_result = jvm->DetachCurrentThread(); + assert(detach_result == 0); + return NULL; +} + +extern "C" JNIEXPORT void JNICALL Java_JniTest_testFindClassOnAttachedNativeThread(JNIEnv*, + jclass) { + pthread_t pthread; + int pthread_create_result = pthread_create(&pthread, + NULL, + testFindClassOnAttachedNativeThread, + NULL); + assert(pthread_create_result == 0); + int pthread_join_result = pthread_join(pthread, NULL); + assert(pthread_join_result == 0); +} |