Commit c04aa203 authored by Johannes Bechberger's avatar Johannes Bechberger

Fix installation and Windows issues

parent 9a87aac9
VERSION = "0.42"
\ No newline at end of file
......@@ -2,9 +2,11 @@ import logging
import os
from pprint import pprint
import sys
import mjtest.util.utils
from os.path import dirname
sys.path.append(dirname(__file__))
import util.utils
import argparse
from mjtest.environment import TestMode, Environment, TEST_MODES
from environment import TestMode, Environment, TEST_MODES
from mjtest.test.tests import TestSuite
# adapted from http://stackoverflow.com/a/8527629
......
......@@ -55,16 +55,15 @@ class Environment:
self.parallel = parallel
self.timeout = timeout
if tmp_dir:
if report_dir:
self.report_dir = os.path.abspath(os.path.expandvars(report_dir))
if not os.path.exists(report_dir):
os.mkdir(self.report_dir)
else:
self.report_dir = os.path.join(get_mjtest_basedir(), "reports")
if not os.path.exists(self.report_dir):
os.mkdir(self.report_dir)
self.report_dir = os.path.join(self.report_dir, datetime.now().strftime("%d.%m.%y:%X"))
self.report_dir = os.path.join(self.report_dir, datetime.now().strftime("%d-%m-%y_%H-%M-%S"))
os.mkdir(self.report_dir)
logging.basicConfig(level=self.LOG_LEVELS[log_level])
......
......@@ -5,7 +5,13 @@ Convenience function
Alternative to subprocess and os.system
"""
import subprocess
import resource
has_resource_module = True
try:
import resource
except ImportError:
has_resource_module = False
pass
import sys
import signal
import threading
......@@ -24,6 +30,8 @@ class SigKill(Exception):
def _lower_rlimit(res, limit):
if not has_resource_module:
return
(soft, hard) = resource.getrlimit(res)
if soft > limit or soft == resource.RLIM_INFINITY:
soft = limit
......@@ -51,6 +59,8 @@ class _Execute(object):
rlimit['RLIMIT_FSIZE'] = 512 * MB
def _set_rlimit(self):
if not has_resource_module:
return
if self.timeout > 0.0:
_lower_rlimit(resource.RLIMIT_CPU, self.timeout)
for k,v in self.rlimit.items():
......@@ -58,11 +68,14 @@ class _Execute(object):
def _run_process(self):
try:
prexec_args = {}
if has_resource_module:
prexec_args["preexec_fn"] = self._set_rlimit
self.proc = subprocess.Popen(self.cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
preexec_fn=self._set_rlimit,
env=self.env)
env=self.env,
**prexec_args)
x = self.proc.communicate()
self.out, self.err = x
self.returncode = self.proc.returncode
......@@ -107,6 +120,8 @@ def execute(cmd, env=None, timeout=0, rlimit=None, propagate_sigint=True):
rlimit = dict()
if cmd is str:
cmd = filter(lambda x: x, cmd.split(' '))
else:
cmd = list(filter(lambda x: x, cmd[0].split(' '))) + cmd[1:]
exc = _Execute(cmd, timeout, env, rlimit)
(out, err, returncode) = exc.run()
if returncode == -signal.SIGINT:
......
......@@ -5,7 +5,7 @@ import sys
def get_mjtest_basedir() -> str:
return path.dirname(path.dirname(path.dirname(path.abspath(__file__))))
return path.dirname(path.dirname(path.dirname(path.realpath(__file__))))
""" Colored logging handler that is used for the root logger """
......
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