SConscript (3020:a33d8709d348) SConscript (3021:3b67ff91f0d6)
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2006 The Regents of The University of Michigan
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer;
10# redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution;
13# neither the name of the copyright holders nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29# Authors: Steve Reinhardt
30# Kevin Lim
31
32import os
33import sys
34import glob
35from SCons.Script.SConscript import SConsEnvironment
36
37Import('env')
38
39env['DIFFOUT'] = File('diff-out')
40
41# Dict that accumulates lists of tests by category (quick, medium, long)
42env.Tests = {}
43
44def contents(node):
45 return file(str(node)).read()
46
47def check_test(target, source, env):
48 """Check output from running test.
49
50 Targets are as follows:
51 target[0] : outdiff
52 target[1] : statsdiff
53 target[2] : status
54
55 """
56 # make sure target files are all gone
57 for t in target:
58 if os.path.exists(t.abspath):
59 Execute(Delete(t.abspath))
60 # Run diff on output & ref directories to find differences.
61 # Exclude m5stats.txt since we will use diff-out on that.
62 Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' +
63 '-I "^command line:" ' + # for stdout file
64 '-I "^M5 compiled " ' + # for stderr file
65 '-I "^M5 started " ' + # for stderr file
66 '-I "^M5 executing on " ' + # for stderr file
67 '-I "^Simulation complete at" ' + # for stderr file
68 '-I "^Listening for" ' + # for stderr file
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2006 The Regents of The University of Michigan
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer;
10# redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution;
13# neither the name of the copyright holders nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29# Authors: Steve Reinhardt
30# Kevin Lim
31
32import os
33import sys
34import glob
35from SCons.Script.SConscript import SConsEnvironment
36
37Import('env')
38
39env['DIFFOUT'] = File('diff-out')
40
41# Dict that accumulates lists of tests by category (quick, medium, long)
42env.Tests = {}
43
44def contents(node):
45 return file(str(node)).read()
46
47def check_test(target, source, env):
48 """Check output from running test.
49
50 Targets are as follows:
51 target[0] : outdiff
52 target[1] : statsdiff
53 target[2] : status
54
55 """
56 # make sure target files are all gone
57 for t in target:
58 if os.path.exists(t.abspath):
59 Execute(Delete(t.abspath))
60 # Run diff on output & ref directories to find differences.
61 # Exclude m5stats.txt since we will use diff-out on that.
62 Execute(env.subst('diff -ubr ${SOURCES[0].dir} ${SOURCES[1].dir} ' +
63 '-I "^command line:" ' + # for stdout file
64 '-I "^M5 compiled " ' + # for stderr file
65 '-I "^M5 started " ' + # for stderr file
66 '-I "^M5 executing on " ' + # for stderr file
67 '-I "^Simulation complete at" ' + # for stderr file
68 '-I "^Listening for" ' + # for stderr file
69 '-I "listening for remote gdb" ' + # for stderr file
69 '--exclude=m5stats.txt --exclude=SCCS ' +
70 '--exclude=${TARGETS[0].file} ' +
71 '> ${TARGETS[0]}', target=target, source=source), None)
72 print "===== Output differences ====="
73 print contents(target[0])
74 # Run diff-out on m5stats.txt file
75 status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}',
76 target=target, source=source),
77 strfunction=None)
78 print "===== Statistics differences ====="
79 print contents(target[1])
80 # Generate status file contents based on exit status of diff-out
81 if status == 0:
82 status_str = "passed."
83 else:
84 status_str = "FAILED!"
85 f = file(str(target[2]), 'w')
86 print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \
87 status_str
88 f.close()
89 # done
90 return 0
91
92def check_test_string(target, source, env):
93 return env.subst("Comparing outputs in ${TARGETS[0].dir}.",
94 target=target, source=source)
95
96testAction = env.Action(check_test, check_test_string)
97
98def print_test(target, source, env):
99 print '***** ' + contents(source[0])
100 return 0
101
102printAction = env.Action(print_test, strfunction = None)
103
104def update_test(target, source, env):
105 """Update reference test outputs.
106
107 Target is phony. First two sources are the ref & new m5stats.txt
108 files, respectively. We actually copy everything in the
109 respective directories except the status & diff output files.
110
111 """
112 dest_dir = str(source[0].get_dir())
113 src_dir = str(source[1].get_dir())
114 dest_files = os.listdir(dest_dir)
115 src_files = os.listdir(src_dir)
116 # Exclude status & diff outputs
117 for f in ('outdiff', 'statsdiff', 'status'):
118 if f in src_files:
119 src_files.remove(f)
120 for f in src_files:
121 if f in dest_files:
122 print " Replacing file", f
123 dest_files.remove(f)
124 else:
125 print " Creating new file", f
126 copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f))
127 copyAction.strfunction = None
128 Execute(copyAction)
129 # warn about any files in dest not overwritten (other than SCCS dir)
130 if 'SCCS' in dest_files:
131 dest_files.remove('SCCS')
132 if dest_files:
133 print "Warning: file(s) in", dest_dir, "not updated:",
134 print ', '.join(dest_files)
135 return 0
136
137def update_test_string(target, source, env):
138 return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}",
139 target=target, source=source)
140
141updateAction = env.Action(update_test, update_test_string)
142
143def test_builder(env, ref_dir):
144 """Define a test."""
145
146 (category, name, _ref, isa, opsys, config) = ref_dir.split('/')
147 assert(_ref == 'ref')
148
149 # target path (where test output goes) is the same except without
150 # the 'ref' component
151 tgt_dir = os.path.join(category, name, isa, opsys, config)
152
153 # prepend file name with tgt_dir
154 def tgt(f):
155 return os.path.join(tgt_dir, f)
156
157 ref_stats = os.path.join(ref_dir, 'm5stats.txt')
158 new_stats = tgt('m5stats.txt')
159 status_file = tgt('status')
160
161 # Base command for running test. We mess around with indirectly
162 # referring to files via SOURCES and TARGETS so that scons can
163 # mess with paths all it wants to and we still get the right
164 # files.
165 base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]} %s' % tgt_dir
166 # stdout and stderr files
167 cmd_stdout = '${TARGETS[0]}'
168 cmd_stderr = '${TARGETS[1]}'
169
170 # Prefix test run with batch job submission command if appropriate.
171 # Output redirection is also different for batch runs.
172 # Batch command also supports timeout arg (in seconds, not minutes).
173 if env['BATCH']:
174 cmd = [env['BATCH_CMD'], '-t', str(timeout * 60),
175 '-o', cmd_stdout, '-e', cmd_stderr, base_cmd]
176 else:
177 cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr]
178
179 env.Command([tgt('stdout'), tgt('stderr'), new_stats],
180 [env.M5Binary, 'run.py'], ' '.join(cmd))
181
182 # order of targets is important... see check_test
183 env.Command([tgt('outdiff'), tgt('statsdiff'), status_file],
184 [ref_stats, new_stats],
185 testAction)
186
187 # phony target to echo status
188 if env['update_ref']:
189 p = env.Command(tgt('_update'),
190 [ref_stats, new_stats, status_file],
191 updateAction)
192 else:
193 p = env.Command(tgt('_print'), [status_file], printAction)
194
195 env.AlwaysBuild(p)
196
197
198# Figure out applicable configs based on build type
199configs = []
200if env['FULL_SYSTEM']:
201 if env['TARGET_ISA'] == 'alpha':
202 if not env['ALPHA_TLASER']:
203 configs += ['tsunami-simple-atomic',
204 'tsunami-simple-timing',
205 'tsunami-simple-atomic-dual',
206 'tsunami-simple-timing-dual']
207else:
208 configs += ['simple-atomic', 'simple-timing']
209
210cwd = os.getcwd()
211os.chdir(str(Dir('.').srcdir))
212for config in configs:
213 dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config))
214 for d in dirs:
215 test_builder(env, d)
216os.chdir(cwd)
70 '--exclude=m5stats.txt --exclude=SCCS ' +
71 '--exclude=${TARGETS[0].file} ' +
72 '> ${TARGETS[0]}', target=target, source=source), None)
73 print "===== Output differences ====="
74 print contents(target[0])
75 # Run diff-out on m5stats.txt file
76 status = Execute(env.subst('$DIFFOUT $SOURCES > ${TARGETS[1]}',
77 target=target, source=source),
78 strfunction=None)
79 print "===== Statistics differences ====="
80 print contents(target[1])
81 # Generate status file contents based on exit status of diff-out
82 if status == 0:
83 status_str = "passed."
84 else:
85 status_str = "FAILED!"
86 f = file(str(target[2]), 'w')
87 print >>f, env.subst('${TARGETS[2].dir}', target=target, source=source), \
88 status_str
89 f.close()
90 # done
91 return 0
92
93def check_test_string(target, source, env):
94 return env.subst("Comparing outputs in ${TARGETS[0].dir}.",
95 target=target, source=source)
96
97testAction = env.Action(check_test, check_test_string)
98
99def print_test(target, source, env):
100 print '***** ' + contents(source[0])
101 return 0
102
103printAction = env.Action(print_test, strfunction = None)
104
105def update_test(target, source, env):
106 """Update reference test outputs.
107
108 Target is phony. First two sources are the ref & new m5stats.txt
109 files, respectively. We actually copy everything in the
110 respective directories except the status & diff output files.
111
112 """
113 dest_dir = str(source[0].get_dir())
114 src_dir = str(source[1].get_dir())
115 dest_files = os.listdir(dest_dir)
116 src_files = os.listdir(src_dir)
117 # Exclude status & diff outputs
118 for f in ('outdiff', 'statsdiff', 'status'):
119 if f in src_files:
120 src_files.remove(f)
121 for f in src_files:
122 if f in dest_files:
123 print " Replacing file", f
124 dest_files.remove(f)
125 else:
126 print " Creating new file", f
127 copyAction = Copy(os.path.join(dest_dir, f), os.path.join(src_dir, f))
128 copyAction.strfunction = None
129 Execute(copyAction)
130 # warn about any files in dest not overwritten (other than SCCS dir)
131 if 'SCCS' in dest_files:
132 dest_files.remove('SCCS')
133 if dest_files:
134 print "Warning: file(s) in", dest_dir, "not updated:",
135 print ', '.join(dest_files)
136 return 0
137
138def update_test_string(target, source, env):
139 return env.subst("Updating ${SOURCES[0].dir} from ${SOURCES[1].dir}",
140 target=target, source=source)
141
142updateAction = env.Action(update_test, update_test_string)
143
144def test_builder(env, ref_dir):
145 """Define a test."""
146
147 (category, name, _ref, isa, opsys, config) = ref_dir.split('/')
148 assert(_ref == 'ref')
149
150 # target path (where test output goes) is the same except without
151 # the 'ref' component
152 tgt_dir = os.path.join(category, name, isa, opsys, config)
153
154 # prepend file name with tgt_dir
155 def tgt(f):
156 return os.path.join(tgt_dir, f)
157
158 ref_stats = os.path.join(ref_dir, 'm5stats.txt')
159 new_stats = tgt('m5stats.txt')
160 status_file = tgt('status')
161
162 # Base command for running test. We mess around with indirectly
163 # referring to files via SOURCES and TARGETS so that scons can
164 # mess with paths all it wants to and we still get the right
165 # files.
166 base_cmd = '${SOURCES[0]} -d $TARGET.dir ${SOURCES[1]} %s' % tgt_dir
167 # stdout and stderr files
168 cmd_stdout = '${TARGETS[0]}'
169 cmd_stderr = '${TARGETS[1]}'
170
171 # Prefix test run with batch job submission command if appropriate.
172 # Output redirection is also different for batch runs.
173 # Batch command also supports timeout arg (in seconds, not minutes).
174 if env['BATCH']:
175 cmd = [env['BATCH_CMD'], '-t', str(timeout * 60),
176 '-o', cmd_stdout, '-e', cmd_stderr, base_cmd]
177 else:
178 cmd = [base_cmd, '>', cmd_stdout, '2>', cmd_stderr]
179
180 env.Command([tgt('stdout'), tgt('stderr'), new_stats],
181 [env.M5Binary, 'run.py'], ' '.join(cmd))
182
183 # order of targets is important... see check_test
184 env.Command([tgt('outdiff'), tgt('statsdiff'), status_file],
185 [ref_stats, new_stats],
186 testAction)
187
188 # phony target to echo status
189 if env['update_ref']:
190 p = env.Command(tgt('_update'),
191 [ref_stats, new_stats, status_file],
192 updateAction)
193 else:
194 p = env.Command(tgt('_print'), [status_file], printAction)
195
196 env.AlwaysBuild(p)
197
198
199# Figure out applicable configs based on build type
200configs = []
201if env['FULL_SYSTEM']:
202 if env['TARGET_ISA'] == 'alpha':
203 if not env['ALPHA_TLASER']:
204 configs += ['tsunami-simple-atomic',
205 'tsunami-simple-timing',
206 'tsunami-simple-atomic-dual',
207 'tsunami-simple-timing-dual']
208else:
209 configs += ['simple-atomic', 'simple-timing']
210
211cwd = os.getcwd()
212os.chdir(str(Dir('.').srcdir))
213for config in configs:
214 dirs = glob.glob('*/*/ref/%s/*/%s' % (env['TARGET_ISA'], config))
215 for d in dirs:
216 test_builder(env, d)
217os.chdir(cwd)