[ci skip] add test framework reformat to .git-blame-ignore-revs
[scons.git] / test / SideEffect / parallel.py
blob6c1dc3924dc1af63716519a599698773b5c149ba
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Verify that targets with the same SideEffect are not built in parallel
29 when the -j option is used.
30 """
32 import TestSCons
34 _python_ = TestSCons._python_
36 test = TestSCons.TestSCons()
38 test.write('build.py', """
39 import os
40 import sys
41 import time
43 lockdir = 'build.lock'
44 logfile = 'log.txt'
46 try:
47 os.mkdir(lockdir)
48 except OSError as e:
49 msg = 'could not create lock directory: %s\\n' % e
50 sys.stderr.write(msg)
51 sys.exit(1)
53 src, target = sys.argv[1:]
55 with open(logfile, 'ab') as f:
56 f.write(('%s -> %s\\n' % (src, target)).encode())
57 with open(target, 'wb') as ofp, open(src, 'rb') as ifp:
58 ofp.write(ifp.read())
60 # Give the other threads a chance to start.
61 time.sleep(1)
63 os.rmdir(lockdir)
64 """)
66 test.write('SConstruct', """\
67 Build = Builder(action=r'%(_python_)s build.py $SOURCE $TARGET')
68 env = Environment(BUILDERS={'Build':Build})
69 env.Build('h1.out', 'h1.in')
70 env.Build('g2.out', 'g2.in')
71 env.Build('f3.out', 'f3.in')
72 SideEffect('log.txt', ['h1.out', 'g2.out', 'f3.out'])
73 env.Build('log.out', 'log.txt')
74 """ % locals())
76 test.write('h1.in', 'h1.in\n')
77 test.write('g2.in', 'g2.in\n')
78 test.write('f3.in', 'f3.in\n')
79 test.write('baz.in', 'baz.in\n')
82 test.run(arguments = "-j 4 .")
84 test.must_match('h1.out', 'h1.in\n')
85 test.must_match('g2.out', 'g2.in\n')
86 test.must_match('f3.out', 'f3.in\n')
87 test.must_exist('log.txt')
88 test.must_exist('log.out')
90 stdout = test.stdout()
93 build_lines = [
94 'build.py h1.in h1.out',
95 'build.py g2.in g2.out',
96 'build.py f3.in f3.out',
99 missing = []
100 for line in build_lines:
101 if stdout.find(line) == -1:
102 missing.append(line)
104 if missing:
105 print("===== standard output is missing the following lines:")
106 print('\n'.join(missing))
107 print("===== STDOUT ========================================")
108 print(stdout)
109 test.fail_test()
112 log = test.read('log.txt', mode='r')
114 log_lines = [
115 'f3.in -> f3.out',
116 'h1.in -> h1.out',
117 'g2.in -> g2.out',
120 missing = []
121 for line in log_lines:
122 if log.find(line) == -1:
123 missing.append(line)
125 if missing:
126 print("===== log file 'log.txt' is missing the following lines:")
127 print('\n'.join(missing))
128 print("===== STDOUT ===========================================")
129 print(log)
130 test.fail_test()
132 test.pass_test()
134 # Local Variables:
135 # tab-width:4
136 # indent-tabs-mode:nil
137 # End:
138 # vim: set expandtab tabstop=4 shiftwidth=4: