Merge "adb: add test for SIGHUP behavior."
This commit is contained in:
commit
a355dd6110
|
@ -31,6 +31,7 @@ import string
|
|||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
|
@ -495,6 +496,36 @@ class ShellTest(DeviceTest):
|
|||
self.assertEqual(input.splitlines(), stdout.splitlines())
|
||||
self.assertEqual('', stderr)
|
||||
|
||||
def test_sighup(self):
|
||||
"""Ensure that SIGHUP gets sent upon non-interactive ctrl-c"""
|
||||
log_path = "/data/local/tmp/adb_signal_test.log"
|
||||
|
||||
# Clear the output file.
|
||||
self.device.shell_nocheck(["echo", ">", log_path])
|
||||
|
||||
script = """
|
||||
trap "echo SIGINT > {path}; exit 0" SIGINT
|
||||
trap "echo SIGHUP > {path}; exit 0" SIGHUP
|
||||
echo Waiting
|
||||
while true; do sleep 100; done
|
||||
""".format(path=log_path)
|
||||
|
||||
script = ";".join([x.strip() for x in script.strip().splitlines()])
|
||||
|
||||
process = self.device.shell_popen(
|
||||
["sh", "-c", "'{}'".format(script)], kill_atexit=False, stdout=subprocess.PIPE)
|
||||
|
||||
self.assertEqual("Waiting\n", process.stdout.readline())
|
||||
process.send_signal(signal.SIGINT)
|
||||
process.wait()
|
||||
|
||||
# Waiting for the local adb to finish is insufficient, since it hangs
|
||||
# up immediately.
|
||||
time.sleep(0.25)
|
||||
|
||||
stdout, _ = self.device.shell(["cat", log_path])
|
||||
self.assertEqual(stdout.strip(), "SIGHUP")
|
||||
|
||||
|
||||
class ArgumentEscapingTest(DeviceTest):
|
||||
def test_shell_escaping(self):
|
||||
|
|
Loading…
Reference in New Issue