1313#include " lldb/Host/Pipe.h"
1414#include " lldb/Host/ProcessLaunchInfo.h"
1515#include " lldb/Utility/ProcessInfo.h"
16+ #include " llvm/ADT/ScopeExit.h"
1617#include " llvm/ADT/Twine.h"
1718#include " llvm/Support/CommandLine.h"
1819#include " llvm/Support/FileSystem.h"
1920#include " llvm/Testing/Support/Error.h"
2021#include " gtest/gtest.h"
2122#include < future>
23+ #include < thread>
2224
2325using namespace lldb_private ;
2426using namespace llvm ;
@@ -94,9 +96,14 @@ TEST(Host, LaunchProcessSetsArgv0) {
9496TEST (Host, FindProcesses) {
9597 SubsystemRAII<FileSystem, HostInfo> subsystems;
9698
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 ));
98103 exit (0 );
104+ }
99105
106+ bool foundPID = false ;
100107 ProcessLaunchInfo info;
101108 ProcessInstanceInfoList processes;
102109 ProcessInstanceInfoMatch match (TestMainArgv0, NameMatch::Equals);
@@ -110,8 +117,18 @@ TEST(Host, FindProcesses) {
110117 });
111118 ASSERT_THAT_ERROR (Host::LaunchProcess (info).takeError (), Succeeded ());
112119 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+ });
115132}
116133
117134TEST (Host, LaunchProcessDuplicatesHandle) {
0 commit comments