13
13
#include " lldb/Host/Pipe.h"
14
14
#include " lldb/Host/ProcessLaunchInfo.h"
15
15
#include " lldb/Utility/ProcessInfo.h"
16
+ #include " llvm/ADT/ScopeExit.h"
16
17
#include " llvm/ADT/Twine.h"
17
18
#include " llvm/Support/CommandLine.h"
18
19
#include " llvm/Support/FileSystem.h"
19
20
#include " llvm/Testing/Support/Error.h"
20
21
#include " gtest/gtest.h"
21
22
#include < future>
23
+ #include < thread>
22
24
23
25
using namespace lldb_private ;
24
26
using namespace llvm ;
@@ -94,9 +96,14 @@ TEST(Host, LaunchProcessSetsArgv0) {
94
96
TEST (Host, FindProcesses) {
95
97
SubsystemRAII<FileSystem, HostInfo> subsystems;
96
98
97
- if (test_arg != 0 )
99
+ if (test_arg != 0 ) {
100
+ // Give the parent time to retrieve information about self.
101
+ // It will kill self when it is done.
102
+ std::this_thread::sleep_for (std::chrono::seconds (10 ));
98
103
exit (0 );
104
+ }
99
105
106
+ bool foundPID = false ;
100
107
ProcessLaunchInfo info;
101
108
ProcessInstanceInfoList processes;
102
109
ProcessInstanceInfoMatch match (TestMainArgv0, NameMatch::Equals);
@@ -110,8 +117,18 @@ TEST(Host, FindProcesses) {
110
117
});
111
118
ASSERT_THAT_ERROR (Host::LaunchProcess (info).takeError (), Succeeded ());
112
119
ASSERT_TRUE (Host::FindProcesses (match, processes));
113
- ASSERT_EQ (processes[0 ].GetArg0 (), TestMainArgv0);
114
- ASSERT_THAT (exit_status.get_future ().get (), 0 );
120
+ for (const auto &process : processes) {
121
+ if (process.GetProcessID () == info.GetProcessID ()) {
122
+ ASSERT_EQ (process.GetExecutableFile ().GetFilename (),
123
+ info.GetExecutableFile ().GetFilename ());
124
+ foundPID = true ;
125
+ }
126
+ }
127
+ ASSERT_TRUE (foundPID);
128
+ auto clean_up = llvm::make_scope_exit ([&] {
129
+ Host::Kill (info.GetProcessID (), SIGKILL);
130
+ exit_status.get_future ().get ();
131
+ });
115
132
}
116
133
117
134
TEST (Host, LaunchProcessDuplicatesHandle) {
0 commit comments