Imported Upstream version 1.57.0
[platform/upstream/boost.git] / tools / build / test / timedata.py
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__)
53     echo timed from $(>) >> $(<)
54 }
55
56 rule record_time ( target : source : start end user system )
57 {
58     __USER_TIME__ on $(target) = $(user) ;
59     __SYSTEM_TIME__ on $(target) = $(system) ;
60 }
61
62 rule make
63 {
64     DEPENDS $(<) : $(>) ;
65 }
66
67 actions make
68 {
69     echo made from $(>) >> $(<)
70 }
71
72 time foo : bar ;
73 make bar : baz ;
74 """)
75
76     t.write("baz", "nothing")
77
78     expected_output = """\
79 \.\.\.found 4 targets\.\.\.
80 \.\.\.updating 2 targets\.\.\.
81 make bar
82 time foo
83 bar +user: [0-9\.]+ +system: +[0-9\.]+ *
84 \.\.\.updated 2 targets\.\.\.$
85 """
86
87     t.run_build_system(["-ffile.jam", "-d+1"], stdout=expected_output,
88         match=lambda actual, expected: re.search(expected, actual, re.DOTALL))
89     t.expect_addition("foo")
90     t.expect_addition("bar")
91     t.expect_nothing_more()
92
93     t.cleanup()
94
95
96 ###############################################################################
97 #
98 # boost_build_testing_support_timing_rule():
99 # ------------------------------------------
100 #
101 ###############################################################################
102
103 def boost_build_testing_support_timing_rule():
104     """
105       Tests the target build timing rule provided by the Boost Build testing
106     support system.
107
108     """
109     t = BoostBuild.Tester(use_test_config=False)
110
111     t.write("aaa.cpp", "int main() {}\n")
112
113     t.write("jamroot.jam", """\
114 import testing ;
115 exe my-exe : aaa.cpp ;
116 time my-time : my-exe ;
117 """)
118
119     t.run_build_system()
120     t.expect_addition("bin/$toolset/debug/aaa.obj")
121     t.expect_addition("bin/$toolset/debug/my-exe.exe")
122     t.expect_addition("bin/$toolset/debug/my-time.time")
123
124     t.expect_content_lines("bin/$toolset/debug/my-time.time",
125         "user: *[0-9] seconds")
126     t.expect_content_lines("bin/$toolset/debug/my-time.time",
127         "system: *[0-9] seconds")
128
129     t.cleanup()
130
131
132 ###############################################################################
133 #
134 # boost_build_testing_support_timing_rule_with_spaces_in_names()
135 # --------------------------------------------------------------
136 #
137 ###############################################################################
138
139 def boost_build_testing_support_timing_rule_with_spaces_in_names():
140     """
141       Tests the target build timing rule provided by the Boost Build testing
142     support system when used with targets contining spaces in their names.
143
144     """
145     t = BoostBuild.Tester(use_test_config=False)
146
147     t.write("aaa bbb.cpp", "int main() {}\n")
148
149     t.write("jamroot.jam", """\
150 import testing ;
151 exe "my exe" : "aaa bbb.cpp" ;
152 time "my time" : "my exe" ;
153 """)
154
155     t.run_build_system()
156     t.expect_addition("bin/$toolset/debug/aaa bbb.obj")
157     t.expect_addition("bin/$toolset/debug/my exe.exe")
158     t.expect_addition("bin/$toolset/debug/my time.time")
159
160     t.expect_content_lines("bin/$toolset/debug/my time.time", "user: *")
161     t.expect_content_lines("bin/$toolset/debug/my time.time", "system: *")
162
163     t.cleanup()
164
165
166 ###############################################################################
167 #
168 # main()
169 # ------
170 #
171 ###############################################################################
172
173 basic_jam_action_test()
174 boost_build_testing_support_timing_rule()
175 boost_build_testing_support_timing_rule_with_spaces_in_names()