selftests/functional: Add Ctrl+C behavior test

Run avocado in a long test, interrupt it and verify if
the runner displays the appropriate behavior, in terms
of exit code and output.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 2aff817c
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
import json import json
import unittest import unittest
import os import os
import signal
import shutil import shutil
import sys import sys
import tempfile import tempfile
...@@ -113,6 +114,25 @@ class RunnerOperationTest(unittest.TestCase): ...@@ -113,6 +114,25 @@ class RunnerOperationTest(unittest.TestCase):
self.assertEqual(result.exit_status, expected_rc, self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" % (expected_rc, result)) "Avocado did not return rc %d:\n%s" % (expected_rc, result))
def test_runner_ctrl_c(self):
os.chdir(basedir)
cmd_line = './scripts/avocado run sleeptenmin'
sp = process.SubProcess(cmd_line)
# Let it run for 3 seconds, then send a SIGINT
# (translates to KeyboardInterrupt)
sp.wait(timeout=3, sig=signal.SIGINT)
result = sp.result
output = result.stdout + result.stderr
expected_rc = 2
unexpected_rc = 3
self.assertNotEqual(result.exit_status, unexpected_rc,
"Avocado crashed (rc %d):\n%s" % (unexpected_rc, result))
self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" % (expected_rc, result))
self.assertIn("Interrupted by user request", output,
"Avocado did not display interruption message. "
"Output:\n%s" % output)
class RunnerDropinTest(unittest.TestCase): class RunnerDropinTest(unittest.TestCase):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册