diff options
Diffstat (limited to 'test/Parallel')
-rw-r--r-- | test/Parallel/duplicate-target.py | 48 | ||||
-rw-r--r-- | test/Parallel/failed-build.py | 111 |
2 files changed, 147 insertions, 12 deletions
diff --git a/test/Parallel/duplicate-target.py b/test/Parallel/duplicate-target.py index 5d4f5e1..43015fe 100644 --- a/test/Parallel/duplicate-target.py +++ b/test/Parallel/duplicate-target.py @@ -41,34 +41,58 @@ _python_ = TestSCons._python_ test = TestSCons.TestSCons() -test.subdir('work') +test.subdir('work', ['work', 'sub']) tar_output = test.workpath('work.tar') -test.write(['work', 'copy.py'], """\ +test.write(['work', 'mycopy.py'], """\ import sys import time time.sleep(int(sys.argv[1])) open(sys.argv[2], 'wb').write(open(sys.argv[3], 'rb').read()) """) +test.write(['work', 'mytar.py'], """\ +import sys +import os.path + +def visit(arg, dirname, fnames): + fnames.sort() + for fn in fnames: + p = os.path.join(dirname, fn) + if os.path.isfile(p): + arg.write(open(p, 'rb').read()) + +fp = open(sys.argv[1], 'wb') +for s in sys.argv[2:]: + os.path.walk(s, visit, fp) +""") + test.write(['work', 'SConstruct'], """\ env = Environment() -out1 = File('f1.out') -out2 = File('f2.out') -env.Command([out1, out1], 'f1.in', r'%(_python_)s copy.py 3 $TARGET $SOURCE') -env.Command([out2, out2], 'f2.in', r'%(_python_)s copy.py 3 $TARGET $SOURCE') +out1 = File('sub/f1.out') +out2 = File('sub/f2.out') +env.Command([out1, out1], 'sub/f1.in', + r'%(_python_)s mycopy.py 3 $TARGET $SOURCE') +env.Command([out2, out2], 'sub/f2.in', + r'%(_python_)s mycopy.py 3 $TARGET $SOURCE') -env.Tar(r'%(tar_output)s', Dir('.')) +env.Command(r'%(tar_output)s', Dir('sub'), + r'%(_python_)s mytar.py $TARGET $SOURCE') """ % locals()) -test.write(['work', 'f1.in'], "work/f1.in\n") -test.write(['work', 'f2.in'], "work/f2.in\n") +test.write(['work', 'sub', 'f1.in'], "work/sub/f1.in\n") +test.write(['work', 'sub', 'f2.in'], "work/sub/f2.in\n") test.run(chdir = 'work', arguments = tar_output + ' -j2') -test.must_match(['work', 'f1.out'], "work/f1.in\n") -test.must_match(['work', 'f2.out'], "work/f2.in\n") -test.must_exist(tar_output) +test.must_match(['work', 'sub', 'f1.out'], "work/sub/f1.in\n") +test.must_match(['work', 'sub', 'f2.out'], "work/sub/f2.in\n") +test.must_match(tar_output, """\ +work/sub/f1.in +work/sub/f1.in +work/sub/f2.in +work/sub/f2.in +""") test.pass_test() diff --git a/test/Parallel/failed-build.py b/test/Parallel/failed-build.py new file mode 100644 index 0000000..64e90c9 --- /dev/null +++ b/test/Parallel/failed-build.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +""" +Verify that a failed build action with -j works as expected. +""" + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import TestSCons + +_python_ = TestSCons._python_ + +try: + import threading +except ImportError: + # if threads are not supported, then + # there is nothing to test + TestCmd.no_result() + sys.exit() + + +test = TestSCons.TestSCons() + +# We want to verify that -j 2 starts precisely two jobs, the first of +# which fails and the second of which succeeds, and then stops processing +# due to the first build failure. To try to control the timing, the two +# created build scripts use a pair of marker directories. +# +# The failure script waits until it sees the 'mycopy.started' directory +# that indicates the successful script has, in fact, gotten started. +# If we don't wait, then SCons could detect our script failure early +# (typically if a high system load happens to delay SCons' ability to +# start the next script) and then not start the successful script at all. +# +# The successful script waits until it sees the 'myfail.exiting' directory +# that indicates the failure script has finished (with everything except +# the final sys.exit(), that is). If we don't wait for that, then SCons +# could detect our successful exit first (typically if a high system +# load happens to delay the failure script) and start another job before +# it sees the failure from the first script. + +test.write('myfail.py', r"""\ +import os.path +import sys +import time +while not os.path.exists('mycopy.started'): + time.sleep(1) +os.mkdir('myfail.exiting') +sys.exit(1) +""") + +test.write('mycopy.py', r"""\ +import os +import sys +import time +os.mkdir('mycopy.started') +open(sys.argv[1], 'wb').write(open(sys.argv[2], 'rb').read()) +while not os.path.exists('myfail.exiting'): + time.sleep(1) +sys.exit(0) +""") + +test.write('SConstruct', """ +MyCopy = Builder(action = r'%(_python_)s mycopy.py $TARGET $SOURCE') +Fail = Builder(action = r'%(_python_)s myfail.py $TARGETS $SOURCE') +env = Environment(BUILDERS = { 'MyCopy' : MyCopy, 'Fail' : Fail }) +env.Fail(target = 'f3', source = 'f3.in') +env.MyCopy(target = 'f4', source = 'f4.in') +env.MyCopy(target = 'f5', source = 'f5.in') +env.MyCopy(target = 'f6', source = 'f6.in') +""" % locals()) + +test.write('f3.in', "f3.in\n") +test.write('f4.in', "f4.in\n") +test.write('f5.in', "f5.in\n") +test.write('f6.in', "f6.in\n") + +test.run(arguments = '-j 2 .', + status = 2, + stderr = "scons: *** [f3] Error 1\n") + +test.must_not_exist(test.workpath('f3')) +test.must_match(test.workpath('f4'), 'f4.in\n') +test.must_not_exist(test.workpath('f5')) +test.must_not_exist(test.workpath('f6')) + + + +test.pass_test() |