diff options
author | 2022-09-21 12:33:36 +0000 | |
---|---|---|
committer | 2022-09-22 14:11:41 +0000 | |
commit | df4219a87bdb7e7d61ba3cfe00f1b2d84c0ee5eb (patch) | |
tree | bb60d463016e831babcfeaa87fb5df6ed5ac2eb2 | |
parent | 1be593c9fcaf8bc821c50aac5ff45bebe8f44d32 (diff) |
Update Test924 to filter for messages related to test thread
Test924 tests that the thread messages are working as expected.
To test this, it constructs a thread, yields and sleeps and then
starts the thread. It expects that there are no events between the
construction of the thread and starting the thread. Though it is not
always guaranteed that there won't be activity corresponding to some
other thread. To prevent corner cases, filter out messages corresponding
to other threads.
Bug: 246688031
Change-Id: I36445d8df87c748b472b21b1a49e11b92907fea1
-rw-r--r-- | test/924-threads/src/art/Test924.java | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/test/924-threads/src/art/Test924.java b/test/924-threads/src/art/Test924.java index e97c9c6b35..355572044f 100644 --- a/test/924-threads/src/art/Test924.java +++ b/test/924-threads/src/art/Test924.java @@ -337,6 +337,19 @@ public class Test924 { } } + private static List<String> filterForThread(Object[] thread_messages, String thread_name) { + List<String> messageListForThread = new ArrayList<String>(); + + for (int i = 0; i < thread_messages.length; i++) { + String message = (String)thread_messages[i]; + if (message.startsWith("Thread(" + thread_name + ")")) { + messageListForThread.add(message); + } + } + + return messageListForThread; + } + private static void doTestEvents() throws Exception { enableThreadEvents(true); @@ -354,21 +367,24 @@ public class Test924 { } } }; - Thread t = new Thread(r, "EventTestThread"); + String thread_name = "EventTestThread"; + Thread t = new Thread(r, thread_name); System.out.println("Constructed thread"); Thread.yield(); Thread.sleep(100); - System.out.println(Arrays.toString(getThreadEventMessages())); + + // Check that there are no events related to EventTestThread that we just created. + System.out.println(filterForThread(getThreadEventMessages(), thread_name).toString()); t.start(); cdl1.await(); - System.out.println(Arrays.toString(getThreadEventMessages())); + System.out.println(filterForThread(getThreadEventMessages(), thread_name).toString()); cdl2.countDown(); t.join(); - System.out.println(Arrays.toString(getThreadEventMessages())); + System.out.println(filterForThread(getThreadEventMessages(), thread_name).toString()); System.out.println("Thread joined"); |