Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe50bb71 authored by Josh Gao's avatar Josh Gao
Browse files

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 cd5d7376, fails before, passes after
Change-Id: I8c431e10fc76da5a9fd404dd70f17bb8a8df24e6
parent 0b47d083
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -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):