Commit c04aa203 authored by Johannes Bechberger's avatar Johannes Bechberger

Fix installation and Windows issues

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