• Home
  • Raw
  • Download

Lines Matching full:process

5 #include "base/process/process.h"
14 #include "base/process/kill.h"
32 #include "base/process/internal_linux.h"
63 // Fake port provider that returns the calling process's
78 std::string GetProcessCpuCgroup(const base::Process& process) { in GetProcessCpuCgroup() argument
81 base::FilePath(base::StringPrintf(kProcPath, process.Pid())), in GetProcessCpuCgroup()
103 bool AddProcessToCpuCgroup(const base::Process& process, in AddProcessToCpuCgroup() argument
107 return base::WriteFile(path, base::NumberToString(process.Pid())); in AddProcessToCpuCgroup()
119 Process process(SpawnChild("SimpleChildProcess")); in TEST_F() local
120 ASSERT_TRUE(process.IsValid()); in TEST_F()
121 ASSERT_FALSE(process.is_current()); in TEST_F()
122 EXPECT_NE(process.Pid(), kNullProcessId); in TEST_F()
123 process.Close(); in TEST_F()
124 ASSERT_FALSE(process.IsValid()); in TEST_F()
128 Process process = Process::Current(); in TEST_F() local
129 ASSERT_TRUE(process.IsValid()); in TEST_F()
130 ASSERT_TRUE(process.is_current()); in TEST_F()
131 EXPECT_NE(process.Pid(), kNullProcessId); in TEST_F()
132 process.Close(); in TEST_F()
133 ASSERT_FALSE(process.IsValid()); in TEST_F()
137 Process process1(SpawnChild("SimpleChildProcess")); in TEST_F()
140 Process process2; in TEST_F()
148 Process process3 = Process::Current(); in TEST_F()
156 Process process1(SpawnChild("SimpleChildProcess")); in TEST_F()
159 Process process2 = process1.Duplicate(); in TEST_F()
171 Process process1 = Process::Current(); in TEST_F()
174 Process process2 = process1.Duplicate(); in TEST_F()
193 // The current process creation time should be less than or equal to the in TEST_F()
195 EXPECT_FALSE(Process::Current().CreationTime().is_null()); in TEST_F()
196 EXPECT_LE(Process::Current().CreationTime(), Time::Now()); in TEST_F()
202 // The creation time of a process should be between a time recorded before it in TEST_F()
204 // base::Time and process creation clocks don't match, tolerate some error. in TEST_F()
207 // On Linux, process creation time is relative to boot time which has a in TEST_F()
212 // On Windows, process creation time is based on the system clock while in TEST_F()
217 // On Mac and Fuchsia, process creation time should be very precise. in TEST_F()
223 Process process(SpawnChild("SleepyChildProcess")); in TEST_F() local
225 const Time creation = process.CreationTime(); in TEST_F()
228 EXPECT_TRUE(process.Terminate(kDummyExitCode, true)); in TEST_F()
233 Process process(SpawnChild("SleepyChildProcess")); in TEST_F() local
234 ASSERT_TRUE(process.IsValid()); in TEST_F()
238 GetTerminationStatus(process.Handle(), &exit_code)); in TEST_F()
243 process.Terminate(kExpectedExitCode, false); in TEST_F()
244 process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), in TEST_F()
248 GetTerminationStatus(process.Handle(), &exit_code)); in TEST_F()
257 // Process::TerminateCurrentProcessImmediately. in AtExitHandler()
265 // Process::TerminateCurrentProcessImmediately. in ~ThreadLocalObject()
274 Process::TerminateCurrentProcessImmediately(0); in MULTIPROCESS_TEST_MAIN()
278 Process process(SpawnChild("TerminateCurrentProcessImmediatelyWithCode0")); in TEST_F() local
279 ASSERT_TRUE(process.IsValid()); in TEST_F()
281 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), in TEST_F()
287 Process::TerminateCurrentProcessImmediately(250); in MULTIPROCESS_TEST_MAIN()
291 Process process(SpawnChild("TerminateCurrentProcessImmediatelyWithCode250")); in TEST_F() local
292 ASSERT_TRUE(process.IsValid()); in TEST_F()
294 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(), in TEST_F()
305 Process process(SpawnChild("FastSleepyChildProcess")); in TEST_F() local
306 ASSERT_TRUE(process.IsValid()); in TEST_F()
309 EXPECT_TRUE(process.WaitForExit(&exit_code)); in TEST_F()
314 Process process(SpawnChild("SleepyChildProcess")); in TEST_F() local
315 ASSERT_TRUE(process.IsValid()); in TEST_F()
319 EXPECT_FALSE(process.WaitForExitWithTimeout(timeout, &exit_code)); in TEST_F()
322 process.Terminate(kDummyExitCode, false); in TEST_F()
327 Process process(SpawnChild("FastSleepyChildProcess")); in TEST_F() local
328 ASSERT_TRUE(process.IsValid()); in TEST_F()
334 EXPECT_EQ(process.WaitForExitOrEvent(stop_watching_handle, &exit_code), in TEST_F()
335 base::Process::WaitExitStatus::PROCESS_EXITED); in TEST_F()
340 Process process(SpawnChild("SleepyChildProcess")); in TEST_F() local
341 ASSERT_TRUE(process.IsValid()); in TEST_F()
347 EXPECT_EQ(process.WaitForExitOrEvent(stop_watching_handle, &exit_code), in TEST_F()
348 base::Process::WaitExitStatus::STOP_EVENT_SIGNALED); in TEST_F()
351 process.Terminate(kDummyExitCode, false); in TEST_F()
355 // Ensure that the priority of a process is restored correctly after
358 // a process. The calls to SetProcessPriority should be noops then.
360 if (!Process::CanSetPriority()) { in TEST_F()
363 Process process(SpawnChild("SimpleChildProcess")); in TEST_F() local
364 int old_os_priority = process.GetOSPriority(); in TEST_F()
366 // On the Mac, backgrounding a process requires a port to that process. in TEST_F()
369 // spawning a process and receiving its port. Because this test just checks in TEST_F()
370 // the ability to background/foreground a process, we can use the current in TEST_F()
371 // process's port instead. in TEST_F()
373 EXPECT_TRUE(process.SetPriority(&provider, Process::Priority::kBestEffort)); in TEST_F()
374 EXPECT_EQ(process.GetPriority(&provider), Process::Priority::kBestEffort); in TEST_F()
375 EXPECT_TRUE(process.SetPriority(&provider, Process::Priority::kUserBlocking)); in TEST_F()
376 EXPECT_EQ(process.GetPriority(&provider), Process::Priority::kUserBlocking); in TEST_F()
379 EXPECT_TRUE(process.SetPriority(base::Process::Priority::kBestEffort)); in TEST_F()
380 EXPECT_EQ(process.GetPriority(), Process::Priority::kBestEffort); in TEST_F()
381 EXPECT_TRUE(process.SetPriority(base::Process::Priority::kUserBlocking)); in TEST_F()
382 EXPECT_EQ(process.GetPriority(), Process::Priority::kUserBlocking); in TEST_F()
386 EXPECT_TRUE(process.SetPriority(base::Process::Priority::kUserVisible)); in TEST_F()
392 EXPECT_EQ(process.GetPriority(), Process::Priority::kUserVisible); in TEST_F()
394 EXPECT_EQ(process.GetPriority(), Process::Priority::kUserBlocking); in TEST_F()
397 EXPECT_TRUE(process.SetPriority(base::Process::Priority::kBestEffort)); in TEST_F()
398 EXPECT_EQ(process.GetPriority(), Process::Priority::kBestEffort); in TEST_F()
399 EXPECT_TRUE(process.SetPriority(base::Process::Priority::kUserVisible)); in TEST_F()
402 EXPECT_EQ(process.GetPriority(), Process::Priority::kUserVisible); in TEST_F()
404 EXPECT_EQ(process.GetPriority(), Process::Priority::kUserBlocking); in TEST_F()
406 EXPECT_TRUE(process.SetPriority(base::Process::Priority::kUserBlocking)); in TEST_F()
407 EXPECT_EQ(process.GetPriority(), Process::Priority::kUserBlocking); in TEST_F()
409 // On other platforms, Process::Priority::kUserVisible is translated as in TEST_F()
410 // Process::Priority::kUserBlocking. in TEST_F()
411 EXPECT_TRUE(process.SetPriority(base::Process::Priority::kUserVisible)); in TEST_F()
412 EXPECT_EQ(process.GetPriority(), Process::Priority::kUserBlocking); in TEST_F()
415 int new_os_priority = process.GetOSPriority(); in TEST_F()
433 // Verify that all the threads in a process are RT or not.
571 // Test creation of thread while process is backgrounded. in MULTIPROCESS_TEST_MAIN()
585 // ProcessThreadBackgrounding: A test to create a process and verify
586 // that the threads in the process are backgrounded correctly.
596 // Register signal handlers to be notified of events in child process. in TEST_F()
600 Process process(SpawnChild("ProcessThreadBackgroundingMain")); in TEST_F() local
601 EXPECT_TRUE(process.IsValid()); in TEST_F()
610 AssertThreadsType(process.Pid(), ThreadType::kDisplayCritical); in TEST_F()
611 AssertThreadsBgState(process.Pid(), false); in TEST_F()
613 EXPECT_TRUE(process.SetPriority(Process::Priority::kBestEffort)); in TEST_F()
615 // Send a signal to create a thread while the process is backgrounded. in TEST_F()
616 kill(process.Pid(), SIGUSR1); in TEST_F()
624 AssertThreadsType(process.Pid(), ThreadType::kDisplayCritical); in TEST_F()
625 AssertThreadsBgState(process.Pid(), true); in TEST_F()
627 EXPECT_TRUE(process.SetPriority(Process::Priority::kUserBlocking)); in TEST_F()
628 EXPECT_TRUE(process.GetPriority() == base::Process::Priority::kUserBlocking); in TEST_F()
631 AssertThreadsType(process.Pid(), ThreadType::kDisplayCritical); in TEST_F()
632 AssertThreadsBgState(process.Pid(), false); in TEST_F()
655 // Test the property of kRealTimeAudio threads in a backgrounded process.
665 // Register signal handler to check if RT thread was created by child process. in TEST_F()
668 Process process(SpawnChild("ProcessRTAudioBgMain")); in TEST_F() local
669 EXPECT_TRUE(process.IsValid()); in TEST_F()
676 AssertThreadsRT(process.Pid(), true); in TEST_F()
677 AssertThreadsType(process.Pid(), ThreadType::kRealtimeAudio); in TEST_F()
678 AssertThreadsBgState(process.Pid(), false); in TEST_F()
680 EXPECT_TRUE(process.SetPriority(Process::Priority::kBestEffort)); in TEST_F()
681 EXPECT_TRUE(process.GetPriority() == base::Process::Priority::kBestEffort); in TEST_F()
683 // Verify that nothing changed when process is kBestEffort in TEST_F()
684 AssertThreadsRT(process.Pid(), true); in TEST_F()
685 AssertThreadsType(process.Pid(), ThreadType::kRealtimeAudio); in TEST_F()
686 AssertThreadsBgState(process.Pid(), false); in TEST_F()
688 EXPECT_TRUE(process.SetPriority(Process::Priority::kUserBlocking)); in TEST_F()
689 EXPECT_TRUE(process.GetPriority() == base::Process::Priority::kUserBlocking); in TEST_F()
691 // Verify that nothing changed when process is kUserBlocking in TEST_F()
692 AssertThreadsRT(process.Pid(), true); in TEST_F()
693 AssertThreadsType(process.Pid(), ThreadType::kRealtimeAudio); in TEST_F()
694 AssertThreadsBgState(process.Pid(), false); in TEST_F()
720 // Test the property of kDisplayCritical threads in a backgrounded process.
732 // Register signal handler to check if RT thread was created by child process. in TEST_F()
735 Process process(SpawnChild("ProcessRTDisplayBgMain")); in TEST_F() local
736 EXPECT_TRUE(process.IsValid()); in TEST_F()
743 AssertThreadsRT(process.Pid(), true); in TEST_F()
744 AssertThreadsType(process.Pid(), ThreadType::kDisplayCritical); in TEST_F()
745 AssertThreadsBgState(process.Pid(), false); in TEST_F()
747 EXPECT_TRUE(process.SetPriority(Process::Priority::kBestEffort)); in TEST_F()
748 EXPECT_TRUE(process.GetPriority() == base::Process::Priority::kBestEffort); in TEST_F()
750 // Verify that the threads transitioned away from RT when process is in TEST_F()
752 AssertThreadsRT(process.Pid(), false); in TEST_F()
753 AssertThreadsType(process.Pid(), ThreadType::kDisplayCritical); in TEST_F()
754 AssertThreadsBgState(process.Pid(), true); in TEST_F()
756 EXPECT_TRUE(process.SetPriority(Process::Priority::kUserBlocking)); in TEST_F()
757 EXPECT_TRUE(process.GetPriority() == base::Process::Priority::kUserBlocking); in TEST_F()
759 // Verify that it is back to RT when process is kUserBlocking in TEST_F()
760 AssertThreadsRT(process.Pid(), true); in TEST_F()
761 AssertThreadsType(process.Pid(), ThreadType::kDisplayCritical); in TEST_F()
762 AssertThreadsBgState(process.Pid(), false); in TEST_F()
768 // whether the process is still running. This may not be safe because of the
769 // potential reusing of the process id. So we won't export Process::IsRunning()
773 EXPECT_FALSE(Process::Current().WaitForExitWithTimeout( in TEST_F()
778 // On Mac OSX, we can detect whether a non-child process is running.
780 // Process 1 is the /sbin/launchd, it should be always running. in TEST_F()
781 EXPECT_FALSE(Process::Open(1).WaitForExitWithTimeout( in TEST_F()
815 Process process(SpawnChild("SleepyChildProcess")); in TEST_F() local
816 EXPECT_FALSE(process.WaitForExitWithTimeout( in TEST_F()
818 process.Terminate(0, true); in TEST_F()
819 EXPECT_TRUE(process.WaitForExitWithTimeout( in TEST_F()
834 Process::Priority::kUserBlocking); in TEST_F()
836 Process::Priority::kBestEffort); in TEST_F()
840 // TODO(b/172213843): base::Process is used by base::TestSuite::Initialize in TEST_F()
843 if (!Process::OneGroupPerRendererEnabledForTesting()) in TEST_F()
846 Process process; in TEST_F() local
847 process.InitializePriority(); in TEST_F()
848 const std::string unique_token = process.unique_token(); in TEST_F()
853 if (!Process::OneGroupPerRendererEnabledForTesting()) in TEST_F()
858 Process process(SpawnChild("SimpleChildProcess")); in TEST_F() local
859 process.InitializePriority(); in TEST_F()
860 const std::string unique_token = process.unique_token(); in TEST_F()
863 EXPECT_TRUE(process.SetPriority(Process::Priority::kUserBlocking)); in TEST_F()
864 EXPECT_EQ(process.GetPriority(), Process::Priority::kUserBlocking); in TEST_F()
865 std::string cgroup = GetProcessCpuCgroup(process); in TEST_F()
869 EXPECT_TRUE(process.SetPriority(Process::Priority::kBestEffort)); in TEST_F()
870 EXPECT_EQ(process.GetPriority(), Process::Priority::kBestEffort); in TEST_F()
872 EXPECT_TRUE(process.Terminate(0, false)); in TEST_F()
881 if (!Process::OneGroupPerRendererEnabledForTesting()) in TEST_F()
886 Process process(SpawnChild("SimpleChildProcess")); in TEST_F() local
887 process.InitializePriority(); in TEST_F()
888 const std::string unique_token = process.unique_token(); in TEST_F()
891 EXPECT_TRUE(process.SetPriority(Process::Priority::kUserBlocking)); in TEST_F()
892 EXPECT_EQ(process.GetPriority(), Process::Priority::kUserBlocking); in TEST_F()
893 std::string cgroup = GetProcessCpuCgroup(process); in TEST_F()
897 // Add another process to the cgroup to ensure it stays busy. in TEST_F()
899 Process process2(SpawnChild("SimpleChildProcess")); in TEST_F()
902 // Terminate the first process that should tirgger a cleanup of the cgroup in TEST_F()
903 EXPECT_TRUE(process.Terminate(0, false)); in TEST_F()
909 // Move the second process to free the cgroup in TEST_F()
924 if (!Process::OneGroupPerRendererEnabledForTesting()) in TEST_F()
927 Process process(SpawnChild("SimpleChildProcess")); in TEST_F() local
928 const std::string unique_token = process.unique_token(); in TEST_F()
932 EXPECT_TRUE(process.SetPriority(Process::Priority::kUserBlocking)); in TEST_F()
933 EXPECT_EQ(process.GetPriority(), Process::Priority::kUserBlocking); in TEST_F()
934 std::string cgroup = GetProcessCpuCgroup(process); in TEST_F()
940 if (!Process::OneGroupPerRendererEnabledForTesting()) in TEST_F()
945 // Create a process that will not be cleaned up in TEST_F()
946 Process process(SpawnChild("SimpleChildProcess")); in TEST_F() local
947 process.InitializePriority(); in TEST_F()
948 const std::string unique_token = process.unique_token(); in TEST_F()
951 EXPECT_TRUE(process.SetPriority(Process::Priority::kBestEffort)); in TEST_F()
952 EXPECT_EQ(process.GetPriority(), Process::Priority::kBestEffort); in TEST_F()
964 Process::CleanUpStaleProcessStates(); in TEST_F()
969 // validate the active process cgroup is not deleted in TEST_F()
976 // clean up the process in TEST_F()
977 EXPECT_TRUE(process.Terminate(0, false)); in TEST_F()
984 if (!Process::OneGroupPerRendererEnabledForTesting()) in TEST_F()
989 // Create a process that will not be cleaned up in TEST_F()
990 Process process(SpawnChild("SimpleChildProcess")); in TEST_F() local
991 process.InitializePriority(); in TEST_F()
992 const std::string unique_token = process.unique_token(); in TEST_F()
995 EXPECT_TRUE(process.SetPriority(Process::Priority::kUserBlocking)); in TEST_F()
996 EXPECT_EQ(process.GetPriority(), Process::Priority::kUserBlocking); in TEST_F()
997 std::string cgroup = GetProcessCpuCgroup(process); in TEST_F()
1007 Process::CleanUpStaleProcessStates(); in TEST_F()
1013 // clean up the process in TEST_F()
1014 EXPECT_TRUE(process.SetPriority(Process::Priority::kBestEffort)); in TEST_F()
1015 EXPECT_EQ(process.GetPriority(), Process::Priority::kBestEffort); in TEST_F()
1016 EXPECT_TRUE(process.Terminate(0, false)); in TEST_F()