Issue 2265: Add additional --taskmastertrace= messages in the Task class.
[scons.git] / test / option / stack-size.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 import string
28
29 import TestSCons
30
31 _python_ = TestSCons._python_
32
33 test = TestSCons.TestSCons()
34
35 isStackSizeAvailable = False
36 try:
37     import threading
38     isStackSizeAvailable = hasattr(threading,'stack_size')
39 except ImportError:
40     pass
41
42 test.subdir('work1', 'work2')
43
44 test.write('build.py', r"""
45 import sys
46 contents = open(sys.argv[2], 'rb').read()
47 file = open(sys.argv[1], 'wb')
48 file.write(contents)
49 file.close()
50 """)
51
52
53 test.write(['work1', 'SConstruct'], """
54 B = Builder(action = r'%(_python_)s ../build.py $TARGETS $SOURCES')
55 env = Environment(BUILDERS = { 'B' : B })
56 f1 = env.B(target = 'f1.out', source = 'f1.in')
57 f2 = env.B(target = 'f2.out', source = 'f2.in')
58 Requires(f2, f1)
59 """ % locals())
60
61 test.write(['work1', 'f1.in'], "f1.in\n")
62 test.write(['work1', 'f2.in'], "f2.in\n")
63
64
65 test.write(['work2', 'SConstruct'], """
66 SetOption('stack_size', 128)
67 B = Builder(action = r'%(_python_)s ../build.py $TARGETS $SOURCES')
68 env = Environment(BUILDERS = { 'B' : B })
69 f1 = env.B(target = 'f1.out', source = 'f1.in')
70 f2 = env.B(target = 'f2.out', source = 'f2.in')
71 Requires(f2, f1)
72 """ % locals())
73
74 test.write(['work2', 'f1.in'], "f1.in\n")
75 test.write(['work2', 'f2.in'], "f2.in\n")
76
77
78
79 expected_stdout = test.wrap_stdout("""\
80 %(_python_)s ../build.py f1.out f1.in
81 %(_python_)s ../build.py f2.out f2.in
82 """ % locals())
83
84 re_expected_stdout = string.replace(expected_stdout, '\\', '\\\\')
85
86 expect_unsupported = """
87 scons: warning: Setting stack size is unsupported by this version of Python:
88     (('module' object|'threading' module) has no attribute 'stack_size'|stack_size)
89 File .*
90 """
91
92
93 #
94 # Test without any options
95 #
96 test.run(chdir='work1', 
97          arguments = '.',
98          stdout=expected_stdout,
99          stderr='')
100 test.must_exist(['work1', 'f1.out'])
101 test.must_exist(['work1', 'f2.out'])
102
103 test.run(chdir='work1', 
104          arguments = '-c .')
105 test.must_not_exist(['work1', 'f1.out'])
106 test.must_not_exist(['work1', 'f2.out'])
107
108 #
109 # Test with -j2
110 #
111 test.run(chdir='work1', 
112          arguments = '-j2 .',
113          stdout=expected_stdout,
114          stderr='')
115 test.must_exist(['work1', 'f1.out'])
116 test.must_exist(['work1', 'f2.out'])
117
118 test.run(chdir='work1', 
119          arguments = '-j2 -c .')
120 test.must_not_exist(['work1', 'f1.out'])
121 test.must_not_exist(['work1', 'f2.out'])
122
123
124 #
125 # Test with --stack-size
126 #
127 test.run(chdir='work1', 
128          arguments = '--stack-size=128 .',
129          stdout=expected_stdout,
130          stderr='')
131 test.must_exist(['work1', 'f1.out'])
132 test.must_exist(['work1', 'f2.out'])
133
134 test.run(chdir='work1', 
135          arguments = '--stack-size=128 -c .')
136 test.must_not_exist(['work1', 'f1.out'])
137 test.must_not_exist(['work1', 'f2.out'])
138
139 #
140 # Test with SetOption('stack_size', 128)
141 #
142 test.run(chdir='work2', 
143          arguments = '.',
144          stdout=expected_stdout,
145          stderr='')
146 test.must_exist(['work2', 'f1.out'])
147 test.must_exist(['work2', 'f2.out'])
148
149 test.run(chdir='work2', 
150          arguments = '--stack-size=128 -c .')
151 test.must_not_exist(['work2', 'f1.out'])
152 test.must_not_exist(['work2', 'f2.out'])
153
154 if isStackSizeAvailable:
155     #
156     # Test with -j2 --stack-size=128
157     #
158     test.run(chdir='work1', 
159              arguments = '-j2 --stack-size=128 .',
160              stdout=expected_stdout,
161              stderr='')
162     test.must_exist(['work1', 'f1.out'])
163     test.must_exist(['work1', 'f2.out'])
164
165     test.run(chdir='work1', 
166              arguments = '-j2 --stack-size=128 -c .')
167     test.must_not_exist(['work1', 'f1.out'])
168     test.must_not_exist(['work1', 'f2.out'])
169
170     #
171     # Test with -j2 --stack-size=16
172     #
173     test.run(chdir='work1', 
174              arguments = '-j2 --stack-size=16 .',
175              match=TestSCons.match_re,
176              stdout=re_expected_stdout,
177              stderr="""
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'])
184
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 .*
192 """)
193     test.must_not_exist(['work1', 'f1.out'])
194     test.must_not_exist(['work1', 'f2.out'])
195
196     #
197     # Test with -j2 SetOption('stack_size', 128)
198     #
199     test.run(chdir='work2', 
200              arguments = '-j2 .',
201              stdout=expected_stdout,
202              stderr='')
203     test.must_exist(['work2', 'f1.out'])
204     test.must_exist(['work2', 'f2.out'])
205
206     test.run(chdir='work2', 
207              arguments = '-j2  -c .')
208     test.must_not_exist(['work2', 'f1.out'])
209     test.must_not_exist(['work2', 'f2.out'])
210
211     #
212     # Test with -j2 --stack-size=128 --warn=no-stack-size
213     #
214     test.run(chdir='work1', 
215              arguments = '-j2 --stack-size=128 --warn=no-stack-size .',
216              stdout=expected_stdout,
217              stderr='')
218     test.must_exist(['work1', 'f1.out'])
219     test.must_exist(['work1', 'f2.out'])
220
221     test.run(chdir='work1', 
222              arguments = '-j2 --stack-size=128  --warn=no-stack-size -c .')
223     test.must_not_exist(['work1', 'f1.out'])
224     test.must_not_exist(['work1', 'f2.out'])
225
226     #
227     # Test with -j2 --stack-size=16 --warn=no-stack-size
228     #
229     test.run(chdir='work1', 
230              arguments = '-j2 --stack-size=16 --warn=no-stack-size .',
231              stdout=expected_stdout,
232              stderr='')
233     test.must_exist(['work1', 'f1.out'])
234     test.must_exist(['work1', 'f2.out'])
235
236     test.run(chdir='work1', 
237              arguments = '-j2 --stack-size=16 --warn=no-stack-size -c .')
238     test.must_not_exist(['work1', 'f1.out'])
239     test.must_not_exist(['work1', 'f2.out'])
240
241     #
242     # Test with -j2  --warn=no-stack-size SetOption('stack_size', 128) 
243     #
244     test.run(chdir='work2', 
245              arguments = '-j2  --warn=no-stack-size .',
246              stdout=expected_stdout,
247              stderr='')
248     test.must_exist(['work2', 'f1.out'])
249     test.must_exist(['work2', 'f2.out'])
250
251     test.run(chdir='work2', 
252              arguments = '-j2   --warn=no-stack-size -c .')
253     test.must_not_exist(['work2', 'f1.out'])
254     test.must_not_exist(['work2', 'f2.out'])
255
256 else:
257
258     #
259     # Test with -j2 --stack-size=128
260     #
261     test.run(chdir='work1', 
262              arguments = '-j2 --stack-size=128 .',
263              match=TestSCons.match_re,
264              stdout=re_expected_stdout,
265              stderr=expect_unsupported)
266     test.must_exist(['work1', 'f1.out'])
267     test.must_exist(['work1', 'f2.out'])
268
269     test.run(chdir='work1', 
270              arguments = '-j2 --stack-size=128 -c .',
271              match=TestSCons.match_re,
272              stderr=expect_unsupported)
273     test.must_not_exist(['work1', 'f1.out'])
274     test.must_not_exist(['work1', 'f2.out'])
275
276     #
277     # Test with -j2 --stack-size=16
278     #
279     test.run(chdir='work1', 
280              arguments = '-j2 --stack-size=16 .',
281              match=TestSCons.match_re,
282              stdout=re_expected_stdout,
283              stderr=expect_unsupported)
284     test.must_exist(['work1', 'f1.out'])
285     test.must_exist(['work1', 'f2.out'])
286
287     test.run(chdir='work1', 
288              arguments = '-j2 --stack-size=16 -c .',
289              match=TestSCons.match_re,
290              stderr=expect_unsupported)
291     test.must_not_exist(['work1', 'f1.out'])
292     test.must_not_exist(['work1', 'f2.out'])
293
294     #
295     # Test with -j2 SetOption('stack_size', 128)
296     #
297     test.run(chdir='work2', 
298              arguments = '-j2 .',
299              match=TestSCons.match_re,
300              stdout=re_expected_stdout,
301              stderr=expect_unsupported)
302     test.must_exist(['work2', 'f1.out'])
303     test.must_exist(['work2', 'f2.out'])
304
305     test.run(chdir='work2', 
306              arguments = '-j2  -c .',
307              match=TestSCons.match_re,
308              stderr=expect_unsupported)
309     test.must_not_exist(['work2', 'f1.out'])
310     test.must_not_exist(['work2', 'f2.out'])
311
312     #
313     # Test with -j2 --stack-size=128 --warn=no-stack-size
314     #
315     test.run(chdir='work1', 
316              arguments = '-j2 --stack-size=128 --warn=no-stack-size .',
317              stdout=expected_stdout,
318              stderr='')
319     test.must_exist(['work1', 'f1.out'])
320     test.must_exist(['work1', 'f2.out'])
321
322     test.run(chdir='work1', 
323              arguments = '-j2 --stack-size=128  --warn=no-stack-size -c .')
324     test.must_not_exist(['work1', 'f1.out'])
325     test.must_not_exist(['work1', 'f2.out'])
326
327     #
328     # Test with -j2 --stack-size=16 --warn=no-stack-size
329     #
330     test.run(chdir='work1', 
331              arguments = '-j2 --stack-size=16 --warn=no-stack-size .',
332              stdout=expected_stdout,
333              stderr='')
334     test.must_exist(['work1', 'f1.out'])
335     test.must_exist(['work1', 'f2.out'])
336
337     test.run(chdir='work1', 
338              arguments = '-j2 --stack-size=16 --warn=no-stack-size -c .')
339     test.must_not_exist(['work1', 'f1.out'])
340     test.must_not_exist(['work1', 'f2.out'])
341
342     #
343     # Test with -j2  --warn=no-stack-size SetOption('stack_size', 128) 
344     #
345     test.run(chdir='work2', 
346              arguments = '-j2  --warn=no-stack-size .',
347              stdout=expected_stdout,
348              stderr='')
349     test.must_exist(['work2', 'f1.out'])
350     test.must_exist(['work2', 'f2.out'])
351
352     test.run(chdir='work2', 
353              arguments = '-j2   --warn=no-stack-size -c .')
354     test.must_not_exist(['work2', 'f1.out'])
355     test.must_not_exist(['work2', 'f2.out'])
356
357 test.pass_test()