From 8767374bfa8851be8cf949e6e75de6a2a5c823c4 Mon Sep 17 00:00:00 2001 From: Alex Groce Date: Fri, 13 Jul 2018 10:20:50 -0700 Subject: [PATCH] log the run so travis doesn't timeout --- tests/logrun.py | 21 +++++++++++++++++++++ tests/test_basic_functionality.py | 21 +++++++++------------ 2 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 tests/logrun.py diff --git a/tests/logrun.py b/tests/logrun.py new file mode 100644 index 0000000..0626f3f --- /dev/null +++ b/tests/logrun.py @@ -0,0 +1,21 @@ +from __future__ import print_function +import subprocess +import time + +def logrun(cmd, file, timeout): + with open(file, 'w') as outf: + p = subprocess.Popen(cmd, stdout=outf, stderr=outf) + start = time.time() + oldContents = "" + while (p.poll() is None) and ((time.time() - start) < timeout): + with open(file, 'r') as inf: + contents = inf.read() + if len(contents) > len(oldContents): + print(contents[len(oldContents):], end="") + oldContents = contents + time.sleep(1) + print() + if p.poll() is None: + return ("TIMEOUT", contents) + return (p.returncode, contents) + diff --git a/tests/test_basic_functionality.py b/tests/test_basic_functionality.py index cb7f346..2d8be55 100644 --- a/tests/test_basic_functionality.py +++ b/tests/test_basic_functionality.py @@ -1,23 +1,20 @@ from __future__ import print_function import os -import subprocess from unittest import TestCase +import logrun class TestBasicFunctionality(TestCase): def test_basic_functionality(self): deepstate = os.getenv("DEEPSTATE_CMD") + if deepstate is None: + deepstate = "deepstate-angr" # default to angr in an environment without a defined command - r = subprocess.call([deepstate + " build/examples/IntegerArithmetic | tee deepstate.out"], - shell=True) + (r, output) = logrun.logrun([deepstate, "build/examples/IntegerArithmetic"], + "deepstate.out", 1800) self.assertEqual(r, 0) - with open("deepstate.out", 'r') as outf: - result = outf.read() - - print ("RESULT:", result) - - self.assertTrue("Passed: Arithmetic_AdditionIsCommutative" in result) - self.assertTrue("Passed: Arithmetic_AdditionIsAssociative" in result) - self.assertTrue("Passed: Arithmetic_InvertibleMultiplication_CanFail" in result) - self.assertTrue("Failed: Arithmetic_InvertibleMultiplication_CanFail" in result) + self.assertTrue("Passed: Arithmetic_AdditionIsCommutative" in output) + self.assertTrue("Passed: Arithmetic_AdditionIsAssociative" in output) + self.assertTrue("Passed: Arithmetic_InvertibleMultiplication_CanFail" in output) + self.assertTrue("Failed: Arithmetic_InvertibleMultiplication_CanFail" in output)