[autotest] Add autotest for browser hang detection
Add desktopui_HangDetector to verify that session_manager's hang detection
for the browser process works.
It will start in the 'regression' suite as an experimental test.
BUG=chromium-os:35729
TEST=run it with run_remote_tests.
CQ-DEPEND=I3e60e1cbda652a3e52126cd69b2ff4cd02cc6a74
CQ-DEPEND=Ied5c9e897485aaf75fdefd211445219712972bdf
Change-Id: I1ba7a4f5db97fb1b92fd5366a18c984a7f5494bc
Reviewed-on: https://gerrit.chromium.org/gerrit/38347
Tested-by: Chris Masone <cmasone@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Ready: Chris Masone <cmasone@chromium.org>
diff --git a/client/bin/site_utils.py b/client/bin/site_utils.py
index 2a9cced..4e44bf4 100644
--- a/client/bin/site_utils.py
+++ b/client/bin/site_utils.py
@@ -43,9 +43,42 @@
return lambda : self.cros_system_data[name]
+def get_oldest_pid_by_name(name):
+ """
+ Return the oldest pid of a process whose name perfectly matches |name|.
+
+ name is an egrep expression, which will be matched against the entire name
+ of processes on the system. For example:
+
+ get_oldest_pid_by_name('chrome')
+
+ on a system running
+ 8600 ? 00:00:04 chrome
+ 8601 ? 00:00:00 chrome
+ 8602 ? 00:00:00 chrome-sandbox
+
+ would return 8600, as that's the oldest process that matches.
+ chrome-sandbox would not be matched.
+
+ Arguments:
+ name: egrep expression to match. Will be anchored at the beginning and
+ end of the match string.
+
+ Returns:
+ pid as an integer, or None if one cannot be found.
+
+ Raises:
+ ValueError if pgrep returns something odd.
+ """
+ str_pid = utils.system_output(
+ 'pgrep -o ^%s$' % name, ignore_status=True).rstrip()
+ if str_pid:
+ return int(str_pid)
+
+
def nuke_process_by_name(name, with_prejudice=False):
try:
- pid = int(utils.system_output('pgrep -o ^%s$' % name).split()[0])
+ pid = get_oldest_pid_by_name(name)
except Exception as e:
logging.error(e)
return
@@ -275,4 +308,4 @@
'(?:\s*#.*)?$', line)
if key_value:
result[key_value.group('key')] = key_value.group('value')
- return result
\ No newline at end of file
+ return result