testability-driver 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. data/README +1 -0
  2. data/bin/start_app_perf +199 -0
  3. data/bin/tdriver-devtools +3 -0
  4. data/config/sut_parameters.rb +39 -0
  5. data/ext/extconf.rb +67 -0
  6. data/ext/native_extensions.c +70 -0
  7. data/lib/matti.rb +30 -0
  8. data/lib/tdriver-devtools/behaviour/old/xml/example/flick-example.rb +223 -0
  9. data/lib/tdriver-devtools/behaviour/old/xml/example/impl.rb_invalid +194 -0
  10. data/lib/tdriver-devtools/behaviour/old/xml/generate_behaviour_xml.rb +95 -0
  11. data/lib/tdriver-devtools/behaviour/old/xml/lib/tdriver_generator.rb +722 -0
  12. data/lib/tdriver-devtools/behaviour/old/xml/qdoc_generator.rb +321 -0
  13. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.method.template +43 -0
  14. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.module.template +54 -0
  15. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument.template +7 -0
  16. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument_type.template +7 -0
  17. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.exception.template +5 -0
  18. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.line.template +2 -0
  19. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.template +5 -0
  20. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.method.template +23 -0
  21. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.template +14 -0
  22. data/lib/tdriver-devtools/behaviour/old/xml/update +3 -0
  23. data/lib/tdriver-devtools/behaviour/xml/generate.rb +88 -0
  24. data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +1924 -0
  25. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.default.template +1 -0
  26. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.template +3 -0
  27. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument_type.template +4 -0
  28. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.exception.template +4 -0
  29. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.arguments.template +4 -0
  30. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.deprecated.template +3 -0
  31. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.exceptions.template +3 -0
  32. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.info.template +1 -0
  33. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.returns.template +3 -0
  34. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.tables.template +3 -0
  35. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.template +12 -0
  36. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.returns.template +5 -0
  37. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.item.template +1 -0
  38. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.row.template +2 -0
  39. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.template +8 -0
  40. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.template +14 -0
  41. data/lib/tdriver-devtools/behaviour/xml_generator/example/flick-example.rb +245 -0
  42. data/lib/tdriver-devtools/behaviour/xml_generator/example/sut.rb +964 -0
  43. data/lib/tdriver-devtools/behaviour/xml_generator/generate.rb +68 -0
  44. data/lib/tdriver-devtools/behaviour/xml_generator/lib/custom_rdoc_generator.rb +1865 -0
  45. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.default.template +1 -0
  46. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.template +3 -0
  47. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument_type.template +4 -0
  48. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.exception.template +4 -0
  49. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.arguments.template +4 -0
  50. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.deprecated.template +3 -0
  51. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.exceptions.template +3 -0
  52. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.info.template +1 -0
  53. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.returns.template +3 -0
  54. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.tables.template +3 -0
  55. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.template +12 -0
  56. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.returns.template +5 -0
  57. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.item.template +1 -0
  58. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.row.template +2 -0
  59. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.template +7 -0
  60. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.template +14 -0
  61. data/lib/tdriver-devtools/behaviour/xml_generator/update +3 -0
  62. data/lib/tdriver-devtools/doc/behaviour_xml/QtExampleGestureBehaviour.xml +138 -0
  63. data/lib/tdriver-devtools/doc/behaviour_xml/created.rid +1 -0
  64. data/lib/tdriver-devtools/doc/behaviour_xml/tdriver.hash +1 -0
  65. data/lib/tdriver-devtools/doc/feature_xml/qt_widget_hold.feature.xml +9 -0
  66. data/lib/tdriver-devtools/doc/feature_xml/qt_widget_tap.feature.xml +9 -0
  67. data/lib/tdriver-devtools/doc/generate.rb +892 -0
  68. data/lib/tdriver-devtools/doc/update +1 -0
  69. data/lib/tdriver-devtools/doc/xslt/html.rb +7 -0
  70. data/lib/tdriver-devtools/doc/xslt/template.xsl +1861 -0
  71. data/lib/tdriver-devtools/doc/xslt/update +3 -0
  72. data/lib/tdriver-devtools/plugin/placeholder.txt +1 -0
  73. data/lib/tdriver-devtools/tdriver-devtools.rb +404 -0
  74. data/lib/tdriver-devtools/tests/feature_tests/example/flick-example.rb +233 -0
  75. data/lib/tdriver-devtools/tests/feature_tests/example/impl.rb +194 -0
  76. data/lib/tdriver-devtools/tests/feature_tests/generate.rb +82 -0
  77. data/lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb +468 -0
  78. data/lib/tdriver-devtools/tests/feature_tests/templates/feature_attribute.template +5 -0
  79. data/lib/tdriver-devtools/tests/feature_tests/templates/feature_method.template +5 -0
  80. data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_attribute.template +5 -0
  81. data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_method.template +5 -0
  82. data/lib/tdriver-devtools/tests/feature_tests/update +3 -0
  83. data/lib/tdriver.rb +26 -0
  84. data/lib/tdriver/base/behaviour/behaviour.rb +32 -0
  85. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +94 -0
  86. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +262 -0
  87. data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +111 -0
  88. data/lib/tdriver/base/behaviour/factory.rb +380 -0
  89. data/lib/tdriver/base/behaviour/loader.rb +28 -0
  90. data/lib/tdriver/base/command_data/command_data.rb +51 -0
  91. data/lib/tdriver/base/command_data/loader.rb +25 -0
  92. data/lib/tdriver/base/errors.rb +131 -0
  93. data/lib/tdriver/base/loader.rb +38 -0
  94. data/lib/tdriver/base/state_object.rb +270 -0
  95. data/lib/tdriver/base/sut/adapter.rb +28 -0
  96. data/lib/tdriver/base/sut/controller.rb +119 -0
  97. data/lib/tdriver/base/sut/factory.rb +287 -0
  98. data/lib/tdriver/base/sut/generic/behaviours/application.rb +243 -0
  99. data/lib/tdriver/base/sut/generic/behaviours/controller.rb +67 -0
  100. data/lib/tdriver/base/sut/generic/behaviours/find.rb +96 -0
  101. data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +346 -0
  102. data/lib/tdriver/base/sut/generic/behaviours/sut.rb +1268 -0
  103. data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +182 -0
  104. data/lib/tdriver/base/sut/generic/behaviours/verification.rb +119 -0
  105. data/lib/tdriver/base/sut/generic/commands/application.rb +219 -0
  106. data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +82 -0
  107. data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +58 -0
  108. data/lib/tdriver/base/sut/generic/plugin.rb +96 -0
  109. data/lib/tdriver/base/sut/loader.rb +35 -0
  110. data/lib/tdriver/base/sut/sut.rb +67 -0
  111. data/lib/tdriver/base/test_object/abstract.rb +179 -0
  112. data/lib/tdriver/base/test_object/behaviours/syncronization.rb +94 -0
  113. data/lib/tdriver/base/test_object/behaviours/test_object.rb +787 -0
  114. data/lib/tdriver/base/test_object/factory.rb +618 -0
  115. data/lib/tdriver/base/test_object/identificator.rb +511 -0
  116. data/lib/tdriver/base/test_object/loader.rb +37 -0
  117. data/lib/tdriver/env.rb +21 -0
  118. data/lib/tdriver/loader.rb +36 -0
  119. data/lib/tdriver/matti.rb +35 -0
  120. data/lib/tdriver/report/error_recovery/tdriver_custom_error_recovery.rb +83 -0
  121. data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +158 -0
  122. data/lib/tdriver/report/error_recovery/tdriver_error_recovery_settings.rb +98 -0
  123. data/lib/tdriver/report/report.rb +47 -0
  124. data/lib/tdriver/report/report_api.rb +207 -0
  125. data/lib/tdriver/report/report_combine.rb +86 -0
  126. data/lib/tdriver/report/report_crash_file_capture.rb +167 -0
  127. data/lib/tdriver/report/report_creator.rb +571 -0
  128. data/lib/tdriver/report/report_cucumber.rb +158 -0
  129. data/lib/tdriver/report/report_cucumber_listener.rb +337 -0
  130. data/lib/tdriver/report/report_cucumber_reporter.rb +335 -0
  131. data/lib/tdriver/report/report_data_presentation.rb +152 -0
  132. data/lib/tdriver/report/report_data_table.rb +64 -0
  133. data/lib/tdriver/report/report_execution_statistics.rb +284 -0
  134. data/lib/tdriver/report/report_file_capture.rb +159 -0
  135. data/lib/tdriver/report/report_grouping.rb +539 -0
  136. data/lib/tdriver/report/report_junit_xml.rb +147 -0
  137. data/lib/tdriver/report/report_rspec.rb +108 -0
  138. data/lib/tdriver/report/report_test_case_run.rb +621 -0
  139. data/lib/tdriver/report/report_test_run.rb +1286 -0
  140. data/lib/tdriver/report/report_test_unit.rb +175 -0
  141. data/lib/tdriver/report/report_writer.rb +1405 -0
  142. data/lib/tdriver/tdriver.rb +158 -0
  143. data/lib/tdriver/util/common.rb +24 -0
  144. data/lib/tdriver/util/common/array.rb +39 -0
  145. data/lib/tdriver/util/common/crc16.rb +100 -0
  146. data/lib/tdriver/util/common/environment.rb +153 -0
  147. data/lib/tdriver/util/common/error.rb +39 -0
  148. data/lib/tdriver/util/common/file.rb +315 -0
  149. data/lib/tdriver/util/common/gem.rb +108 -0
  150. data/lib/tdriver/util/common/kernel.rb +189 -0
  151. data/lib/tdriver/util/common/loader.rb +39 -0
  152. data/lib/tdriver/util/common/retryable.rb +98 -0
  153. data/lib/tdriver/util/common/string.rb +77 -0
  154. data/lib/tdriver/util/dbaccess/dbaccess.rb +188 -0
  155. data/lib/tdriver/util/dbaccess/dbconnection.rb +41 -0
  156. data/lib/tdriver/util/dbaccess/error.rb +35 -0
  157. data/lib/tdriver/util/dbaccess/loader.rb +29 -0
  158. data/lib/tdriver/util/dynamic_attribute_filter.rb +182 -0
  159. data/lib/tdriver/util/hooking.rb +434 -0
  160. data/lib/tdriver/util/loader.rb +65 -0
  161. data/lib/tdriver/util/localisation.rb +24 -0
  162. data/lib/tdriver/util/localisation/error.rb +32 -0
  163. data/lib/tdriver/util/localisation/loader.rb +28 -0
  164. data/lib/tdriver/util/localisation/localisation.rb +479 -0
  165. data/lib/tdriver/util/logger.rb +377 -0
  166. data/lib/tdriver/util/operator_data/error.rb +29 -0
  167. data/lib/tdriver/util/operator_data/loader.rb +26 -0
  168. data/lib/tdriver/util/operator_data/operator_data.rb +93 -0
  169. data/lib/tdriver/util/other/config.rb +221 -0
  170. data/lib/tdriver/util/parameter.rb +24 -0
  171. data/lib/tdriver/util/parameter/error.rb +45 -0
  172. data/lib/tdriver/util/parameter/loader.rb +37 -0
  173. data/lib/tdriver/util/parameter/parameter.rb +285 -0
  174. data/lib/tdriver/util/parameter/parameter_hash.rb +101 -0
  175. data/lib/tdriver/util/parameter/parameter_template.rb +120 -0
  176. data/lib/tdriver/util/parameter/parameter_user_api.rb +84 -0
  177. data/lib/tdriver/util/parameter/parameter_xml.rb +247 -0
  178. data/lib/tdriver/util/plugin/abstract.rb +60 -0
  179. data/lib/tdriver/util/plugin/error.rb +25 -0
  180. data/lib/tdriver/util/plugin/loader.rb +28 -0
  181. data/lib/tdriver/util/plugin/service.rb +200 -0
  182. data/lib/tdriver/util/recorder.rb +292 -0
  183. data/lib/tdriver/util/stats.rb +90 -0
  184. data/lib/tdriver/util/user_data/error.rb +29 -0
  185. data/lib/tdriver/util/user_data/loader.rb +26 -0
  186. data/lib/tdriver/util/user_data/user_data.rb +103 -0
  187. data/lib/tdriver/util/video_rec.rb +264 -0
  188. data/lib/tdriver/util/xml/abstraction.rb +47 -0
  189. data/lib/tdriver/util/xml/builder.rb +54 -0
  190. data/lib/tdriver/util/xml/document.rb +32 -0
  191. data/lib/tdriver/util/xml/element.rb +32 -0
  192. data/lib/tdriver/util/xml/error.rb +46 -0
  193. data/lib/tdriver/util/xml/loader.rb +46 -0
  194. data/lib/tdriver/util/xml/nil_element.rb +89 -0
  195. data/lib/tdriver/util/xml/nodeset.rb +32 -0
  196. data/lib/tdriver/util/xml/parsers/libxml/libxml.rb +140 -0
  197. data/lib/tdriver/util/xml/parsers/loader.rb +22 -0
  198. data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +111 -0
  199. data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +54 -0
  200. data/lib/tdriver/util/xml/parsers/nokogiri/builder.rb +58 -0
  201. data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +58 -0
  202. data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +147 -0
  203. data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +42 -0
  204. data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +187 -0
  205. data/lib/tdriver/util/xml/xml.rb +170 -0
  206. data/lib/tdriver/verify/verify.rb +687 -0
  207. data/lib/tdriver/verify/verify.rb_org +630 -0
  208. data/lib/tdriver/version.rb +21 -0
  209. data/xml/behaviours/generic.xml +495 -0
  210. data/xml/defaults/generic.xml +97 -0
  211. data/xml/defaults/sut_generic.xml +36 -0
  212. data/xml/parameters/tdriver_parameters.xml +23 -0
  213. data/xml/templates/generic.xml +227 -0
  214. metadata +327 -0
@@ -0,0 +1,41 @@
1
+ ############################################################################
2
+ ##
3
+ ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
+ ## All rights reserved.
5
+ ## Contact: Nokia Corporation (testabilitydriver@nokia.com)
6
+ ##
7
+ ## This file is part of Testability Driver.
8
+ ##
9
+ ## If you have questions regarding the use of this file, please contact
10
+ ## Nokia at testabilitydriver@nokia.com .
11
+ ##
12
+ ## This library is free software; you can redistribute it and/or
13
+ ## modify it under the terms of the GNU Lesser General Public
14
+ ## License version 2.1 as published by the Free Software Foundation
15
+ ## and appearing in the file LICENSE.LGPL included in the packaging
16
+ ## of this file.
17
+ ##
18
+ ############################################################################
19
+
20
+
21
+ module MobyUtil
22
+
23
+ class DBConnection
24
+ attr_accessor :db_type, :host, :database_name, :username, :password, :dbh
25
+
26
+ # == description
27
+ # Initialize connection object
28
+ #
29
+ def initialize( db_type, host, database_name, username, password )
30
+ @db_type = db_type.to_s.downcase
31
+ @host = host.to_s.downcase
32
+ @database_name = database_name
33
+ @username = username
34
+ @password = password
35
+ @dbh = nil
36
+ end
37
+
38
+ end # class
39
+
40
+ end # module
41
+
@@ -0,0 +1,35 @@
1
+ ############################################################################
2
+ ##
3
+ ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
+ ## All rights reserved.
5
+ ## Contact: Nokia Corporation (testabilitydriver@nokia.com)
6
+ ##
7
+ ## This file is part of Testability Driver.
8
+ ##
9
+ ## If you have questions regarding the use of this file, please contact
10
+ ## Nokia at testabilitydriver@nokia.com .
11
+ ##
12
+ ## This library is free software; you can redistribute it and/or
13
+ ## modify it under the terms of the GNU Lesser General Public
14
+ ## License version 2.1 as published by the Free Software Foundation
15
+ ## and appearing in the file LICENSE.LGPL included in the packaging
16
+ ## of this file.
17
+ ##
18
+ ############################################################################
19
+
20
+
21
+ module MobyUtil
22
+
23
+ # This error should be raised when no database type is defined
24
+ class DbTypeNotDefinedError < CustomError; end;
25
+
26
+ # This error should be raised when not supported db type is defined
27
+ class DbTypeNotSupportedError < CustomError; end;
28
+
29
+ # This error should be raised when there is connectivity problem with sql database
30
+ class SqlConnectError < CustomError; end;
31
+
32
+ # This error should be raised when there is problem with sql query
33
+ class SqlError < CustomError; end;
34
+
35
+ end
@@ -0,0 +1,29 @@
1
+ ############################################################################
2
+ ##
3
+ ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
+ ## All rights reserved.
5
+ ## Contact: Nokia Corporation (testabilitydriver@nokia.com)
6
+ ##
7
+ ## This file is part of Testability Driver.
8
+ ##
9
+ ## If you have questions regarding the use of this file, please contact
10
+ ## Nokia at testabilitydriver@nokia.com .
11
+ ##
12
+ ## This library is free software; you can redistribute it and/or
13
+ ## modify it under the terms of the GNU Lesser General Public
14
+ ## License version 2.1 as published by the Free Software Foundation
15
+ ## and appearing in the file LICENSE.LGPL included in the packaging
16
+ ## of this file.
17
+ ##
18
+ ############################################################################
19
+
20
+
21
+
22
+
23
+ # dbaccess related errors
24
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'error.rb' ) )
25
+
26
+ # dbaccess module implementation
27
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'dbaccess.rb' ) )
28
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'dbconnection.rb' ) )
29
+
@@ -0,0 +1,182 @@
1
+ ############################################################################
2
+ ##
3
+ ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
+ ## All rights reserved.
5
+ ## Contact: Nokia Corporation (testabilitydriver@nokia.com)
6
+ ##
7
+ ## This file is part of Testability Driver.
8
+ ##
9
+ ## If you have questions regarding the use of this file, please contact
10
+ ## Nokia at testabilitydriver@nokia.com .
11
+ ##
12
+ ## This library is free software; you can redistribute it and/or
13
+ ## modify it under the terms of the GNU Lesser General Public
14
+ ## License version 2.1 as published by the Free Software Foundation
15
+ ## and appearing in the file LICENSE.LGPL included in the packaging
16
+ ## of this file.
17
+ ##
18
+ ############################################################################
19
+
20
+ module MobyUtil
21
+
22
+ class DynamicAttributeFilter
23
+
24
+ include Singleton
25
+
26
+ attr_accessor :filter_string
27
+
28
+ def initialize
29
+
30
+ @filter_string = "" # coma separated list of symbol names in the filter
31
+
32
+ @attributes = []
33
+
34
+ @files = []
35
+
36
+ end
37
+
38
+ def update_filter( backtrace )
39
+
40
+ begin
41
+
42
+ if backtrace.collect{ | stack_point |
43
+
44
+ next if stack_point =~ /^\(eval\)/ # skip eval trace lines
45
+
46
+ read_attributes_from_file( $1 ) unless @files.include?( $1 ) if stack_point =~ /([\w\/:_\-\.\\\s\']+\.rb):\d+/
47
+
48
+ }.include?( true )
49
+
50
+ # new symbols added, update filter string
51
+ update_filter_string
52
+
53
+ end
54
+
55
+ rescue Exception => exception
56
+
57
+ puts exception
58
+
59
+ puts exception.backtrace
60
+
61
+ end
62
+ end
63
+
64
+ # Adds a hard coded symbol to be added to every filter.
65
+ # Used in situations when variables are used to identify
66
+ # attributes e.g:
67
+ # var = 'text'
68
+ # app.Object.attribute(var)
69
+ def add_hardcoded_symbol( symbol )
70
+
71
+ $stderr.puts "warning: DynamicAttributeFilter#add_hardcoded_symbol is deprecated, please use DynamicAttributeFilter#add_attribute instead."
72
+
73
+ # update filter if new symbols added
74
+ update_filter_string if add_attribute_to_filter( symbol )
75
+
76
+ end
77
+
78
+ def add_attribute( symbol )
79
+
80
+ # update filter if new symbols added
81
+ update_filter_string if add_attribute_to_filter( symbol )
82
+
83
+ end
84
+
85
+ def add_attributes( symbols )
86
+
87
+ # update filter if new symbols added
88
+ update_filter_string if symbols.collect{ | symbol | add_attribute_to_filter( symbol ) }.include?( true )
89
+
90
+ end
91
+
92
+ private
93
+
94
+ # == returns
95
+ # Boolean:: determine that was symbol added to attributes list or not
96
+ def add_attribute_to_filter( symbol )
97
+
98
+ symbol = symbol.to_s
99
+
100
+ unless @attributes.include?( symbol )
101
+
102
+ # add symbol to atributes list
103
+ @attributes << symbol
104
+
105
+ true
106
+
107
+ else
108
+
109
+ false
110
+
111
+ end
112
+
113
+ end
114
+
115
+ def update_filter_string
116
+
117
+ @filter_string = @attributes.join( "," )
118
+
119
+ end
120
+
121
+ # This method will parse a file to collect its symbols and add them to the @filter
122
+ # It will skip already parsed files
123
+ # == params
124
+ # String:: File path to the file to parse for symbols
125
+ # == returns
126
+ #
127
+ # == throws
128
+ #
129
+ def read_attributes_from_file( file_name )
130
+
131
+ #DEBUG
132
+ #puts "File skipped :" + file_name if @files.include?( file_name )
133
+
134
+ unless @files.include?( file_name )
135
+
136
+ open( file_name ) do | file |
137
+
138
+ file.each do | line |
139
+
140
+ # Line Parser
141
+ next if ( line.nil? or line =~ /^#/ ) # ignore comments
142
+
143
+ line_symbols =
144
+ (
145
+ # :attribute => value
146
+ line.scan( /[^:]\:(\w+)\s*\=\>/ )
147
+
148
+ ).concat(
149
+
150
+ # .attribute( 'name' )
151
+ line.scan( /\.attribute\s*[\(\s]{1}\s*["']{1}(\w+)["']{1}[\)\s]{1}/ )
152
+
153
+ ).concat(
154
+
155
+ # .attribute( :name )
156
+ line.scan( /\.attribute\s*[\(\s]{1}\s*[:]{1}(\w+)[\)\s]{1}/ )
157
+ )
158
+
159
+ next if line_symbols.empty? # skip lines with no symbols
160
+
161
+ # store found attributes
162
+ @attributes.concat( line_symbols.collect{ | value | value[ 0 ] }.compact ).uniq!
163
+ end
164
+
165
+ end
166
+
167
+ # store filename that we don't scan the file again...
168
+ @files << file_name
169
+
170
+ # do not change this or evaluate anything after this line; update filter behaviour depends of this return value
171
+ true
172
+
173
+ end
174
+
175
+ end
176
+
177
+ # enable hooking for performance measurement & debug logging
178
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
179
+
180
+ end # DynamicAttributeFilter
181
+
182
+ end # MobyUtil
@@ -0,0 +1,434 @@
1
+ ############################################################################
2
+ ##
3
+ ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
+ ## All rights reserved.
5
+ ## Contact: Nokia Corporation (testabilitydriver@nokia.com)
6
+ ##
7
+ ## This file is part of Testability Driver.
8
+ ##
9
+ ## If you have questions regarding the use of this file, please contact
10
+ ## Nokia at testabilitydriver@nokia.com .
11
+ ##
12
+ ## This library is free software; you can redistribute it and/or
13
+ ## modify it under the terms of the GNU Lesser General Public
14
+ ## License version 2.1 as published by the Free Software Foundation
15
+ ## and appearing in the file LICENSE.LGPL included in the packaging
16
+ ## of this file.
17
+ ##
18
+ ############################################################################
19
+ module MobyUtil
20
+
21
+ class Hooking
22
+
23
+ include Singleton
24
+
25
+ attr_accessor :wrappee_count
26
+ attr_accessor :wrapped_methods
27
+ attr_accessor :benchmark
28
+
29
+ # list of non-wrappable methods
30
+ @@non_wrappable_methods = [ 'instance' ]
31
+
32
+ def initialize
33
+
34
+ # default values
35
+ @wrapped_methods = {}
36
+
37
+ @wrappee_count = 0
38
+ @benchmark = {}
39
+
40
+ @logger_method = nil
41
+ @logger_instance = nil
42
+
43
+ $mobyutil_hooking_instance = self
44
+ $mobyutil_hooking_elapsed_time = []
45
+
46
+ $mobyutil_hooking_start_benchmark_time = Time.now
47
+ $mobyutil_hooking_last_call_end_time = Time.now
48
+
49
+ end
50
+
51
+ # Function to set logger instance used by wrapper
52
+ # == params
53
+ # logger_instance:: Instance of TDriver logger
54
+ # == returns
55
+ def set_logger_instance( logger_instance )
56
+
57
+ @logger_instance = logger_instance
58
+
59
+ nil
60
+
61
+ end
62
+
63
+ # Function to create logger event - this method is called from wrapper
64
+ # == params
65
+ # text:: Text sent from wrapper
66
+ # arguments:: Not in use
67
+ # == returns
68
+ def log( text, *arguments )
69
+
70
+
71
+ unless @logger_instance.nil?
72
+
73
+ @logger_instance.debug( "%s" % text ) # if @logger_instance.enabled
74
+
75
+ end
76
+
77
+ #@logger_instance.log( "debug", "%s" % text ) unless @logger_instance.nil?
78
+
79
+ nil
80
+
81
+ end
82
+
83
+ # Function to hook all instance and static methods of target Class/Module
84
+ # == params
85
+ # base:: Target Class or Module
86
+ # == returns
87
+ def hook_methods( _base )
88
+
89
+ hook_static_methods( _base )
90
+ hook_instance_methods( _base )
91
+
92
+ nil
93
+
94
+ end
95
+
96
+ def add_wrapper( wrapper )
97
+
98
+ @wrapped_methods.merge!( wrapper )
99
+ @wrappee_count += 1
100
+
101
+ end
102
+
103
+ # Function to update method runtime & calls count for benchmark
104
+ # == params
105
+ # method_name:: Name of the target method
106
+ # time_elapsed_in_subcalls::
107
+ # total_time_elapsed::
108
+ def update_method_benchmark( method_name, time_elapsed_in_subcalls, total_time_elapsed )
109
+
110
+ @benchmark[ method_name ].tap{ | hash |
111
+
112
+ hash[ :time_elapsed ] += ( total_time_elapsed - time_elapsed_in_subcalls )
113
+ hash[ :time_elapsed_total ] += total_time_elapsed
114
+ hash[ :times_called ] += 1
115
+
116
+ }
117
+
118
+ end
119
+
120
+ def print_benchmark( rules = {} )
121
+
122
+ #total_run_time = $mobyutil_hooking_last_call_end_time - $mobyutil_hooking_start_benchmark_time
123
+
124
+ total_run_time = 0
125
+
126
+ # :sort => :total_time || :times_called || :average_time
127
+
128
+ rules = { :sort => :total_time, :order => :ascending, :show_uncalled_methods => true }.merge( rules )
129
+
130
+ puts "%-80s %8s %15s %15s %9s %15s" % [ 'Name:', 'Calls:', 'Time total:', 'W/O subcalls:', '%/run', 'Total/call:' ]
131
+ puts "%-80s %8s %15s %15s %9s %15s" % [ '-' * 80, '-' * 8, '-' * 15, '-' * 15, '-' * 8, '-' * 15 ]
132
+
133
+ # calculate average time for method
134
+ ( table = @benchmark ).each{ | key, value |
135
+
136
+ table[ key ][ :average_time ] = ( value[ :times_elapsed_total ] == 0 || value[ :times_called ] == 0 ) ? 0 : value[ :time_elapsed_total ] / value[ :times_called ]
137
+
138
+ total_run_time += value[ :time_elapsed ]
139
+
140
+ }
141
+
142
+ table = table.sort{ | method_a, method_b |
143
+
144
+ case rules[ :sort ]
145
+
146
+ when :name
147
+ method_a[ 0 ] <=> method_b[ 0 ]
148
+
149
+ when :times_called
150
+ method_a[ 1 ][ :times_called ] <=> method_b[ 1 ][ :times_called ]
151
+
152
+ when :total_time
153
+ method_a[ 1 ][ :time_elapsed_total ] <=> method_b[ 1 ][ :time_elapsed_total ]
154
+
155
+ when :total_time_no_subs
156
+ method_a[ 1 ][ :time_elapsed ] <=> method_b[ 1 ][ :time_elapsed ]
157
+
158
+ when :percentage
159
+
160
+ ( ( method_a[ 1 ][ :time_elapsed ].to_f / total_run_time.to_f ) * 100 ) <=> ( ( method_b[ 1 ][ :time_elapsed ].to_f / total_run_time.to_f ) * 100 )
161
+
162
+ when :average_time
163
+ method_a[ 1 ][ :average_time ] <=> method_b[ 1 ][ :average_time ]
164
+
165
+ else
166
+
167
+ Kernel::raise ArgumentError.new("Invalid sorting rule, valid rules are :name, :times_called, :total_time, :total_time_no_subs, :percentage or :average_time")
168
+
169
+ end
170
+
171
+ }
172
+
173
+ case rules[ :order ]
174
+
175
+ when :ascending
176
+ # do nothing
177
+
178
+ when :descending
179
+ table = table.reverse
180
+
181
+ else
182
+
183
+ Kernel::raise ArgumentError.new("Invalid sort order rule, valid rules are :ascending, :descending")
184
+
185
+ end
186
+
187
+ total_percentage = 0.0
188
+ total_time_elapsed_total = 0.0
189
+ total_average = 0.0
190
+ total_calls = 0
191
+
192
+ table.each{ | method |
193
+
194
+ puts "%-80s %8s %15.8f %15.8f %8.3f%% %15.8f" % [
195
+ method[ 0 ],
196
+ method[ 1 ][ :times_called ],
197
+ method[ 1 ][ :time_elapsed_total ],
198
+ method[ 1 ][ :time_elapsed ],
199
+
200
+ ( ( method[ 1 ][ :time_elapsed ].to_f / total_run_time.to_f ) * 100 ),
201
+
202
+ method[ 1 ][ :average_time ]
203
+ ] unless !rules[ :show_uncalled_methods ] && method[ 1 ][ :times_called ] == 0
204
+
205
+ total_percentage += ( ( method[ 1 ][ :time_elapsed ].to_f / total_run_time.to_f ) * 100 )
206
+
207
+ total_calls += method[ 1 ][ :times_called ]
208
+ total_time_elapsed_total += method[ 1 ][ :time_elapsed_total ]
209
+ total_average += method[ 1 ][ :average_time ]
210
+
211
+ }
212
+
213
+ puts "%-80s %8s %15s %15s %9s %15s" % [ '-' * 80, '-' * 8, '-' * 15, '-' * 15, '-' * 8, '-' * 15 ]
214
+
215
+ puts "%-80s %8s %15.6f %15.6f %8.3f%% %15.8f" % [ 'Total:', total_calls, total_time_elapsed_total, total_run_time, total_percentage, total_average ]
216
+
217
+ end
218
+
219
+
220
+ private
221
+
222
+ # Function to hook a method
223
+ # == params
224
+ # base:: Class or Module
225
+ # method_name:: Name of the method
226
+ # method_type:: public, private or static
227
+ # == returns
228
+ def hook_method( base, method_name, method_type )
229
+
230
+ # create only one wrapper for each method
231
+ unless MobyUtil::Hooking.instance.wrapped_methods.has_key?( "#{ base.name }::#{ method_name }" )
232
+
233
+ # evaluate the generated wrapper source code
234
+ eval("base.#{ base.class.name.downcase }_eval( \"#{ make_wrapper( base, method_name.to_s, method_type.to_s )}\" )") if [ Class, Module ].include?( base.class )
235
+
236
+ end
237
+
238
+ nil
239
+
240
+ end
241
+
242
+ # Function to hook static methods for given Class or Module
243
+ # == params
244
+ # base:: Target Class or Module
245
+ # == returns
246
+ def hook_static_methods( _base )
247
+
248
+ if [ Class, Module ].include?( _base.class )
249
+
250
+ _base.singleton_methods( false ).each { | method_name |
251
+
252
+ hook_method( _base, method_name, "static" ) unless @@non_wrappable_methods.include?( method_name )
253
+
254
+ }
255
+
256
+ end
257
+
258
+ nil
259
+ end
260
+
261
+ # Function to hook instance methods for given Class or Module
262
+ # == params
263
+ # base:: Target Class or Module
264
+ # == returns
265
+ def hook_instance_methods( _base )
266
+
267
+ if [ Class, Module ].include?( _base.class )
268
+
269
+ { :public => _base.public_instance_methods( false ), :private => _base.private_instance_methods( false ), :protected => _base.protected_instance_methods( false ) }.each { | method_type, methods |
270
+
271
+ methods.each { | method_name | hook_method( _base, method_name, method_type.to_s ) unless /__wrappee_\d+/i.match( method_name ) }
272
+
273
+ }
274
+
275
+ end
276
+
277
+ nil
278
+ end
279
+
280
+ # Function to retrieve method path (e.g. Module1::Module2::Class1)
281
+ # == params
282
+ # base:: Target Class or Module
283
+ # == returns
284
+ # String:: Method path
285
+ def method_path( _base )
286
+
287
+ if [ Class, Module ].include?( _base.class )
288
+
289
+ _base.name
290
+
291
+ else
292
+
293
+ _base.class.name
294
+
295
+ end
296
+
297
+ end
298
+
299
+ # Function to generate unique name for wrappee method
300
+ # == params
301
+ # method_name:: Name of the target method
302
+ # == returns
303
+ # String:: Unique name for wrappee method
304
+ def create_wrappee_name( method_name )
305
+
306
+ wrappee_name = "non_pritanble_method_name" if ( wrappee_name = ( /[a-z0-9_]*/i.match( method_name ) ) ).length == 0
307
+
308
+ wrappee_name = "__wrappee_#{ @wrappee_count }__#{ wrappee_name }"
309
+
310
+ end
311
+
312
+ # Function for create source code of wrapper for method
313
+ # == params
314
+ # base:: Class or Module
315
+ # method_name:: Name of the method
316
+ # method_type:: public, private or static
317
+ # == returns
318
+ # String:: source code
319
+ def make_wrapper( base, method_name, method_type = nil )
320
+
321
+ # method name with namespace
322
+ base_and_method_name = "#{ base.name }::#{ method_name }"
323
+
324
+ # add method to benchmark table
325
+ @benchmark[ base_and_method_name ] = { :time_elapsed => 0 , :times_called => 0, :time_elapsed_total => 0 } if ENV[ 'TDRIVER_BENCHMARK' ].to_s.downcase == 'true'
326
+
327
+ # create new name for original method
328
+ original_method_name = create_wrappee_name( method_name )
329
+
330
+ # add method to wrapper methods list
331
+ @wrapped_methods.merge!( base_and_method_name => nil )
332
+ @wrappee_count += 1
333
+
334
+ case method_type
335
+
336
+ when 'public', 'private', 'static'
337
+
338
+ source = "
339
+ #{
340
+ # this is needed if method is static
341
+ "class << self" if method_type == 'static'
342
+
343
+ }
344
+
345
+ # create a copy of original method
346
+ alias_method :#{ original_method_name }, :#{ method_name }
347
+
348
+ #{
349
+
350
+ if method_type == 'static'
351
+
352
+ # undefine original version if static method
353
+ "self.send( :undef_method, :#{ method_name } )"
354
+
355
+ else
356
+
357
+ # method visiblity unless method type is static
358
+ "#{ method_type }"
359
+
360
+ end
361
+
362
+
363
+ }
364
+
365
+ def #{ method_name }( *args, &block )
366
+
367
+ # log method call
368
+ $mobyutil_hooking_instance.log( '#{ method_path( base ) }.#{ method_name }', nil )
369
+
370
+ #{
371
+
372
+ if ENV[ 'TDRIVER_BENCHMARK' ].to_s.downcase == 'true'
373
+
374
+ "# store start time for performance measurement
375
+ start_time = Time.now
376
+
377
+ # Time elapsed in sub calls
378
+ $mobyutil_hooking_elapsed_time << 0.0
379
+
380
+ begin
381
+
382
+ # call original method
383
+ result = method(:#{ original_method_name }).call( *args, &block )
384
+
385
+ rescue Exception => exception
386
+
387
+ raise exception
388
+
389
+ ensure
390
+
391
+ # calculate actual elapsed time, including time elapsed in sub calls
392
+ elapsed_time = ( ( $mobyutil_hooking_last_call_end_time = Time.now ) - start_time )
393
+
394
+ # elapsed time in sub calls
395
+ elapsed_time_in_subcalls = $mobyutil_hooking_elapsed_time.pop || 0
396
+
397
+ # add elapsed time to caller method
398
+ $mobyutil_hooking_elapsed_time[ -1 ] += elapsed_time unless $mobyutil_hooking_elapsed_time.empty?
399
+
400
+ # store performance results to benchmark hash
401
+ $mobyutil_hooking_instance.update_method_benchmark( '#{ base_and_method_name }', elapsed_time_in_subcalls, elapsed_time )
402
+
403
+ end
404
+
405
+ # return results
406
+ result"
407
+
408
+ else
409
+
410
+ "# call original method
411
+ result = self.method(:#{ original_method_name }).call( *args, &block )"
412
+
413
+ end
414
+
415
+ }
416
+
417
+ end
418
+
419
+ private :#{ original_method_name }
420
+
421
+ #{
422
+
423
+ # this is needed if method is static
424
+ "end" if method_type == 'static'
425
+
426
+ }"
427
+
428
+ end
429
+
430
+ end
431
+
432
+ end # Hooking
433
+
434
+ end # MobyUtil