Commit 1d748182 authored by Vadim Rutkovsky's avatar Vadim Rutkovsky

tests: capture stdout

parent 2c3485e6
......@@ -5,15 +5,15 @@ if isA11yEnabled() is False:
from time import time, sleep
from functools import wraps
from os import strerror, errno, kill, system
from signal import signal, alarm, SIGALRM, SIGKILL
from subprocess import Popen
from os import strerror, errno, system
from signal import signal, alarm, SIGALRM
from subprocess import Popen, PIPE
from behave import step
from gi.repository import GLib, Gio
import fcntl, os
from dogtail.rawinput import keyCombo, absoluteMotion, pressKey
from dogtail.tree import root
from dogtail.utils import run
from unittest import TestCase
......@@ -125,7 +125,8 @@ class App(object):
self.a11yAppName = self.internCommand
# Trap weird bus errors
for attempt in xrange(0, 10):
for attempt in xrange(0, 30):
sleep(1)
try:
return self.a11yAppName in [x.name for x in root.applications()]
except GLib.GError:
......@@ -140,7 +141,7 @@ class App(object):
keyCombo('<Control><Alt><Shift>R')
try:
kill(self.pid, SIGKILL)
self.process.kill()
except:
# Fall back to killall
Popen("killall " + self.appCommand, shell=True).wait()
......@@ -153,8 +154,11 @@ class App(object):
self.kill()
assert not self.isRunning(), "Application cannot be stopped"
command = "%s %s" % (self.appCommand, self.parameters)
self.pid = run(command, timeout=5)
#command = "%s %s" % (self.appCommand, self.parameters)
#self.pid = run(command, timeout=5)
self.process = Popen(self.appCommand.split() + self.parameters.split(),
stdout=PIPE, stderr=PIPE, bufsize=0)
self.pid = self.process.pid
assert self.isRunning(), "Application failed to start"
return root.application(self.a11yAppName)
......@@ -222,3 +226,13 @@ def check_for_errors(context):
system("rm -rf %s > /dev/null" % folder)
raise RuntimeError("Error occurred: %s" % messages)
def non_block_read(output):
fd = output.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
try:
return output.read()
except:
return ""
......@@ -5,7 +5,7 @@ from dogtail.utils import isA11yEnabled, enableA11y
if not isA11yEnabled():
enableA11y(True)
from common_steps import App, dummy, cleanup
from common_steps import App, dummy, cleanup, non_block_read
from dogtail.config import config
import os
......@@ -57,9 +57,6 @@ def after_scenario(context, scenario):
Kill evolution (in order to make this reliable we send sigkill)
"""
try:
# Stop evolution
context.app_class.kill()
# Attach journalctl logs
if hasattr(context, "embed"):
os.system("pkexec journalctl /usr/bin/gnome-session --no-pager -o cat --since='%s'> /tmp/journal-session.log" % context.log_start_time)
......@@ -67,6 +64,14 @@ def after_scenario(context, scenario):
if data:
context.embed('text/plain', data)
context.app_class.kill()
stdout = non_block_read(context.app_class.process.stdout)
stderr = non_block_read(context.app_class.process.stderr)
context.embed('text/plain', '\n'.join(stdout))
context.embed('text/plain', '\n'.join(stderr))
# Make some pause after scenario
sleep(1)
except Exception as e:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment