summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy McFadden <fadden@android.com>2011-01-20 10:41:57 -0800
committerAndy McFadden <fadden@android.com>2011-01-20 10:41:57 -0800
commit6ff6ec6b6361db707e4b0318075fc38dd319a49a (patch)
tree4a4ee44f2a1f165cda021dd41bf36f85fdcb82b8 /tests
parent84547e16cfef6e2f1ebe377a466e858a61b59e45 (diff)
downloadandroid_dalvik-6ff6ec6b6361db707e4b0318075fc38dd319a49a.tar.gz
android_dalvik-6ff6ec6b6361db707e4b0318075fc38dd319a49a.tar.bz2
android_dalvik-6ff6ec6b6361db707e4b0318075fc38dd319a49a.zip
Fix dalvik test 084.
Two threads were waiting for initialization of a class to complete. There was nothing encouraging one thread to resume execution first, but on single-core devices it always worked out the same way. Bug 3366697 Change-Id: I29430d398dfbd9509d7db2b7db2800d340b29d19
Diffstat (limited to 'tests')
-rw-r--r--tests/084-class-init/expected.txt2
-rw-r--r--tests/084-class-init/src/Main.java24
2 files changed, 19 insertions, 7 deletions
diff --git a/tests/084-class-init/expected.txt b/tests/084-class-init/expected.txt
index 9865edba7..6e74fbb47 100644
--- a/tests/084-class-init/expected.txt
+++ b/tests/084-class-init/expected.txt
@@ -3,6 +3,6 @@ Got expected NCDFE for FIELD0
Got expected NCDFE for FIELD1
SlowInit static block pre-sleep
SlowInit static block post-sleep
-Fields (child thread): 111222333444
MethodThread message
+Fields (child thread): 111222333444
Fields (main thread): 111222333444
diff --git a/tests/084-class-init/src/Main.java b/tests/084-class-init/src/Main.java
index 89b76f536..f77711302 100644
--- a/tests/084-class-init/src/Main.java
+++ b/tests/084-class-init/src/Main.java
@@ -60,8 +60,13 @@ public class Main {
/* start class init */
IntHolder zero = SlowInit.FIELD0;
- /* init complete; allow other threads time to finish printing */
- Main.sleep(500);
+ /* wait for children to complete */
+ try {
+ fieldThread.join();
+ methodThread.join();
+ } catch (InterruptedException ie) {
+ System.err.println(ie);
+ }
/* print all values */
System.out.println("Fields (main thread): " +
@@ -74,17 +79,24 @@ public class Main {
/* allow class init to start */
Main.sleep(200);
- /* print fields; should delay until class init completes */
+ /* collect fields; should delay until class init completes */
+ int field0, field1, field2, field3;
+ field0 = SlowInit.FIELD0.getValue();
+ field1 = SlowInit.FIELD1.getValue();
+ field2 = SlowInit.FIELD2.getValue();
+ field3 = SlowInit.FIELD3.getValue();
+
+ /* let MethodThread print first */
+ Main.sleep(400);
System.out.println("Fields (child thread): " +
- SlowInit.FIELD0.getValue() + SlowInit.FIELD1.getValue() +
- SlowInit.FIELD2.getValue() + SlowInit.FIELD3.getValue());
+ field0 + field1 + field2 + field3);
}
}
static class MethodThread extends Thread {
public void run() {
/* allow class init to start */
- Main.sleep(400);
+ Main.sleep(200);
/* use a method that shouldn't be accessible yet */
SlowInit.printMsg("MethodThread message");