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__"
33 test = TestSCons.TestSCons()
35 test.write('SConstruct', """
36 env = Environment(OBJSUFFIX = '.ooo', PROGSUFFIX = '.xxx')
37 env.Program('foo', Split('foo.c bar.c'))
40 test.write('foo.c', r"""
44 int main(int argc, char *argv[])
52 test.write('bar.c', """
56 test.write('foo.h', """
63 test.write('bar.h', """
71 return float(re.search(match, line).group(1))
73 # Try to make things a little more equal by measuring Python overhead
74 # executing a minimal file, and reading the scons.py script itself from
75 # disk so that it's already been cached.
76 test.write('pass.py', "pass\n")
77 test.read(test.program)
79 start_time = time.time()
80 test.run(program=TestSCons.python, arguments=test.workpath('pass.py'))
81 overhead = time.time() - start_time
83 start_time = time.time()
84 test.run(arguments = "--debug=time .")
85 complete_time = time.time() - start_time
87 expected_total_time = complete_time - overhead
88 lines = string.split(test.stdout(), '\n')
90 expected_command_time = 0.0
91 for cmdline in filter(lambda x: x[:23] == "Command execution time:", lines):
92 n = num(r'Command execution time: (\d+\.\d+) seconds', cmdline)
93 expected_command_time = expected_command_time + n
95 stdout = test.stdout()
97 total_time = num(r'Total build time: (\d+\.\d+) seconds', stdout)
98 sconscript_time = num(r'Total SConscript file execution time: (\d+\.\d+) seconds', stdout)
99 scons_time = num(r'Total SCons execution time: (\d+\.\d+) seconds', stdout)
100 command_time = num(r'Total command execution time: (\d+\.\d+) seconds', stdout)
102 def within_tolerance(expected, actual, tolerance):
103 return abs((expected-actual)/actual) <= tolerance
107 if not within_tolerance(expected_command_time, command_time, 0.01):
109 SCons reported a total command execution time of %s,
110 but command execution times really totalled %s,
111 outside of the 1%% tolerance.
112 """ % (command_time, expected_command_time))
114 added_times = sconscript_time+scons_time+command_time
115 if not within_tolerance(total_time, added_times, 0.01):
117 SCons reported a total build time of %s,
118 but the various execution times actually totalled %s,
119 outside of the 1%% tolerance.
120 """ % (total_time, added_times))
122 if not within_tolerance(total_time, expected_total_time, 0.15):
124 SCons reported total build time of %s,
125 but the actual measured build time was %s
126 (end-to-end time of %s less Python overhead of %s),
127 outside of the 15%% tolerance.
128 """ % (total_time, expected_total_time, complete_time, overhead))
131 print string.join([test.stdout()] + failures, '\n')