Don't fail 050-sync-test due to thread timing
Currently, there is a thread execution possible wherein the sleepy
thread, even though it has a longer wait, finishes before the pesky thread,
and hence prints an output which is not expected, even if the
synchronization primitives are working fine.
In this change we let sleepy thread wait in a loop until pesky thread is
not done. This way the unexpected output is printed only if interrupt()
fails to interrupt sleepy thread.
Bug: 117597114
Test: art/test/testrunner/testrunner.py --target --gcstress --debug -t
050-sync-test
Change-Id: I4fc3afb40ac11e413174391419eaad39e80c8b10
diff --git a/test/050-sync-test/src/Main.java b/test/050-sync-test/src/Main.java
index 734b51e..ba37818 100644
--- a/test/050-sync-test/src/Main.java
+++ b/test/050-sync-test/src/Main.java
@@ -133,11 +133,13 @@
class SleepyThread extends Thread {
private SleepyThread mOther;
private Integer[] mWaitOnMe; // any type of object will do
+ private volatile boolean otherDone;
private static int count = 0;
SleepyThread(SleepyThread other) {
mOther = other;
+ otherDone = false;
mWaitOnMe = new Integer[] { 1, 2 };
setName("thread#" + count);
@@ -158,9 +160,11 @@
boolean intr = false;
try {
+ do {
synchronized (mWaitOnMe) {
mWaitOnMe.wait(9000);
}
+ } while (!otherDone);
} catch (InterruptedException ie) {
// Expecting this; interrupted should be false.
System.out.println(Thread.currentThread().getName() +
@@ -182,6 +186,7 @@
System.out.println("interrupting other (isAlive="
+ mOther.isAlive() + ")");
mOther.interrupt();
+ mOther.otherDone = true;
}
}
}
diff --git a/test/knownfailures.json b/test/knownfailures.json
index 7b40160..f0eacfa 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -1110,11 +1110,5 @@
"tests": ["454-get-vreg", "457-regs"],
"variant": "baseline",
"description": ["Tests are expected to fail with baseline."]
- },
- {
- "tests": ["050-sync-test"],
- "variant": "target & gcstress & debug",
- "bug": "b/117597114",
- "description": ["Looks timing dependent"]
}
]