- # 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)
-
- # 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)
-
- # 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 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