]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/python | |
2 | ||
3 | # Copyright 2005 David Abrahams | |
4 | # Copyright 2008, 2012 Jurko Gospodnetic | |
5 | # Distributed under the Boost Software License, Version 1.0. | |
6 | # (See accompanying file LICENSE_1_0.txt or copy at | |
7 | # http://www.boost.org/LICENSE_1_0.txt) | |
8 | ||
9 | # Tests the build step timing facilities. | |
10 | ||
11 | # TODO: Missing tests: | |
12 | # 1. 'time' target with a source target representing more than one virtual | |
13 | # target. This happens in practice, e.g. when using the time rule on a msvc | |
14 | # exe target whose generator actually constructs an EXE and a PDB target. | |
15 | # When this is done - only the main virtual target's constructing action | |
16 | # should be timed. | |
17 | # 2. 'time' target with a source target representing a virtual target that | |
18 | # actually gets built by multiple actions run in sequence. In that case a | |
19 | # separate timing result should be reported for each of those actions. This | |
20 | # happens in practice, e.g. when using the time rule on a msvc exe target | |
21 | # which first gets created as a result of some link action and then its | |
22 | # manifest gets embedded inside it as a resource using a separate action | |
23 | # (assuming an appropriate property has been set for this target - see the | |
24 | # msvc module for details). | |
25 | ||
26 | import BoostBuild | |
27 | import re | |
28 | ||
29 | ||
30 | ############################################################################### | |
31 | # | |
32 | # basic_jam_action_test() | |
33 | # ----------------------- | |
34 | # | |
35 | ############################################################################### | |
36 | ||
37 | def basic_jam_action_test(): | |
38 | """Tests basic Jam action timing support.""" | |
39 | ||
40 | t = BoostBuild.Tester(pass_toolset=0) | |
41 | ||
42 | t.write("file.jam", """\ | |
43 | rule time | |
44 | { | |
45 | DEPENDS $(<) : $(>) ; | |
46 | __TIMING_RULE__ on $(>) = record_time $(<) ; | |
47 | DEPENDS all : $(<) ; | |
48 | } | |
49 | ||
50 | actions time | |
51 | { | |
52 | echo $(>) user: $(__USER_TIME__) system: $(__SYSTEM_TIME__) clock: $(__CLOCK_TIME__) | |
53 | echo timed from $(>) >> $(<) | |
54 | } | |
55 | ||
56 | rule record_time ( target : source : start end user system clock ) | |
57 | { | |
58 | __USER_TIME__ on $(target) = $(user) ; | |
59 | __SYSTEM_TIME__ on $(target) = $(system) ; | |
60 | __CLOCK_TIME__ on $(target) = $(clock) ; | |
61 | } | |
62 | ||
63 | rule make | |
64 | { | |
65 | DEPENDS $(<) : $(>) ; | |
66 | } | |
67 | ||
68 | actions make | |
69 | { | |
70 | echo made from $(>) >> $(<) | |
71 | } | |
72 | ||
73 | time foo : bar ; | |
74 | make bar : baz ; | |
75 | """) | |
76 | ||
77 | t.write("baz", "nothing") | |
78 | ||
79 | expected_output = """\ | |
80 | \.\.\.found 4 targets\.\.\. | |
81 | \.\.\.updating 2 targets\.\.\. | |
82 | make bar | |
83 | time foo | |
84 | bar +user: [0-9\.]+ +system: +[0-9\.]+ +clock: +[0-9\.]+ * | |
85 | \.\.\.updated 2 targets\.\.\.$ | |
86 | """ | |
87 | ||
88 | t.run_build_system(["-ffile.jam", "-d+1"], stdout=expected_output, | |
89 | match=lambda actual, expected: re.search(expected, actual, re.DOTALL)) | |
90 | t.expect_addition("foo") | |
91 | t.expect_addition("bar") | |
92 | t.expect_nothing_more() | |
93 | ||
94 | t.cleanup() | |
95 | ||
96 | ||
97 | ############################################################################### | |
98 | # | |
99 | # boost_build_testing_support_timing_rule(): | |
100 | # ------------------------------------------ | |
101 | # | |
102 | ############################################################################### | |
103 | ||
104 | def boost_build_testing_support_timing_rule(): | |
105 | """ | |
106 | Tests the target build timing rule provided by the Boost Build testing | |
107 | support system. | |
108 | ||
109 | """ | |
110 | t = BoostBuild.Tester(use_test_config=False) | |
111 | ||
112 | t.write("aaa.cpp", "int main() {}\n") | |
113 | ||
114 | t.write("jamroot.jam", """\ | |
115 | import testing ; | |
116 | exe my-exe : aaa.cpp ; | |
117 | time my-time : my-exe ; | |
118 | """) | |
119 | ||
120 | t.run_build_system() | |
121 | t.expect_addition("bin/$toolset/debug*/aaa.obj") | |
122 | t.expect_addition("bin/$toolset/debug*/my-exe.exe") | |
123 | t.expect_addition("bin/$toolset/debug*/my-time.time") | |
124 | ||
125 | t.expect_content_lines("bin/$toolset/debug*/my-time.time", | |
126 | "user: *[0-9] seconds") | |
127 | t.expect_content_lines("bin/$toolset/debug*/my-time.time", | |
128 | "system: *[0-9] seconds") | |
129 | t.expect_content_lines("bin/$toolset/debug*/my-time.time", | |
130 | "clock: *[0-9] seconds") | |
131 | ||
132 | t.cleanup() | |
133 | ||
134 | ||
135 | ############################################################################### | |
136 | # | |
137 | # boost_build_testing_support_timing_rule_with_spaces_in_names() | |
138 | # -------------------------------------------------------------- | |
139 | # | |
140 | ############################################################################### | |
141 | ||
142 | def boost_build_testing_support_timing_rule_with_spaces_in_names(): | |
143 | """ | |
144 | Tests the target build timing rule provided by the Boost Build testing | |
145 | support system when used with targets contining spaces in their names. | |
146 | ||
147 | """ | |
148 | t = BoostBuild.Tester(use_test_config=False) | |
149 | ||
150 | t.write("aaa bbb.cpp", "int main() {}\n") | |
151 | ||
152 | t.write("jamroot.jam", """\ | |
153 | import testing ; | |
154 | exe "my exe" : "aaa bbb.cpp" ; | |
155 | time "my time" : "my exe" ; | |
156 | """) | |
157 | ||
158 | t.run_build_system() | |
159 | t.expect_addition("bin/$toolset/debug*/aaa bbb.obj") | |
160 | t.expect_addition("bin/$toolset/debug*/my exe.exe") | |
161 | t.expect_addition("bin/$toolset/debug*/my time.time") | |
162 | ||
163 | t.expect_content_lines("bin/$toolset/debug*/my time.time", "user: *") | |
164 | t.expect_content_lines("bin/$toolset/debug*/my time.time", "system: *") | |
165 | ||
166 | t.cleanup() | |
167 | ||
168 | ||
169 | ############################################################################### | |
170 | # | |
171 | # main() | |
172 | # ------ | |
173 | # | |
174 | ############################################################################### | |
175 | ||
176 | basic_jam_action_test() | |
177 | boost_build_testing_support_timing_rule() | |
178 | boost_build_testing_support_timing_rule_with_spaces_in_names() |