Add skeleton of a jvmti plugin for art.
Test: mma test-art-host-run-test-901-hello-ti-agent
Change-Id: If6807b6238d57471e4ba0dd75c717721246443f6
diff --git a/test/901-hello-ti-agent/basics.cc b/test/901-hello-ti-agent/basics.cc
new file mode 100644
index 0000000..81a1b66
--- /dev/null
+++ b/test/901-hello-ti-agent/basics.cc
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2016 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 "901-hello-ti-agent/basics.h"
+
+#include <jni.h>
+#include <stdio.h>
+#include <string.h>
+#include "base/macros.h"
+#include "openjdkjvmti/jvmti.h"
+
+namespace art {
+namespace Test901HelloTi {
+
+jint OnLoad(JavaVM* vm,
+ char* options ATTRIBUTE_UNUSED,
+ void* reserved ATTRIBUTE_UNUSED) {
+ printf("Loaded Agent for test 901-hello-ti-agent\n");
+ fsync(1);
+ jvmtiEnv* env = nullptr;
+ jvmtiEnv* env2 = nullptr;
+
+#define CHECK_CALL_SUCCESS(c) \
+ do { \
+ if (c != JNI_OK) { \
+ printf("call " #c " did not succeed\n"); \
+ return -1; \
+ } \
+ } while (false)
+
+ CHECK_CALL_SUCCESS(vm->GetEnv(reinterpret_cast<void**>(&env), JVMTI_VERSION_1_0));
+ CHECK_CALL_SUCCESS(vm->GetEnv(reinterpret_cast<void**>(&env2), JVMTI_VERSION_1_0));
+ if (env == env2) {
+ printf("GetEnv returned same environment twice!\n");
+ return -1;
+ }
+ unsigned char* local_data = nullptr;
+ CHECK_CALL_SUCCESS(env->Allocate(8, &local_data));
+ strcpy(reinterpret_cast<char*>(local_data), "hello!!");
+ CHECK_CALL_SUCCESS(env->SetEnvironmentLocalStorage(local_data));
+ unsigned char* get_data = nullptr;
+ CHECK_CALL_SUCCESS(env->GetEnvironmentLocalStorage(reinterpret_cast<void**>(&get_data)));
+ if (get_data != local_data) {
+ printf("Got different data from local storage then what was set!\n");
+ return -1;
+ }
+ CHECK_CALL_SUCCESS(env2->GetEnvironmentLocalStorage(reinterpret_cast<void**>(&get_data)));
+ if (get_data != nullptr) {
+ printf("env2 did not have nullptr local storage.\n");
+ return -1;
+ }
+ CHECK_CALL_SUCCESS(env->Deallocate(local_data));
+ jint version = 0;
+ CHECK_CALL_SUCCESS(env->GetVersionNumber(&version));
+ if ((version & JVMTI_VERSION_1) != JVMTI_VERSION_1) {
+ printf("Unexpected version number!\n");
+ return -1;
+ }
+ CHECK_CALL_SUCCESS(env->DisposeEnvironment());
+ CHECK_CALL_SUCCESS(env2->DisposeEnvironment());
+#undef CHECK_CALL_SUCCESS
+ return JNI_OK;
+}
+
+
+} // namespace Test901HelloTi
+} // namespace art
diff --git a/test/901-hello-ti-agent/basics.h b/test/901-hello-ti-agent/basics.h
new file mode 100644
index 0000000..f482950
--- /dev/null
+++ b/test/901-hello-ti-agent/basics.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef ART_TEST_901_HELLO_TI_AGENT_BASICS_H_
+#define ART_TEST_901_HELLO_TI_AGENT_BASICS_H_
+
+#include <jni.h>
+
+namespace art {
+namespace Test901HelloTi {
+
+jint OnLoad(JavaVM* vm, char* options, void* reserved);
+
+} // namespace Test901HelloTi
+} // namespace art
+
+#endif // ART_TEST_901_HELLO_TI_AGENT_BASICS_H_
diff --git a/test/901-hello-ti-agent/build b/test/901-hello-ti-agent/build
new file mode 100755
index 0000000..898e2e5
--- /dev/null
+++ b/test/901-hello-ti-agent/build
@@ -0,0 +1,17 @@
+#!/bin/bash
+#
+# Copyright 2016 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.
+
+./default-build "$@" --experimental agents
diff --git a/test/901-hello-ti-agent/expected.txt b/test/901-hello-ti-agent/expected.txt
new file mode 100644
index 0000000..414eb3b
--- /dev/null
+++ b/test/901-hello-ti-agent/expected.txt
@@ -0,0 +1,2 @@
+Loaded Agent for test 901-hello-ti-agent
+Hello, world!
diff --git a/test/901-hello-ti-agent/info.txt b/test/901-hello-ti-agent/info.txt
new file mode 100644
index 0000000..875a5f6
--- /dev/null
+++ b/test/901-hello-ti-agent/info.txt
@@ -0,0 +1 @@
+Tests basic functions in the jvmti plugin.
diff --git a/test/901-hello-ti-agent/run b/test/901-hello-ti-agent/run
new file mode 100755
index 0000000..8079a8c
--- /dev/null
+++ b/test/901-hello-ti-agent/run
@@ -0,0 +1,27 @@
+#!/bin/bash
+#
+# Copyright 2016 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.
+
+plugin=libopenjdkjvmtid.so
+agent=libtiagentd.so
+if [[ "$@" == *"-O"* ]]; then
+ agent=libtiagent.so
+ plugin=libopenjdkjvmti.so
+fi
+
+./default-run "$@" --experimental agents \
+ --experimental runtime-plugins \
+ --runtime-option -agentpath:${agent}=901-hello-ti-agent \
+ --android-runtime-option -Xplugin:${plugin}
diff --git a/test/901-hello-ti-agent/src/Main.java b/test/901-hello-ti-agent/src/Main.java
new file mode 100644
index 0000000..1ef6289
--- /dev/null
+++ b/test/901-hello-ti-agent/src/Main.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+public class Main {
+ public static void main(String[] args) {
+ System.out.println("Hello, world!");
+ }
+}