From: y0169.zhang Date: Tue, 27 Dec 2016 07:09:14 +0000 (+0900) Subject: Add pty to run docker-based tests. X-Git-Tag: submit/devel/20190730.074604~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7a473aacc8a77309d5c6660820646275d73cf2eb;p=tools%2Fitest-core.git Add pty to run docker-based tests. Change-Id: I0d8aae8f7e8d6c07f3e852116a45a657c4d93efb --- diff --git a/debian/itest-core.install b/debian/itest-core.install index 7e5e164..0ff6eb9 100644 --- a/debian/itest-core.install +++ b/debian/itest-core.install @@ -3,4 +3,5 @@ usr/lib/python*/*packages/itest/conf/*.py usr/lib/python*/*packages/imgdiff/*.py usr/lib/python*/*packages/itest-*.egg-info usr/bin/runtest +usr/bin/runtest_pty usr/bin/imgdiff diff --git a/packaging/itest-core.spec b/packaging/itest-core.spec index ac26273..effa514 100644 --- a/packaging/itest-core.spec +++ b/packaging/itest-core.spec @@ -76,6 +76,7 @@ Use this plugin with ``nosetests --with-xcase xml case`` %{python_sitelib}/imgdiff/* %{python_sitelib}/itest/* %{_bindir}/runtest +%{_bindir}/runtest_pty %{_bindir}/imgdiff %files -n spm diff --git a/scripts/runtest_pty b/scripts/runtest_pty new file mode 100644 index 0000000..03925d1 --- /dev/null +++ b/scripts/runtest_pty @@ -0,0 +1,46 @@ +#!/usr/bin/env python +#!-*-coding:utf-8-*- + +import sys +import os +import pty +import select +import time +import subprocess + +def run_with_pty(command): + ret = 0 + + if command: + (master, slave) = pty.openpty() + process = subprocess.Popen(command, stdin=slave, stdout=slave, stderr=slave, shell=True) + while True: + r, w, e = select.select([master], [], [], 0) # timeout of 0 means "poll" + if r: + line = os.read(master, 1024) + ##### + # Warning, uncomment at your own risk - several programs + # print empty lines that will cause this to break and + # the output will be all goofed up. + #if not line : + # break + #print output.rstrip() + os.write(1, line) + elif process.poll() is not None : + break + os.close(master) + os.close(slave) + process.wait() + ret = process.returncode + + return ret + +def main(): + cmd = "runtest " + for i in range(1, len(sys.argv)): + cmd = cmd + sys.argv[i] + " " + + sys.exit(run_with_pty(cmd)) + +if __name__=="__main__": + main() diff --git a/setup.py b/setup.py index 9c5cd0b..e6c6932 100644 --- a/setup.py +++ b/setup.py @@ -23,6 +23,7 @@ setup(name='itest', }, scripts=[ 'scripts/runtest', + 'scripts/runtest_pty', 'scripts/imgdiff', 'scripts/spm', ],