timedata.py 5.1 KB

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