summaryrefslogtreecommitdiff
path: root/test/051-thread/src/Main.java
diff options
context:
space:
mode:
author Andreas Gampe <agampe@google.com> 2017-04-17 20:19:14 -0700
committer Andreas Gampe <agampe@google.com> 2017-04-17 21:16:29 -0700
commit21cf95d8f34dc9cc20c75896a0cc4df9a8fd77e6 (patch)
tree0f0e14c2f3f1f6637558b5221deab4568665e0bb /test/051-thread/src/Main.java
parent36831abc29f76baee9a7673a2c18465f33df3f05 (diff)
ART: Call ThreadGroup.add in Thread::FinishStartup
ART should add the main thread to the main ThreadGroup. Behavior of the Thread constructor changed. Bug: 37444210 Test: art/test/testrunner/testrunner.py -b --host -t 051 Test: m test-art-host Test: m build-art-host && art/tools/run-libcore-tests.sh --mode=host Change-Id: I92cf2f9a6c5c3fdf385eb7925addc38b64fa4d98
Diffstat (limited to 'test/051-thread/src/Main.java')
-rw-r--r--test/051-thread/src/Main.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/051-thread/src/Main.java b/test/051-thread/src/Main.java
index 82fc0d471b..08cb5deeac 100644
--- a/test/051-thread/src/Main.java
+++ b/test/051-thread/src/Main.java
@@ -15,6 +15,9 @@
*/
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
/**
* Test some basic thread stuff.
@@ -28,6 +31,8 @@ public class Main {
testSleepZero();
testSetName();
testThreadPriorities();
+ testMainThreadGroup();
+ testMainThreadAllStackTraces();
System.out.println("thread test done");
}
@@ -159,6 +164,49 @@ public class Main {
System.out.print("testThreadPriorities finished\n");
}
+ private static void testMainThreadGroup() {
+ Thread threads[] = new Thread[10];
+ Thread current = Thread.currentThread();
+ current.getThreadGroup().enumerate(threads);
+
+ for (Thread t : threads) {
+ if (t == current) {
+ System.out.println("Found current Thread in ThreadGroup");
+ return;
+ }
+ }
+ throw new RuntimeException("Did not find main thread: " + Arrays.toString(threads));
+ }
+
+ private static void testMainThreadAllStackTraces() {
+ StackTraceElement[] trace = Thread.getAllStackTraces().get(Thread.currentThread());
+ if (trace == null) {
+ throw new RuntimeException("Did not find main thread: " + Thread.getAllStackTraces());
+ }
+ List<StackTraceElement> list = Arrays.asList(trace);
+ Iterator<StackTraceElement> it = list.iterator();
+ while (it.hasNext()) {
+ StackTraceElement ste = it.next();
+ if (ste.getClassName().equals("Main")) {
+ if (!ste.getMethodName().equals("testMainThreadAllStackTraces")) {
+ throw new RuntimeException(list.toString());
+ }
+
+ StackTraceElement ste2 = it.next();
+ if (!ste2.getClassName().equals("Main")) {
+ throw new RuntimeException(list.toString());
+ }
+ if (!ste2.getMethodName().equals("main")) {
+ throw new RuntimeException(list.toString());
+ }
+
+ System.out.println("Found expected stack in getAllStackTraces()");
+ return;
+ }
+ }
+ throw new RuntimeException(list.toString());
+ }
+
private static native int getNativePriority();
private static native boolean supportsThreadPriorities();