aboutsummaryrefslogtreecommitdiff
path: root/cros_utils
diff options
context:
space:
mode:
authorZhizhou Yang <zhizhouy@google.com>2019-10-15 15:39:00 -0700
committerZhizhou Yang <zhizhouy@google.com>2019-10-16 17:17:43 +0000
commit03a2534ff8955b237e7c9b312962acf56834bfaa (patch)
treec656a350e6736279948f2a420bb29aaa22f5f929 /cros_utils
parentf94608f33f26b8502fd7c26d0df1e71295d75510 (diff)
downloadtoolchain-utils-03a2534ff8955b237e7c9b312962acf56834bfaa.tar.gz
toolchain-utils: fix a unittest failure in cros_utils
no_pseudo_terminal_test always failed when running tests in toolchain-utils. This is caused by that strace cannot run without sudo permision. This patch fixes it. TEST=Passed unittest. BUG=None Change-Id: Ife8f13dc04cd515eff207ea73716e04cbdc7b8b2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1863626 Reviewed-by: George Burgess <gbiv@chromium.org> Commit-Queue: Zhizhou Yang <zhizhouy@google.com> Tested-by: Zhizhou Yang <zhizhouy@google.com>
Diffstat (limited to 'cros_utils')
-rwxr-xr-x[-rw-r--r--]cros_utils/no_pseudo_terminal_test.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/cros_utils/no_pseudo_terminal_test.py b/cros_utils/no_pseudo_terminal_test.py
index 43eabb13..41d71539 100644..100755
--- a/cros_utils/no_pseudo_terminal_test.py
+++ b/cros_utils/no_pseudo_terminal_test.py
@@ -1,3 +1,10 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+#
+# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
"""Test to ensure we're not touching /dev/ptmx when running commands."""
from __future__ import print_function
@@ -18,9 +25,9 @@ class NoPsuedoTerminalTest(unittest.TestCase):
def _AttachStraceToSelf(self, output_file):
"""Attaches strace to the current process."""
- args = ['strace', '-o', output_file, '-p', str(os.getpid())]
+ args = ['sudo', 'strace', '-o', output_file, '-p', str(os.getpid())]
print(args)
- self._strace_process = subprocess.Popen(args)
+ self._strace_process = subprocess.Popen(args, preexec_fn=os.setpgrp)
# Wait until we see some activity.
start_time = time.time()
while time.time() - start_time < self.STRACE_TIMEOUT:
@@ -31,9 +38,12 @@ class NoPsuedoTerminalTest(unittest.TestCase):
def _KillStraceProcess(self):
"""Kills strace that was started by _AttachStraceToSelf()."""
- self._strace_process.terminate()
- self._strace_process.wait()
- return True
+ pgid = os.getpgid(self._strace_process.pid)
+ args = ['sudo', 'kill', str(pgid)]
+ if subprocess.call(args) == 0:
+ os.waitpid(pgid, 0)
+ return True
+ return False
def testNoPseudoTerminalWhenRunningCommand(self):
"""Test to make sure we're not touching /dev/ptmx when running commands."""