summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/configs/dram-lowp.py20
-rw-r--r--tests/configs/learning-gem5-p1-simple.py10
-rw-r--r--tests/configs/learning-gem5-p1-two-level.py24
-rw-r--r--tests/configs/memcheck.py17
-rw-r--r--tests/run.py26
5 files changed, 40 insertions, 57 deletions
diff --git a/tests/configs/dram-lowp.py b/tests/configs/dram-lowp.py
index 20c774ea9..418514d63 100644
--- a/tests/configs/dram-lowp.py
+++ b/tests/configs/dram-lowp.py
@@ -50,19 +50,13 @@ import m5
def run_test(root):
# Called from tests/run.py
- # Set the working directory in case we are executing from
- # outside gem5's source tree
- import os
- os.chdir(os.path.join(os.path.dirname(__file__), "../"))
-
- # The path to this script is the only parameter. Delete it so
- # we can execute the script that we want to execute.
import sys
- del sys.argv[1:]
-
- # Add a specific page policy and specify the number of ranks
- sys.argv.append('-p%s' % page_policy)
- sys.argv.append('-r 2')
+ argv = [
+ sys.argv[0],
+ # Add a specific page policy and specify the number of ranks
+ '-p%s' % page_policy,
+ '-r 2',
+ ]
# Execute the script we are wrapping
- execfile(srcpath('configs/dram/low_power_sweep.py'), globals())
+ run_config('configs/dram/low_power_sweep.py', argv=argv)
diff --git a/tests/configs/learning-gem5-p1-simple.py b/tests/configs/learning-gem5-p1-simple.py
index 9ad70854e..aba538a7e 100644
--- a/tests/configs/learning-gem5-p1-simple.py
+++ b/tests/configs/learning-gem5-p1-simple.py
@@ -33,12 +33,4 @@
root = None
def run_test(root):
- # Called from tests/run.py
-
- # Set the working directory in case we are executing from
- # outside gem5's source tree
- import os
- os.chdir(os.path.join(os.path.dirname(__file__), "../"))
-
- # Execute the script we are wrapping
- execfile(srcpath('configs/learning_gem5/part1/simple.py'))
+ run_config('configs/learning_gem5/part1/simple.py')
diff --git a/tests/configs/learning-gem5-p1-two-level.py b/tests/configs/learning-gem5-p1-two-level.py
index c0a1e4662..0c355e838 100644
--- a/tests/configs/learning-gem5-p1-two-level.py
+++ b/tests/configs/learning-gem5-p1-two-level.py
@@ -32,27 +32,5 @@
# For some reason, this is implicitly needed by run.py
root = None
-import m5
-
def run_test(root):
- # Called from tests/run.py
-
-
- # Set the working directory in case we are executing from
- # outside gem5's source tree
- import os
- os.chdir(os.path.join(os.path.dirname(__file__), "../"))
-
- # Add paths that we need
- m5.util.addToPath('../configs/learning_gem5/part1')
- m5.util.addToPath('../configs/')
-
- # The path to this script is the only parameter. Delete it so we can
- # execute the script that we want to execute.
- import sys
- del sys.argv[1:]
- # Note: at this point, we could add options we want to test.
- # For instance, sys.argv.append('--l2_size=512kB')
-
- # Execute the script we are wrapping
- execfile(srcpath('configs/learning_gem5/part1/two_level.py'))
+ run_config('configs/learning_gem5/part1/two_level.py')
diff --git a/tests/configs/memcheck.py b/tests/configs/memcheck.py
index 97f8d1369..ec20431db 100644
--- a/tests/configs/memcheck.py
+++ b/tests/configs/memcheck.py
@@ -54,18 +54,11 @@ root = None
def run_test(root):
# Called from tests/run.py
- # Set the working directory in case we are executing from
- # outside gem5's source tree
- import os
- os.chdir(os.path.join(os.path.dirname(__file__), "../"))
-
- # The path to this script is the only parameter. Delete it so
- # we can execute the script that we want to execute.
import sys
- del sys.argv[1:]
-
- # Add a specific max tick
- sys.argv.append('-m %d' % maxtick)
+ argv = [
+ sys.argv[0],
+ '-m %d' % maxtick,
+ ]
# Execute the script we are wrapping
- execfile(srcpath('configs/example/memcheck.py'), globals())
+ run_config('configs/example/memcheck.py', argv=argv)
diff --git a/tests/run.py b/tests/run.py
index 845a3eb62..93ea82edd 100644
--- a/tests/run.py
+++ b/tests/run.py
@@ -177,6 +177,32 @@ def srcpath(path):
"""Path to file in gem5's source tree"""
return joinpath(os.path.dirname(__file__), "..", path)
+def run_config(config, argv=None):
+ """Execute a configuration script that is external to the test system"""
+
+ src_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../"))
+ abs_path = joinpath(src_root, config)
+
+ code = compile(open(abs_path, 'r').read(), abs_path, 'exec')
+ scope = {
+ '__file__' : config,
+ '__name__' : '__m5_main__',
+ }
+
+ # Set the working directory in case we are executing from
+ # outside gem5's source tree
+ os.chdir(src_root)
+
+ # gem5 normally adds the script's directory to the path to make
+ # script-relative imports work.
+ sys.path = [ os.path.dirname(abs_path), ] + sys.path
+
+ if argv is None:
+ sys.argv = [ config, ]
+ else:
+ sys.argv = argv
+ exec(code, scope)
+
# build configuration
sys.path.append(joinpath(tests_root, 'configs'))
test_filename = config