Reland "Update test to not trace thread start / join"
This reverts commit 89fae872b0aa0c7186ee11bdf1f5732de3f66030.
Reason for revert: Reland after some fixes and improvements
1. The actual reason for failures is a bug introduced in a different CL
(https://android-review.git.corp.google.com/c/platform/art/+/2561890).
This CL fixes the bug where break was used instead of continue
2. Update the test to check only events corresponding to the expected
thread. Though the origianl CL was to prevent thread join and thread
start events to prevent races across threads it wasn't quite accurate.
There were still events corresponding to thread join. So this CL
updates the checks for a particular thread.
3. A small cleanup to use local the_trace in trace.cc for consistency.
4. A small cleanup to properly delete temporary files.
Bug: 259258187
Test: art/test.py -t 2246
Change-Id: Ida21433a7040217bd2da2231cc8ce475e413b1df
diff --git a/runtime/trace.cc b/runtime/trace.cc
index 745c252..99b314d 100644
--- a/runtime/trace.cc
+++ b/runtime/trace.cc
@@ -567,7 +567,7 @@
namespace {
-bool IsShutdownThread(std::string name) {
+bool IsShutdownThread(const std::string& name) {
return (name.compare("Shutdown thread") == 0);
}
@@ -626,7 +626,7 @@
MutexLock tl_lock(Thread::Current(), *Locks::thread_list_lock_);
for (Thread* thread : Runtime::Current()->GetThreadList()->GetList()) {
if (thread->GetMethodTraceBuffer() != nullptr) {
- the_trace_->FlushStreamingBuffer(thread);
+ the_trace->FlushStreamingBuffer(thread);
thread->ResetMethodTraceBuffer();
}
// Record threads here before resetting the_trace_ to prevent any races between
diff --git a/test/2246-trace-stream/expected-stdout.txt b/test/2246-trace-stream/expected-stdout.txt
index d6ad93c..d7bb83f 100644
--- a/test/2246-trace-stream/expected-stdout.txt
+++ b/test/2246-trace-stream/expected-stdout.txt
@@ -1,7 +1,15 @@
***** streaming test *******
.>> TestThread2246 java.lang.Thread run ()V Thread.java
..>> TestThread2246 Main$$ExternalSyntheticLambda0 run ()V D8$$SyntheticClass
-...>> TestThread2246 Main lambda$testTracing$0 ()V Main.java
+...>> TestThread2246 Main lambda$testTracing$0 (ZLBaseTraceParser;I)V Main.java
+....>> TestThread2246 Main$VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V Main.java
+.....>> TestThread2246 java.lang.reflect.Method invoke (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; Method.java
+......>> TestThread2246 dalvik.system.VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V VMDebug.java
+.......>> TestThread2246 dalvik.system.VMDebug startMethodTracingFd (Ljava/lang/String;IIIZIZ)V VMDebug.java
+.......<< TestThread2246 dalvik.system.VMDebug startMethodTracingFd (Ljava/lang/String;IIIZIZ)V VMDebug.java
+......<< TestThread2246 dalvik.system.VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V VMDebug.java
+.....<< TestThread2246 java.lang.reflect.Method invoke (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; Method.java
+....<< TestThread2246 Main$VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V Main.java
....>> TestThread2246 Main <init> ()V Main.java
.....>> TestThread2246 java.lang.Object <init> ()V Object.java
.....<< TestThread2246 java.lang.Object <init> ()V Object.java
@@ -14,9 +22,7 @@
.....>> TestThread2246 Main callLeafFunction ()V Main.java
.....<< TestThread2246 Main callLeafFunction ()V Main.java
....<< TestThread2246 Main $noinline$doSomeWork ()V Main.java
-...<< TestThread2246 Main lambda$testTracing$0 ()V Main.java
-..<< TestThread2246 Main$$ExternalSyntheticLambda0 run ()V D8$$SyntheticClass
-.<< TestThread2246 java.lang.Thread run ()V Thread.java
+....>> TestThread2246 Main$VMDebug $noinline$stopMethodTracing ()V Main.java
.>> main Main main ([Ljava/lang/String;)V Main.java
..>> main Main testTracing (ZLBaseTraceParser;I)V Main.java
...>> main Main$VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V Main.java
@@ -27,26 +33,6 @@
.....<< main dalvik.system.VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V VMDebug.java
....<< main java.lang.reflect.Method invoke (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; Method.java
...<< main Main$VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V Main.java
-...>> main java.lang.Thread start ()V Thread.java
-....>> main java.lang.ThreadGroup add (Ljava/lang/Thread;)V ThreadGroup.java
-....<< main java.lang.ThreadGroup add (Ljava/lang/Thread;)V ThreadGroup.java
-....>> main java.lang.Thread nativeCreate (Ljava/lang/Thread;JZ)V Thread.java
-....<< main java.lang.Thread nativeCreate (Ljava/lang/Thread;JZ)V Thread.java
-...<< main java.lang.Thread start ()V Thread.java
-...>> main java.lang.Thread join ()V Thread.java
-....>> main java.lang.Thread join (J)V Thread.java
-.....>> main java.lang.System currentTimeMillis ()J System.java
-.....<< main java.lang.System currentTimeMillis ()J System.java
-.....>> main java.lang.Thread isAlive ()Z Thread.java
-.....<< main java.lang.Thread isAlive ()Z Thread.java
-.....>> main java.lang.Object wait (J)V Object.java
-......>> main java.lang.Object wait (JI)V Object.java
-......<< main java.lang.Object wait (JI)V Object.java
-.....<< main java.lang.Object wait (J)V Object.java
-.....>> main java.lang.Thread isAlive ()Z Thread.java
-.....<< main java.lang.Thread isAlive ()Z Thread.java
-....<< main java.lang.Thread join (J)V Thread.java
-...<< main java.lang.Thread join ()V Thread.java
...>> main Main $noinline$doSomeWork ()V Main.java
....>> main Main callOuterFunction ()V Main.java
.....>> main Main callLeafFunction ()V Main.java
@@ -75,7 +61,15 @@
***** non streaming test *******
.>> TestThread2246 java.lang.Thread run ()V Thread.java
..>> TestThread2246 Main$$ExternalSyntheticLambda0 run ()V D8$$SyntheticClass
-...>> TestThread2246 Main lambda$testTracing$0 ()V Main.java
+...>> TestThread2246 Main lambda$testTracing$0 (ZLBaseTraceParser;I)V Main.java
+....>> TestThread2246 Main$VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V Main.java
+.....>> TestThread2246 java.lang.reflect.Method invoke (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; Method.java
+......>> TestThread2246 dalvik.system.VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V VMDebug.java
+.......>> TestThread2246 dalvik.system.VMDebug startMethodTracingFd (Ljava/lang/String;IIIZIZ)V VMDebug.java
+.......<< TestThread2246 dalvik.system.VMDebug startMethodTracingFd (Ljava/lang/String;IIIZIZ)V VMDebug.java
+......<< TestThread2246 dalvik.system.VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V VMDebug.java
+.....<< TestThread2246 java.lang.reflect.Method invoke (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; Method.java
+....<< TestThread2246 Main$VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V Main.java
....>> TestThread2246 Main <init> ()V Main.java
.....>> TestThread2246 java.lang.Object <init> ()V Object.java
.....<< TestThread2246 java.lang.Object <init> ()V Object.java
@@ -88,15 +82,9 @@
.....>> TestThread2246 Main callLeafFunction ()V Main.java
.....<< TestThread2246 Main callLeafFunction ()V Main.java
....<< TestThread2246 Main $noinline$doSomeWork ()V Main.java
-...<< TestThread2246 Main lambda$testTracing$0 ()V Main.java
-..<< TestThread2246 Main$$ExternalSyntheticLambda0 run ()V D8$$SyntheticClass
-.<< TestThread2246 java.lang.Thread run ()V Thread.java
-.>> TestThread2246 java.lang.ThreadGroup threadTerminated (Ljava/lang/Thread;)V ThreadGroup.java
-..>> TestThread2246 java.lang.ThreadGroup remove (Ljava/lang/Thread;)V ThreadGroup.java
-...>> TestThread2246 java.lang.System arraycopy (Ljava/lang/Object;ILjava/lang/Object;II)V System.java
-...<< TestThread2246 java.lang.System arraycopy (Ljava/lang/Object;ILjava/lang/Object;II)V System.java
-..<< TestThread2246 java.lang.ThreadGroup remove (Ljava/lang/Thread;)V ThreadGroup.java
-.<< TestThread2246 java.lang.ThreadGroup threadTerminated (Ljava/lang/Thread;)V ThreadGroup.java
+....>> TestThread2246 Main$VMDebug $noinline$stopMethodTracing ()V Main.java
+.....>> TestThread2246 java.lang.reflect.Method invoke (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; Method.java
+......>> TestThread2246 dalvik.system.VMDebug stopMethodTracing ()V VMDebug.java
.>> main Main main ([Ljava/lang/String;)V Main.java
..>> main Main testTracing (ZLBaseTraceParser;I)V Main.java
...>> main Main$VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V Main.java
@@ -107,26 +95,6 @@
.....<< main dalvik.system.VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V VMDebug.java
....<< main java.lang.reflect.Method invoke (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; Method.java
...<< main Main$VMDebug startMethodTracing (Ljava/lang/String;Ljava/io/FileDescriptor;IIZIZ)V Main.java
-...>> main java.lang.Thread start ()V Thread.java
-....>> main java.lang.ThreadGroup add (Ljava/lang/Thread;)V ThreadGroup.java
-....<< main java.lang.ThreadGroup add (Ljava/lang/Thread;)V ThreadGroup.java
-....>> main java.lang.Thread nativeCreate (Ljava/lang/Thread;JZ)V Thread.java
-....<< main java.lang.Thread nativeCreate (Ljava/lang/Thread;JZ)V Thread.java
-...<< main java.lang.Thread start ()V Thread.java
-...>> main java.lang.Thread join ()V Thread.java
-....>> main java.lang.Thread join (J)V Thread.java
-.....>> main java.lang.System currentTimeMillis ()J System.java
-.....<< main java.lang.System currentTimeMillis ()J System.java
-.....>> main java.lang.Thread isAlive ()Z Thread.java
-.....<< main java.lang.Thread isAlive ()Z Thread.java
-.....>> main java.lang.Object wait (J)V Object.java
-......>> main java.lang.Object wait (JI)V Object.java
-......<< main java.lang.Object wait (JI)V Object.java
-.....<< main java.lang.Object wait (J)V Object.java
-.....>> main java.lang.Thread isAlive ()Z Thread.java
-.....<< main java.lang.Thread isAlive ()Z Thread.java
-....<< main java.lang.Thread join (J)V Thread.java
-...<< main java.lang.Thread join ()V Thread.java
...>> main Main $noinline$doSomeWork ()V Main.java
....>> main Main callOuterFunction ()V Main.java
.....>> main Main callLeafFunction ()V Main.java
diff --git a/test/2246-trace-stream/src/BaseTraceParser.java b/test/2246-trace-stream/src/BaseTraceParser.java
index ebc346c..b551b64 100644
--- a/test/2246-trace-stream/src/BaseTraceParser.java
+++ b/test/2246-trace-stream/src/BaseTraceParser.java
@@ -136,16 +136,16 @@
threadIdMap.put(threadId, threadInfo);
}
- public boolean ShouldIgnoreThread(int threadId) throws Exception {
+ public boolean ShouldCheckThread(int threadId, String threadName) throws Exception {
if (!threadIdMap.containsKey(threadId)) {
System.out.println("no threadId -> name mapping for thread " + threadId);
// TODO(b/279547877): Ideally we should throw here, since it isn't expected. Just
// continuing to get more logs from the bots to see what's happening here. The
- // test will fail anyway because the diff will be different.
- return false;
+ // test will fail anyway because the expected output will be different.
+ return true;
}
- return threadIdMap.get(threadId).contains("Daemon");
+ return threadIdMap.get(threadId).equals(threadName);
}
public String eventTypeToString(int eventType, int threadId) {
@@ -203,8 +203,8 @@
threadEventsMap.put(threadName, threadEventsMap.get(threadName) + "\n" + entry);
}
- public abstract void CheckTraceFileFormat(File traceFile, int expectedVersion)
- throws Exception;
+ public abstract void CheckTraceFileFormat(File traceFile,
+ int expectedVersion, String threadName) throws Exception;
DataInputStream dataStream;
HashMap<Integer, String> methodIdMap;
diff --git a/test/2246-trace-stream/src/Main.java b/test/2246-trace-stream/src/Main.java
index daada7d..77cece9 100644
--- a/test/2246-trace-stream/src/Main.java
+++ b/test/2246-trace-stream/src/Main.java
@@ -43,30 +43,46 @@
public static void testTracing(boolean streaming, BaseTraceParser parser, int expected_version)
throws Exception {
- file = createTempFile();
- FileOutputStream out_file = new FileOutputStream(file);
Main m = new Main();
Thread t = new Thread(() -> {
- Main m1 = new Main();
- m1.$noinline$doSomeWork();
+ try {
+ file = createTempFile();
+ FileOutputStream out_file = new FileOutputStream(file);
+ VMDebug.startMethodTracing(
+ file.getPath(), out_file.getFD(), 0, 0, false, 0, streaming);
+ Main m1 = new Main();
+ m1.$noinline$doSomeWork();
+ VMDebug.$noinline$stopMethodTracing();
+ out_file.close();
+ parser.CheckTraceFileFormat(file, expected_version, "TestThread2246");
+ file.delete();
+ } catch (Exception e) {
+ System.out.println("Exception in thread " + e);
+ e.printStackTrace();
+ } finally {
+ file.delete();
+ }
}, "TestThread2246");
try {
if (VMDebug.getMethodTracingMode() != 0) {
VMDebug.$noinline$stopMethodTracing();
}
- VMDebug.startMethodTracing(file.getPath(), out_file.getFD(), 0, 0, false, 0, streaming);
t.start();
t.join();
+
+ file = createTempFile();
+ FileOutputStream main_out_file = new FileOutputStream(file);
+ VMDebug.startMethodTracing(
+ file.getPath(), main_out_file.getFD(), 0, 0, false, 0, streaming);
m.$noinline$doSomeWork();
m.doSomeWorkThrow();
VMDebug.$noinline$stopMethodTracing();
- out_file.close();
- parser.CheckTraceFileFormat(file, expected_version);
+ main_out_file.close();
+ parser.CheckTraceFileFormat(file, expected_version, "main");
+ file.delete();
} finally {
- if (out_file != null) {
- out_file.close();
- }
+ file.delete();
}
}
diff --git a/test/2246-trace-stream/src/NonStreamTraceParser.java b/test/2246-trace-stream/src/NonStreamTraceParser.java
index 49903ca..d9658a4 100644
--- a/test/2246-trace-stream/src/NonStreamTraceParser.java
+++ b/test/2246-trace-stream/src/NonStreamTraceParser.java
@@ -19,7 +19,8 @@
public class NonStreamTraceParser extends BaseTraceParser {
- public void CheckTraceFileFormat(File file, int expectedVersion) throws Exception {
+ public void CheckTraceFileFormat(File file,
+ int expectedVersion, String threadName) throws Exception {
InitializeParser(file);
// On non-streaming formats, the file starts with information about options and threads and
@@ -83,7 +84,7 @@
String eventString = ProcessEventEntry(threadId);
// Ignore daemons (ex: heap task daemon, reference queue daemon) because they may not
// be deterministic.
- if (ShouldIgnoreThread(threadId)) {
+ if (!ShouldCheckThread(threadId, threadName)) {
continue;
}
// Ignore events after method tracing was stopped. The code that is executed
diff --git a/test/2246-trace-stream/src/StreamTraceParser.java b/test/2246-trace-stream/src/StreamTraceParser.java
index d7ef9b9..3cad4e9 100644
--- a/test/2246-trace-stream/src/StreamTraceParser.java
+++ b/test/2246-trace-stream/src/StreamTraceParser.java
@@ -19,7 +19,8 @@
public class StreamTraceParser extends BaseTraceParser {
- public void CheckTraceFileFormat(File file, int expectedVersion) throws Exception {
+ public void CheckTraceFileFormat(File file,
+ int expectedVersion, String threadName) throws Exception {
InitializeParser(file);
validateTraceHeader(expectedVersion);
@@ -29,8 +30,8 @@
int threadId = GetThreadID();
if (threadId != 0) {
String eventString = ProcessEventEntry(threadId);
- if (ShouldIgnoreThread(threadId)) {
- break;
+ if (!ShouldCheckThread(threadId, threadName)) {
+ continue;
}
// Ignore events after method tracing was stopped. The code that is executed
// later could be non-deterministic.