changeset f3184dd8257f in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=f3184dd8257f
description:
scons: Use the new test framework from scons
Rewrite the SCons script responsible for launching tests to use the
new test framework. The biggest visible change after this changeset is
that SCons no longer produces a "status" file in test build
directories. Instead, it creates a status.pickle file. That file can
be inspected using the new tests.py script. Another visible change is
that timed out tests are now reported as failed rather than a using a
separate summary message.
Since the pickle file will remain in the build directory after running
tests, it's now possible to convert the test results into other
formats. For example:
./tests/tests.py show --format junit -o junit.xml \
`find build/ -name status.pickle`
To better facilitate running outside of scons, there is now a set of
targets that generate test listings that can be used by the test
script. There are currently three targets, quick.list, long.list, and
all.list. For example:
scons build/ARM/tests/opt/all.list
for F in `cat build/ARM/tests/opt/all.list`; do
./tests/tests.py run build/ARM/gem5.opt $F
done
Change-Id: I2c0f8ca0080d7af737362e198eda4cb3a72e6c36
Signed-off-by: Andreas Sandberg <[email protected]>
Reviewed-by: Curtis Dunham <[email protected]>
diffstat:
tests/SConscript | 442 +++++++++++++++++++-----------------------------------
1 files changed, 156 insertions(+), 286 deletions(-)
diffs (truncated from 521 to 300 lines):
diff -r e9b095599766 -r f3184dd8257f tests/SConscript
--- a/tests/SConscript Tue May 31 11:26:59 2016 +0100
+++ b/tests/SConscript Tue May 31 11:27:00 2016 +0100
@@ -1,5 +1,17 @@
# -*- mode:python -*-
-
+#
+# Copyright (c) 2016 ARM Limited
+# All rights reserved
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
# Copyright (c) 2004-2006 The Regents of The University of Michigan
# All rights reserved.
#
@@ -28,157 +40,62 @@
#
# Authors: Steve Reinhardt
# Kevin Lim
+# Andreas Sandberg
-import os, signal
-import sys, time
-import glob
from SCons.Script.SConscript import SConsEnvironment
+import os
+import pickle
+import sys
+
+sys.path.insert(0, Dir(".").srcnode().abspath)
+import testing.tests as tests
+import testing.results as results
Import('env')
-env['DIFFOUT'] = File('diff-out')
-
# get the termcap from the environment
termcap = env['TERMCAP']
# Dict that accumulates lists of tests by category (quick, medium, long)
env.Tests = {}
+gpu_isa = env['TARGET_GPU_ISA'] if env['BUILD_GPU'] else None
+for cat in tests.all_categories:
+ env.Tests[cat] = tuple(
+ tests.get_tests(env["TARGET_ISA"],
+ categories=(cat, ),
+ ruby_protocol=env["PROTOCOL"],
+ gpu_isa=gpu_isa))
-def contents(node):
- return file(str(node)).read()
-
-# functions to parse return value from scons Execute()... not the same
-# as wait() etc., so python built-in os funcs don't work.
-def signaled(status):
- return (status & 0x80) != 0;
-
-def signum(status):
- return (status & 0x7f);
-
-# List of signals that indicate that we should retry the test rather
-# than consider it failed.
-retry_signals = (signal.SIGTERM, signal.SIGKILL, signal.SIGINT,
- signal.SIGQUIT, signal.SIGHUP)
-
-# regular expressions of lines to ignore when diffing outputs
-output_ignore_regexes = (
- '^command line:', # for stdout file
- '^gem5 compiled ', # for stderr file
- '^gem5 started ', # for stderr file
- '^gem5 executing on ', # for stderr file
- '^Simulation complete at', # for stderr file
- '^Listening for', # for stderr file
- 'listening for remote gdb', # for stderr file
- )
-
-output_ignore_args = ' '.join(["-I '"+s+"'" for s in output_ignore_regexes])
-
-output_ignore_args += ' --exclude=stats.txt --exclude=outdiff'
+def color_message(color, msg):
+ return color + msg + termcap.Normal
def run_test(target, source, env):
- """Check output from running test.
+ """Run a test and produce results as a pickle file.
Targets are as follows:
- target[0] : status
+ target[0] : Pickle file
Sources are:
source[0] : gem5 binary
source[1] : tests/run.py script
- source[2] : reference stats file
+ source[2:] : reference files
"""
- # make sure target files are all gone
- for t in target:
- if os.path.exists(t.abspath):
- env.Execute(Delete(t.abspath))
+ tgt_dir = os.path.dirname(str(target[0]))
+ config = tests.ClassicConfig(*tgt_dir.split('/')[-6:])
+ test = tests.ClassicTest(source[0].abspath, tgt_dir, config,
+ timeout=5*60*60,
+ skip_diff_out=True)
- tgt_dir = os.path.dirname(str(target[0]))
+ for ref in test.ref_files():
+ out_file = os.path.join(tgt_dir, ref)
+ if os.path.exists(out_file):
+ env.Execute(Delete(out_file))
- # Base command for running test. We mess around with indirectly
- # referring to files via SOURCES and TARGETS so that scons can mess
- # with paths all it wants to and we still get the right files.
- cmd = '${SOURCES[0]} -d %s -re ${SOURCES[1]} %s' % (tgt_dir, tgt_dir)
+ with open(target[0].abspath, "wb") as fout:
+ formatter = results.Pickle(fout=fout)
+ formatter.dump_suites([ test.run() ])
- # Prefix test run with batch job submission command if appropriate.
- # Batch command also supports timeout arg (in seconds, not minutes).
- timeout = 15 * 60 # used to be a param, probably should be again
- if env['BATCH']:
- cmd = '%s -t %d %s' % (env['BATCH_CMD'], timeout, cmd)
- # The slowest regression (bzip2) requires ~4 hours;
- # 5 hours was chosen to be conservative.
- elif env['TIMEOUT']:
- cmd = 'timeout --foreground 5h %s' % cmd
-
- # Create a default value for the status string, changed as needed
- # based on the status.
- status_str = "passed."
-
- pre_exec_time = time.time()
- status = env.Execute(env.subst(cmd, target=target, source=source))
- if status == 0:
- # gem5 terminated normally.
- # Run diff on output & ref directories to find differences.
- # Exclude the stats file since we will use diff-out on that.
-
- # NFS file systems can be annoying and not have updated yet
- # wait until we see the file modified
- statsdiff = os.path.join(tgt_dir, 'statsdiff')
- m_time = 0
- nap = 0
- while m_time < pre_exec_time and nap < 10:
- try:
- m_time = os.stat(statsdiff).st_mtime
- except OSError:
- pass
- time.sleep(1)
- nap += 1
-
- outdiff = os.path.join(tgt_dir, 'outdiff')
- # tack 'true' on the end so scons doesn't report diff's
- # non-zero exit code as a build error
- diffcmd = 'diff -ubrs %s ${SOURCES[2].dir} %s > %s; true' \
- % (output_ignore_args, tgt_dir, outdiff)
- env.Execute(env.subst(diffcmd, target=target, source=source))
- print "===== Output differences ====="
- print contents(outdiff)
- # Run diff-out on stats.txt file
- diffcmd = '$DIFFOUT ${SOURCES[2]} %s > %s' \
- % (os.path.join(tgt_dir, 'stats.txt'), statsdiff)
- diffcmd = env.subst(diffcmd, target=target, source=source)
- diff_status = env.Execute(diffcmd, strfunction=None)
- # If there is a difference, change the status string to say so
- if diff_status != 0:
- status_str = "CHANGED!"
- print "===== Statistics differences ====="
- print contents(statsdiff)
-
- else: # gem5 exit status != 0
- # Consider it a failed test unless the exit status is 2
- status_str = "FAILED!"
- # gem5 did not terminate properly, so no need to check the output
- if env['TIMEOUT'] and status == 124:
- status_str = "TIMED-OUT!"
- elif signaled(status):
- print 'gem5 terminated with signal', signum(status)
- if signum(status) in retry_signals:
- # Consider the test incomplete; don't create a 'status' output.
- # Hand the return status to scons and let scons decide what
- # to do about it (typically terminate unless run with -k).
- return status
- elif status == 2:
- # The test was skipped, change the status string to say so
- status_str = "skipped."
- else:
- print 'gem5 exited with non-zero status', status
- # complete but failed execution (call to exit() with non-zero
- # status, SIGABORT due to assertion failure, etc.)... fall through
- # and generate FAILED status as if output comparison had failed
-
- # Generate status file contents based on exit status of gem5 and diff-out
- f = file(str(target[0]), 'w')
- print >>f, tgt_dir, status_str
- f.close()
- # done
return 0
def run_test_string(target, source, env):
@@ -188,197 +105,150 @@
testAction = env.Action(run_test, run_test_string)
def print_test(target, source, env):
- # print the status with colours to make it easier to see what
- # passed and what failed
- line = contents(source[0])
+ """Run a test and produce results as a pickle file.
- # split the line to words and get the last one
- words = line.split()
- status = words[-1]
+ Targets are as follows:
+ target[*] : Dummy targets
- # if the test failed make it red, if it passed make it green, and
- # skip the punctuation
- if status == "FAILED!" or status == "TIMED-OUT!":
- status = termcap.Red + status[:-1] + termcap.Normal + status[-1]
- elif status == "CHANGED!":
- status = termcap.Yellow + status[:-1] + termcap.Normal + status[-1]
- elif status == "passed.":
- status = termcap.Green + status[:-1] + termcap.Normal + status[-1]
- elif status == "skipped.":
- status = termcap.Cyan + status[:-1] + termcap.Normal + status[-1]
+ Sources are:
+ source[0] : Pickle file
- # put it back in the list and join with space
- words[-1] = status
- line = " ".join(words)
+ """
+ with open(source[0].abspath, "rb") as fin:
+ result = pickle.load(fin)
- print '***** ' + line
+ assert len(result) == 1
+ result = result[0]
+
+ run = result.results[0]
+ assert run.name == "gem5"
+
+ formatter = None
+ if not run:
+ status = color_message(termcap.Red, "FAILED!")
+ formatter = results.Text()
+ elif run.skipped():
+ status = color_message(termcap.Cyan, "skipped.")
+ elif result:
+ status = color_message(termcap.Green, "passed.")
+ else:
+ status = color_message(termcap.Yellow, "CHANGED!")
+ formatter = results.Text()
+
+ if formatter:
+ formatter.dump_suites([result])
+
+ print "***** %s: %s" % (source[0].dir, status)
return 0
-printAction = env.Action(print_test, strfunction = None)
-
-# Static vars for update_test:
-# - long-winded message about ignored sources
-ignore_msg = '''
-Note: The following file(s) will not be copied. New non-standard
- output files must be copied manually once before --update-ref will
- recognize them as outputs. Otherwise they are assumed to be
- inputs and are ignored.
-'''
-# - reference files always needed
-needed_files = set(['simout', 'simerr', 'stats.txt', 'config.ini'])
-# - source files we always want to ignore
-known_ignores = set(['status', 'outdiff', 'statsdiff'])
+printAction = env.Action(print_test, strfunction=None)
def update_test(target, source, env):
- """Update reference test outputs.
+ """Update test reference data
- Target is phony. First two sources are the ref & new stats.txt file
- files, respectively. We actually copy everything in the
- respective directories except the status & diff output files.
+ Targets are as follows:
+ target[0] : Dummy file
+ Sources are:
+ source[0] : Pickle file
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev