cf6c4e06d495c615f7adcaff0bf00a0b11504599
[scons.git] / test / option--debug.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2001, 2002 Steven Knight
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 TestSCons
28 import sys
29 import string
30 import re
31 import time
32
33 test = TestSCons.TestSCons()
34
35 test.write('SConstruct', """
36 env = Environment(OBJSUFFIX = '.ooo', PROGSUFFIX = '.xxx')
37 env.Program('foo', Split('foo.c bar.c'))
38 """)
39
40 test.write('foo.c', r"""
41 #include "foo.h"
42 int main(int argc, char *argv[])
43 {
44         argv[argc++] = "--";
45         printf("f1.c\n");
46         exit (0);
47 }
48 """)
49
50 test.write('bar.c', """
51 #include "bar.h"
52 """)
53
54 test.write('foo.h', """
55 #ifndef FOO_H
56 #define FOO_H
57 #include "bar.h"
58 #endif
59 """)
60
61 test.write('bar.h', """
62 #ifndef BAR_H
63 #define BAR_H
64 #include "foo.h"
65 #endif
66 """)
67
68 test.run(arguments = "--debug=tree foo.xxx")
69
70 tree = """
71 +-foo.xxx
72   +-foo.ooo
73   | +-foo.c
74   | +-foo.h
75   | +-bar.h
76   +-bar.ooo
77     +-bar.c
78     +-bar.h
79     +-foo.h
80 """
81
82 test.fail_test(string.find(test.stdout(), tree) == -1)
83
84 test.run(arguments = "--debug=tree foo.xxx")
85 test.fail_test(string.find(test.stdout(), tree) == -1)
86
87
88 tree = """
89 +-foo.xxx
90   +-foo.ooo
91   +-bar.ooo
92 """
93
94 test.run(arguments = "--debug=dtree foo.xxx")
95 test.fail_test(string.find(test.stdout(), tree) == -1)
96
97 tree = """scons: \".\" is up to date.
98
99 +-.
100   +-SConstruct
101   +-bar.c
102   +-bar.h
103   +-bar.ooo
104   | +-bar.c
105   | +-bar.h
106   | +-foo.h
107   +-foo.c
108   +-foo.h
109   +-foo.ooo
110   | +-foo.c
111   | +-foo.h
112   | +-bar.h
113   +-foo.xxx
114     +-foo.ooo
115     | +-foo.c
116     | +-foo.h
117     | +-bar.h
118     +-bar.ooo
119       +-bar.c
120       +-bar.h
121       +-foo.h
122 """
123 test.run(arguments = "--debug=tree .")
124 test.fail_test(string.find(test.stdout(), tree) == -1)
125
126 test.run(arguments = "--debug=pdb", stdin = "n\ns\nq\n")
127 test.fail_test(string.find(test.stdout(), "(Pdb)") == -1)
128 test.fail_test(string.find(test.stdout(), "scons") == -1)
129
130 test.write('foo.c', r"""
131 #include "foo.h"
132
133 int main(int argc, char *argv[])
134 {
135         argv[argc++] = "--";
136         printf("f1.c\n");
137         exit (0);
138 }
139 """)
140
141 test.write('bar.c', """
142 #include "bar.h"
143
144 """)
145
146 ############################
147 # test --debug=time
148
149 def num(match, line):
150     return float(re.match(match, line).group(1))
151
152 start_time = time.time()
153 test.run(program=sys.executable, arguments='-c pass')
154 overhead = time.time() - start_time 
155
156 start_time = time.time()
157 test.run(arguments = "--debug=time .")
158 expected_total_time = time.time() - start_time - overhead
159 line = string.split(test.stdout(), '\n')
160
161 cmdline = filter(lambda x: x[:23] == "Command execution time:", line)
162
163 expected_command_time = num(r'Command execution time: (\d+\.\d+) seconds', cmdline[0])
164 expected_command_time = expected_command_time + num(r'Command execution time: (\d+\.\d+) seconds', cmdline[1])
165 expected_command_time = expected_command_time + num(r'Command execution time: (\d+\.\d+) seconds', cmdline[2])
166
167 totalline = filter(lambda x: x[:6] == "Total ", line)
168
169 total_time = num(r'Total build time: (\d+\.\d+) seconds', totalline[0])
170 sconscript_time = num(r'Total SConscript file execution time: (\d+\.\d+) seconds', totalline[1])
171 scons_time = num(r'Total SCons execution time: (\d+\.\d+) seconds', totalline[2])
172 command_time = num(r'Total command execution time: (\d+\.\d+) seconds', totalline[3])
173
174 def check(expected, actual, tolerance):
175     return abs((expected-actual)/actual) <= tolerance
176
177 assert check(expected_command_time, command_time, 0.01)
178 assert check(total_time, sconscript_time+scons_time+command_time, 0.01) 
179 assert check(total_time, expected_total_time, 0.1)
180
181 test.pass_test()
182