adb: add test for SIGHUP behavior.

This keeps regressing, so add a test to keep this from happening.

Bug: http://b/23603716
Bug: http://b/25965770
Bug: http://b/29565233
Test: Ran test with/without commit cd5d737, fails before, passes after
Change-Id: I8c431e10fc76da5a9fd404dd70f17bb8a8df24e6
This commit is contained in:
Josh Gao 2016-06-22 18:27:22 -07:00
parent 0b47d08303
commit fe50bb713b
1 changed files with 31 additions and 0 deletions

View File

@ -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):