added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / option / stack-size.py
blobe9cb38e73b9b2f8e70bd831af2b530b13a880f61
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
14 # The above copyright notice and this permission notice shall be included
15 # in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
18 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
19 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 import TestSCons
27 _python_ = TestSCons._python_
29 test = TestSCons.TestSCons()
31 isStackSizeAvailable = False
32 try:
33 import threading
34 isStackSizeAvailable = hasattr(threading,'stack_size')
35 except ImportError:
36 pass
38 test.subdir('work1', 'work2')
40 test.write('build.py', r"""
41 import sys
42 with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as infp:
43 f.write(infp.read())
44 """)
47 test.write(['work1', 'SConstruct'], """
48 B = Builder(action = r'%(_python_)s ../build.py $TARGETS $SOURCES')
49 DefaultEnvironment(tools=[]) # test speedup
50 env = Environment(tools=[], BUILDERS = { 'B' : B })
51 f1 = env.B(target = 'f1.out', source = 'f1.in')
52 f2 = env.B(target = 'f2.out', source = 'f2.in')
53 Requires(f2, f1)
54 """ % locals())
56 test.write(['work1', 'f1.in'], "f1.in\n")
57 test.write(['work1', 'f2.in'], "f2.in\n")
60 test.write(['work2', 'SConstruct'], """
61 SetOption('stack_size', 128)
62 B = Builder(action = r'%(_python_)s ../build.py $TARGETS $SOURCES')
63 DefaultEnvironment(tools=[]) # test speedup
64 env = Environment(BUILDERS = { 'B' : B })
65 f1 = env.B(target = 'f1.out', source = 'f1.in')
66 f2 = env.B(target = 'f2.out', source = 'f2.in')
67 Requires(f2, f1)
68 """ % locals())
70 test.write(['work2', 'f1.in'], "f1.in\n")
71 test.write(['work2', 'f2.in'], "f2.in\n")
75 expected_stdout = test.wrap_stdout("""\
76 %(_python_)s ../build.py f1.out f1.in
77 %(_python_)s ../build.py f2.out f2.in
78 """ % locals())
80 re_expected_stdout = expected_stdout.replace('\\', '\\\\')
82 expect_unsupported = """
83 scons: warning: Setting stack size is unsupported by this version of Python:
84 (('module' object|'threading' module) has no attribute 'stack_size'|stack_size)
85 File .*
86 """
90 # Test without any options
92 test.run(chdir='work1',
93 arguments = '.',
94 stdout=expected_stdout,
95 stderr='')
96 test.must_exist(['work1', 'f1.out'])
97 test.must_exist(['work1', 'f2.out'])
99 test.run(chdir='work1',
100 arguments = '-c .')
101 test.must_not_exist(['work1', 'f1.out'])
102 test.must_not_exist(['work1', 'f2.out'])
105 # Test with -j2
107 test.run(chdir='work1',
108 arguments = '-j2 .',
109 stdout=expected_stdout,
110 stderr='')
111 test.must_exist(['work1', 'f1.out'])
112 test.must_exist(['work1', 'f2.out'])
114 test.run(chdir='work1',
115 arguments = '-j2 -c .')
116 test.must_not_exist(['work1', 'f1.out'])
117 test.must_not_exist(['work1', 'f2.out'])
121 # Test with --stack-size
123 test.run(chdir='work1',
124 arguments = '--stack-size=128 .',
125 stdout=expected_stdout,
126 stderr='')
127 test.must_exist(['work1', 'f1.out'])
128 test.must_exist(['work1', 'f2.out'])
130 test.run(chdir='work1',
131 arguments = '--stack-size=128 -c .')
132 test.must_not_exist(['work1', 'f1.out'])
133 test.must_not_exist(['work1', 'f2.out'])
136 # Test with SetOption('stack_size', 128)
138 test.run(chdir='work2',
139 arguments = '.',
140 stdout=expected_stdout,
141 stderr='')
142 test.must_exist(['work2', 'f1.out'])
143 test.must_exist(['work2', 'f2.out'])
145 test.run(chdir='work2',
146 arguments = '--stack-size=128 -c .')
147 test.must_not_exist(['work2', 'f1.out'])
148 test.must_not_exist(['work2', 'f2.out'])
150 if isStackSizeAvailable:
152 # Test with -j2 --stack-size=128
154 test.run(chdir='work1',
155 arguments = '-j2 --stack-size=128 .',
156 stdout=expected_stdout,
157 stderr='')
158 test.must_exist(['work1', 'f1.out'])
159 test.must_exist(['work1', 'f2.out'])
161 test.run(chdir='work1',
162 arguments = '-j2 --stack-size=128 -c .')
163 test.must_not_exist(['work1', 'f1.out'])
164 test.must_not_exist(['work1', 'f2.out'])
167 # Test with -j2 --stack-size=16
169 test.run(chdir='work1',
170 arguments = '-j2 --stack-size=16 .',
171 match=TestSCons.match_re,
172 stdout=re_expected_stdout,
173 stderr="""
174 scons: warning: Setting stack size failed:
175 size not valid: 16384 bytes
176 File .*
178 scons: warning: Setting stack size failed:
179 size not valid: 16384 bytes
180 File .*
181 """)
182 test.must_exist(['work1', 'f1.out'])
183 test.must_exist(['work1', 'f2.out'])
185 test.run(chdir='work1',
186 arguments = '-j2 --stack-size=16 -c .',
187 match=TestSCons.match_re,
188 stderr="""
189 scons: warning: Setting stack size failed:
190 size not valid: 16384 bytes
191 File .*
193 scons: warning: Setting stack size failed:
194 size not valid: 16384 bytes
195 File .*
196 """)
197 test.must_not_exist(['work1', 'f1.out'])
198 test.must_not_exist(['work1', 'f2.out'])
201 # Test with -j2 SetOption('stack_size', 128)
203 test.run(chdir='work2',
204 arguments = '-j2 .',
205 stdout=expected_stdout,
206 stderr='')
207 test.must_exist(['work2', 'f1.out'])
208 test.must_exist(['work2', 'f2.out'])
210 test.run(chdir='work2',
211 arguments = '-j2 -c .')
212 test.must_not_exist(['work2', 'f1.out'])
213 test.must_not_exist(['work2', 'f2.out'])
216 # Test with -j2 --stack-size=128 --warn=no-stack-size
218 test.run(chdir='work1',
219 arguments = '-j2 --stack-size=128 --warn=no-stack-size .',
220 stdout=expected_stdout,
221 stderr='')
222 test.must_exist(['work1', 'f1.out'])
223 test.must_exist(['work1', 'f2.out'])
225 test.run(chdir='work1',
226 arguments = '-j2 --stack-size=128 --warn=no-stack-size -c .')
227 test.must_not_exist(['work1', 'f1.out'])
228 test.must_not_exist(['work1', 'f2.out'])
231 # Test with -j2 --stack-size=16 --warn=no-stack-size
233 test.run(chdir='work1',
234 arguments = '-j2 --stack-size=16 --warn=no-stack-size .',
235 stdout=expected_stdout,
236 stderr='')
237 test.must_exist(['work1', 'f1.out'])
238 test.must_exist(['work1', 'f2.out'])
240 test.run(chdir='work1',
241 arguments = '-j2 --stack-size=16 --warn=no-stack-size -c .')
242 test.must_not_exist(['work1', 'f1.out'])
243 test.must_not_exist(['work1', 'f2.out'])
246 # Test with -j2 --warn=no-stack-size SetOption('stack_size', 128)
248 test.run(chdir='work2',
249 arguments = '-j2 --warn=no-stack-size .',
250 stdout=expected_stdout,
251 stderr='')
252 test.must_exist(['work2', 'f1.out'])
253 test.must_exist(['work2', 'f2.out'])
255 test.run(chdir='work2',
256 arguments = '-j2 --warn=no-stack-size -c .')
257 test.must_not_exist(['work2', 'f1.out'])
258 test.must_not_exist(['work2', 'f2.out'])
260 else:
263 # Test with -j2 --stack-size=128
265 test.run(chdir='work1',
266 arguments = '-j2 --stack-size=128 .',
267 match=TestSCons.match_re,
268 stdout=re_expected_stdout,
269 stderr=expect_unsupported)
270 test.must_exist(['work1', 'f1.out'])
271 test.must_exist(['work1', 'f2.out'])
273 test.run(chdir='work1',
274 arguments = '-j2 --stack-size=128 -c .',
275 match=TestSCons.match_re,
276 stderr=expect_unsupported)
277 test.must_not_exist(['work1', 'f1.out'])
278 test.must_not_exist(['work1', 'f2.out'])
281 # Test with -j2 --stack-size=16
283 test.run(chdir='work1',
284 arguments = '-j2 --stack-size=16 .',
285 match=TestSCons.match_re,
286 stdout=re_expected_stdout,
287 stderr=expect_unsupported)
288 test.must_exist(['work1', 'f1.out'])
289 test.must_exist(['work1', 'f2.out'])
291 test.run(chdir='work1',
292 arguments = '-j2 --stack-size=16 -c .',
293 match=TestSCons.match_re,
294 stderr=expect_unsupported)
295 test.must_not_exist(['work1', 'f1.out'])
296 test.must_not_exist(['work1', 'f2.out'])
299 # Test with -j2 SetOption('stack_size', 128)
301 test.run(chdir='work2',
302 arguments = '-j2 .',
303 match=TestSCons.match_re,
304 stdout=re_expected_stdout,
305 stderr=expect_unsupported)
306 test.must_exist(['work2', 'f1.out'])
307 test.must_exist(['work2', 'f2.out'])
309 test.run(chdir='work2',
310 arguments = '-j2 -c .',
311 match=TestSCons.match_re,
312 stderr=expect_unsupported)
313 test.must_not_exist(['work2', 'f1.out'])
314 test.must_not_exist(['work2', 'f2.out'])
317 # Test with -j2 --stack-size=128 --warn=no-stack-size
319 test.run(chdir='work1',
320 arguments = '-j2 --stack-size=128 --warn=no-stack-size .',
321 stdout=expected_stdout,
322 stderr='')
323 test.must_exist(['work1', 'f1.out'])
324 test.must_exist(['work1', 'f2.out'])
326 test.run(chdir='work1',
327 arguments = '-j2 --stack-size=128 --warn=no-stack-size -c .')
328 test.must_not_exist(['work1', 'f1.out'])
329 test.must_not_exist(['work1', 'f2.out'])
332 # Test with -j2 --stack-size=16 --warn=no-stack-size
334 test.run(chdir='work1',
335 arguments = '-j2 --stack-size=16 --warn=no-stack-size .',
336 stdout=expected_stdout,
337 stderr='')
338 test.must_exist(['work1', 'f1.out'])
339 test.must_exist(['work1', 'f2.out'])
341 test.run(chdir='work1',
342 arguments = '-j2 --stack-size=16 --warn=no-stack-size -c .')
343 test.must_not_exist(['work1', 'f1.out'])
344 test.must_not_exist(['work1', 'f2.out'])
347 # Test with -j2 --warn=no-stack-size SetOption('stack_size', 128)
349 test.run(chdir='work2',
350 arguments = '-j2 --warn=no-stack-size .',
351 stdout=expected_stdout,
352 stderr='')
353 test.must_exist(['work2', 'f1.out'])
354 test.must_exist(['work2', 'f2.out'])
356 test.run(chdir='work2',
357 arguments = '-j2 --warn=no-stack-size -c .')
358 test.must_not_exist(['work2', 'f1.out'])
359 test.must_not_exist(['work2', 'f2.out'])
361 test.pass_test()
363 # Local Variables:
364 # tab-width:4
365 # indent-tabs-mode:nil
366 # End:
367 # vim: set expandtab tabstop=4 shiftwidth=4: