summaryrefslogtreecommitdiffstats
path: root/test/Parallel
diff options
context:
space:
mode:
Diffstat (limited to 'test/Parallel')
-rw-r--r--test/Parallel/duplicate-children.py74
-rw-r--r--test/Parallel/duplicate-target.py108
-rw-r--r--test/Parallel/failed-build.py121
-rw-r--r--test/Parallel/multiple-parents.py268
-rw-r--r--test/Parallel/ref_count.py158
5 files changed, 729 insertions, 0 deletions
diff --git a/test/Parallel/duplicate-children.py b/test/Parallel/duplicate-children.py
new file mode 100644
index 0000000..c6c5c29
--- /dev/null
+++ b/test/Parallel/duplicate-children.py
@@ -0,0 +1,74 @@
+#!/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.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Verify that parallel builds work correctly when a Node is duplicated
+in the children (once in the sources and once in the depends list).
+"""
+
+import TestSCons
+
+_python_ = TestSCons._python_
+
+test = TestSCons.TestSCons()
+
+test.write('cat.py', """\
+import sys
+fp = open(sys.argv[1], 'wb')
+for fname in sys.argv[2:]:
+ fp.write(open(fname, 'rb').read())
+fp.close()
+""")
+
+test.write('sleep.py', """\
+import sys
+import time
+time.sleep(int(sys.argv[1]))
+""")
+
+test.write('SConstruct', """
+# Test case for SCons issue #1608
+# Create a file "foo.in" in the current directory before running scons.
+env = Environment()
+env.Command('foo.out', ['foo.in'], '%(_python_)s cat.py $TARGET $SOURCE && %(_python_)s sleep.py 3')
+env.Command('foobar', ['foo.out'], '%(_python_)s cat.py $TARGET $SOURCES')
+env.Depends('foobar', 'foo.out')
+""" % locals())
+
+test.write('foo.in', "foo.in\n")
+
+test.run(arguments = '-j2 .')
+
+test.must_match('foo.out', "foo.in\n")
+test.must_match('foobar', "foo.in\n")
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/test/Parallel/duplicate-target.py b/test/Parallel/duplicate-target.py
new file mode 100644
index 0000000..efe20d9
--- /dev/null
+++ b/test/Parallel/duplicate-target.py
@@ -0,0 +1,108 @@
+#!/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.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Verify that, when a file is specified multiple times in a target
+list, we still build all of the necessary targets.
+
+This used to cause a target to "disappear" from the DAG when its reference
+count dropped below 0, because we were subtracting the duplicated target
+mutiple times even though we'd only visit it once. This was particularly
+hard to track down because the DAG itself (when printed with --tree=prune,
+for example) doesn't show the duplication in the *target* list.
+"""
+
+import TestSCons
+
+_python_ = TestSCons._python_
+
+test = TestSCons.TestSCons()
+
+test.subdir('work', ['work', 'sub'])
+
+tar_output = test.workpath('work.tar')
+
+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
+
+fp = open(sys.argv[1], 'wb')
+
+def visit(dirname):
+ names = os.listdir(dirname)
+ names.sort()
+ for n in names:
+ p = os.path.join(dirname, n)
+ if os.path.isdir(p):
+ visit(p)
+ elif os.path.isfile(p):
+ fp.write(open(p, 'rb').read())
+
+for s in sys.argv[2:]:
+ visit(s)
+""")
+
+test.write(['work', 'SConstruct'], """\
+env = Environment()
+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.Command(r'%(tar_output)s', Dir('sub'),
+ r'%(_python_)s mytar.py $TARGET $SOURCE')
+""" % locals())
+
+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', '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()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/test/Parallel/failed-build.py b/test/Parallel/failed-build.py
new file mode 100644
index 0000000..b46762c
--- /dev/null
+++ b/test/Parallel/failed-build.py
@@ -0,0 +1,121 @@
+#!/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
+import sys
+import time
+for i in [1, 2, 3, 4, 5]:
+ time.sleep(2)
+ if os.path.exists('mycopy.started'):
+ os.mkdir('myfail.exiting')
+ sys.exit(1)
+sys.exit(99)
+""")
+
+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())
+for i in [1, 2, 3, 4, 5]:
+ time.sleep(2)
+ if os.path.exists('myfail.exiting'):
+ sys.exit(0)
+sys.exit(99)
+""")
+
+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()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/test/Parallel/multiple-parents.py b/test/Parallel/multiple-parents.py
new file mode 100644
index 0000000..7fbcb00
--- /dev/null
+++ b/test/Parallel/multiple-parents.py
@@ -0,0 +1,268 @@
+#!/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 sys
+
+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()
+
+# Test that we can handle parallel builds with a dependency graph
+# where:
+# a) Some nodes have multiple parents
+# b) Some targets fail building
+# c) Some targets succeed building
+# d) Some children are ignored
+# e) Some children are pre-requesites
+# f) Some children have side-effects
+# g) Some sources are missing
+# h) Builds that are interrupted
+
+test.write('SConstruct', """
+vars = Variables()
+vars.Add( BoolVariable('interrupt', 'Interrupt the build.', 0 ) )
+varEnv = Environment(variables=vars)
+
+def fail_action(target = None, source = None, env = None):
+ return 2
+
+def simulate_keyboard_interrupt(target = None, source = None, env = None):
+ # Directly invoked the SIGINT handler to simulate a
+ # KeyboardInterrupt. This hack is necessary because there is no
+ # easy way to get access to the current Job/Taskmaster object.
+ import signal
+ handler = signal.getsignal(signal.SIGINT)
+ handler(signal.SIGINT, None)
+ return 0
+
+interrupt = Command(target='interrupt', source='', action=simulate_keyboard_interrupt)
+
+touch0 = Touch('${TARGETS[0]}')
+touch1 = Touch('${TARGETS[1]}')
+touch2 = Touch('${TARGETS[2]}')
+
+failed0 = Command(target='failed00', source='', action=fail_action)
+ok0 = Command(target=['ok00a', 'ok00b', 'ok00c'],
+ source='',
+ action=[touch0, touch1, touch2])
+prereq0 = Command(target='prereq00', source='', action=touch0)
+ignore0 = Command(target='ignore00', source='', action=touch0)
+igreq0 = Command(target='igreq00', source='', action=touch0)
+missing0 = Command(target='missing00', source='MissingSrc', action=touch0)
+withSE0 = Command(target=['withSE00a', 'withSE00b', 'withSE00c'],
+ source='',
+ action=[touch0, touch1, touch2, Touch('side_effect')])
+SideEffect('side_effect', withSE0)
+
+prev_level = failed0 + ok0 + ignore0 + missing0 + withSE0
+prev_prereq = prereq0
+prev_ignore = ignore0
+prev_igreq = igreq0
+
+if varEnv['interrupt']:
+ prev_level = prev_level + interrupt
+
+for i in range(1,20):
+
+ failed = Command(target='failed%02d' % i, source='', action=fail_action)
+ ok = Command(target=['ok%02da' % i, 'ok%02db' % i, 'ok%02dc' % i],
+ source='',
+ action=[touch0, touch1, touch2])
+ prereq = Command(target='prereq%02d' % i, source='', action=touch0)
+ ignore = Command(target='ignore%02d' % i, source='', action=touch0)
+ igreq = Command(target='igreq%02d' % i, source='', action=touch0)
+ missing = Command(target='missing%02d' %i, source='MissingSrc', action=touch0)
+ withSE = Command(target=['withSE%02da' % i, 'withSE%02db' % i, 'withSE%02dc' % i],
+ source='',
+ action=[touch0, touch1, touch2, Touch('side_effect')])
+ SideEffect('side_effect', withSE)
+
+ next_level = failed + ok + ignore + igreq + missing + withSE
+
+ for j in range(1,10):
+ a = Alias('a%02d%02d' % (i,j), prev_level)
+
+ Requires(a, prev_prereq)
+ Ignore(a, prev_ignore)
+
+ Requires(a, prev_igreq)
+ Ignore(a, prev_igreq)
+
+ next_level = next_level + a
+
+ prev_level = next_level
+ prev_prereq = prereq
+ prev_ignore = ignore
+ prev_igreq = igreq
+
+all = Alias('all', prev_level)
+
+Requires(all, prev_prereq)
+Ignore(all, prev_ignore)
+
+Requires(all, prev_igreq)
+Ignore(all, prev_igreq)
+
+Default(all)
+""")
+
+re_error = """\
+(scons: \\*\\*\\* \\[failed\\d+] Error 2\\n)|\
+(scons: \\*\\*\\* \\[missing\\d+] Source `MissingSrc' not found, needed by target `missing\\d+'\\.( Stop\\.)?\\n)|\
+(scons: \\*\\*\\* \\[\\w+] Build interrupted\.\\n)|\
+(scons: Build interrupted\.\\n)\
+"""
+
+re_errors = "(" + re_error + ")+"
+
+# Make the script chatty so lack of output doesn't fool buildbot into
+# thinking it's hung.
+
+sys.stdout.write('Initial build.\n')
+test.run(arguments = 'all',
+ status = 2,
+ stderr = "scons: *** [failed19] Error 2\n")
+test.must_not_exist(test.workpath('side_effect'))
+for i in range(20):
+ test.must_not_exist(test.workpath('ok%02da' % i))
+ test.must_not_exist(test.workpath('ok%02db' % i))
+ test.must_not_exist(test.workpath('ok%02dc' % i))
+ test.must_not_exist(test.workpath('ignore%02d' % i))
+ test.must_not_exist(test.workpath('withSE%02da' % i))
+ test.must_not_exist(test.workpath('withSE%02db' % i))
+ test.must_not_exist(test.workpath('withSE%02dc' % i))
+
+# prereq19 and igreq19 will exist because, as prerequisites,
+# they are now evaluated *before* the direct children of the Node.
+for i in range(19):
+ test.must_not_exist(test.workpath('prereq%02d' % i))
+ test.must_not_exist(test.workpath('igreq%02d' % i))
+test.must_exist(test.workpath('prereq19'))
+test.must_exist(test.workpath('igreq19'))
+
+
+sys.stdout.write('-j8 all\n')
+for i in range(3):
+ test.run(arguments = '-c all')
+
+ test.run(arguments = '-j8 all',
+ status = 2,
+ stderr = re_errors,
+ match=TestSCons.match_re_dotall)
+
+
+sys.stdout.write('-j 8 -k all\n')
+for i in range(3):
+ test.run(arguments = '-c all')
+
+ test.run(arguments = '-j 8 -k all',
+ status = 2,
+ stderr = re_errors,
+ match=TestSCons.match_re_dotall)
+ test.must_exist(test.workpath('side_effect'))
+ for i in range(20):
+ test.must_exist(test.workpath('ok%02da' % i))
+ test.must_exist(test.workpath('ok%02db' % i))
+ test.must_exist(test.workpath('ok%02dc' % i))
+ test.must_exist(test.workpath('prereq%02d' % i))
+ test.must_not_exist(test.workpath('ignore%02d' % i))
+ test.must_exist(test.workpath('igreq%02d' % i))
+ test.must_exist(test.workpath('withSE%02da' % i))
+ test.must_exist(test.workpath('withSE%02db' % i))
+ test.must_exist(test.workpath('withSE%02dc' % i))
+
+
+sys.stdout.write('all --random\n')
+for i in range(3):
+ test.run(arguments = 'all --random',
+ status = 2,
+ stderr = re_errors,
+ match=TestSCons.match_re_dotall)
+
+
+sys.stdout.write('-j8 --random all\n')
+for i in range(3):
+ test.run(arguments = '-c all')
+
+ test.run(arguments = '-j8 --random all',
+ status = 2,
+ stderr = re_errors,
+ match=TestSCons.match_re_dotall)
+
+
+sys.stdout.write('-j8 -k --random all\n')
+for i in range(3):
+ test.run(arguments = '-c all')
+
+ test.run(arguments = '-j 8 -k --random all',
+ status = 2,
+ stderr = re_errors,
+ match=TestSCons.match_re_dotall)
+ test.must_exist(test.workpath('side_effect'))
+ for i in range(20):
+ test.must_exist(test.workpath('ok%02da' % i))
+ test.must_exist(test.workpath('ok%02db' % i))
+ test.must_exist(test.workpath('ok%02dc' % i))
+ test.must_exist(test.workpath('prereq%02d' % i))
+ test.must_not_exist(test.workpath('ignore%02d' % i))
+ test.must_exist(test.workpath('igreq%02d' % i))
+ test.must_exist(test.workpath('withSE%02da' % i))
+ test.must_exist(test.workpath('withSE%02db' % i))
+ test.must_exist(test.workpath('withSE%02dc' % i))
+
+
+sys.stdout.write('-j8 -k --random all interupt=yes\n')
+for i in range(3):
+ test.run(arguments = '-c all')
+
+ test.run(arguments = '-j 8 -k --random interrupt=yes all',
+ status = 2,
+ stderr = re_errors,
+ match=TestSCons.match_re_dotall)
+
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
diff --git a/test/Parallel/ref_count.py b/test/Parallel/ref_count.py
new file mode 100644
index 0000000..ce59668
--- /dev/null
+++ b/test/Parallel/ref_count.py
@@ -0,0 +1,158 @@
+#!/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.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Test for a specific race condition that used to stop a build cold when
+a Node's ref_count would get decremented past 0 and "disappear" from
+the Taskmaster's walk of the dependency graph.
+
+Note that this test does not fail every time, but would at least fail
+more than 60%-70% of the time on the system(s) I tested.
+
+The rather complicated set up here creates a condition where,
+after building four "object files" simultaneously while running with
+-j4, sets up a race condition amongst the three dependencies of the
+c6146/cpumanf.out file, where two of the dependencies are built at the
+same time (that is, by the same command) and one is built separately.
+
+We used to detect Nodes that had been started but not finished building
+and just set the waiting ref_count to the number of Nodes. In this case,
+if we got unlucky, we'd re-visit the Nodes for the two files first and
+set the ref_count to two *before* the command that built individual node
+completed and decremented the ref_count from two to one. Then when the
+two files completed, we'd update the ref_count to 1 - 2 = -1, which would
+cause the Taskmaster to *not* "wake up" the Node because it's ref_count
+hadn't actually reached 0.
+
+(The solution was to not set the ref_count, but to add to it only the
+Nodes that were, in fact, added to the waiting_parents lists of various
+child Nodes.)
+"""
+
+import TestSCons
+
+_python_ = TestSCons._python_
+
+test = TestSCons.TestSCons()
+
+test.write('build.py', """\
+import sys
+import time
+args = sys.argv[1:]
+outputs = []
+while args:
+ if args[0][0] != '-':
+ break
+ arg = args.pop(0)
+ if arg == '-o':
+ outputs.append(args.pop(0))
+ continue
+ if arg == '-s':
+ time.sleep(int(args.pop(0)))
+contents = ''
+for ifile in args:
+ contents = contents + open(ifile, 'rb').read()
+for ofile in outputs:
+ ofp = open(ofile, 'wb')
+ ofp.write('%s: building from %s\\n' % (ofile, " ".join(args)))
+ ofp.write(contents)
+ ofp.close()
+""")
+
+#
+#
+#
+
+test.write('SConstruct', """\
+env = Environment()
+cmd = r'%(_python_)s build.py -o $TARGET $SOURCES'
+f1 = env.Command('c6416/cpumanf/file1.obj', 'file1.c', cmd)
+f2 = env.Command('c6416/cpumanf/file2.obj', 'file2.c', cmd)
+f3 = env.Command('c6416/cpumanf/file3.obj', 'file3.c', cmd)
+f4 = env.Command('c6416/cpumanf/file4.obj', 'file4.c', cmd)
+f5 = env.Command('c6416/cpumanf/file5.obj', 'file5.c', cmd)
+f6 = env.Command('c6416/cpumanf/file6.obj', 'file6.c', cmd)
+
+objs = f1 + f2 + f3 + f4 + f5 + f6
+
+btc = env.Command('build/target/cpumanf.out', 'c6416/cpumanf.out', cmd)
+
+addcheck_obj = env.Command('addcheck.obj', 'addcheck.c', cmd)
+
+addcheck_exe = env.Command('addcheck.exe', addcheck_obj, cmd)
+
+cmd2 = r'%(_python_)s build.py -s 2 -o ${TARGETS[0]} -o ${TARGETS[1]} $SOURCES'
+
+cksums = env.Command(['c6416/cpumanf_pre_cksum.out',
+ 'c6416/cpumanf_pre_cksum.map'],
+ objs,
+ cmd2)
+
+cpumanf_out = env.Command('c6416/cpumanf.out',
+ cksums + addcheck_exe,
+ cmd)
+
+cpumanf = env.Alias('cpumanf', objs + btc)
+
+env.Command('after.out', cpumanf, r'%(_python_)s build.py -o $TARGET after.in')
+""" % locals())
+
+test.write('file1.c', "file1.c\n")
+test.write('file2.c', "file2.c\n")
+test.write('file3.c', "file3.c\n")
+test.write('file4.c', "file4.c\n")
+test.write('file5.c', "file5.c\n")
+test.write('file6.c', "file6.c\n")
+
+test.write('addcheck.c', "addcheck.c\n")
+
+test.write('after.in', "after.in\n")
+
+test.run(arguments = '-j4 after.out')
+
+test.must_match('after.out', """\
+after.out: building from after.in
+after.in
+""")
+
+test.write('file5.c', "file5.c modified\n")
+
+test.write('after.in', "after.in modified\n")
+
+test.run(arguments = '-j4 after.out')
+
+test.must_match('after.out', """\
+after.out: building from after.in
+after.in modified
+""")
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: