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

Commit c0c57c43 authored by Josh Gao's avatar Josh Gao Committed by android-build-merger
Browse files

Merge \\"adb: add test for SIGHUP behavior.\\" am: a355dd61

am: 05f889dd

Change-Id: I7ea1f3071fbf0f8a5dd83173c62566e08b3c2503
parents 3f8ad892 05f889dd
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):