R3T 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/GPL.txt +342 -0
  2. data/lib/threading_test_tools.rb +332 -0
  3. metadata +47 -0
data/GPL.txt ADDED
@@ -0,0 +1,342 @@
1
+ The GNU General Public License (GPL)
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
+
6
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7
+
8
+ Everyone is permitted to copy and distribute verbatim copies
9
+ of this license document, but changing it is not allowed.
10
+
11
+ Preamble
12
+
13
+ The licenses for most software are designed to take away your
14
+ freedom to share and change it. By contrast, the GNU General Public
15
+ License is intended to guarantee your freedom to share and change free
16
+ software--to make sure the software is free for all its users. This
17
+ General Public License applies to most of the Free Software
18
+ Foundation's software and to any other program whose authors commit to
19
+ using it. (Some other Free Software Foundation software is covered by
20
+ the GNU Library General Public License instead.) You can apply it to
21
+ your programs, too.
22
+
23
+ When we speak of free software, we are referring to freedom, not
24
+ price. Our General Public Licenses are designed to make sure that you
25
+ have the freedom to distribute copies of free software (and charge for
26
+ this service if you wish), that you receive source code or can get it
27
+ if you want it, that you can change the software or use pieces of it
28
+ in new free programs; and that you know you can do these things.
29
+
30
+ To protect your rights, we need to make restrictions that forbid
31
+ anyone to deny you these rights or to ask you to surrender the rights.
32
+ These restrictions translate to certain responsibilities for you if you
33
+ distribute copies of the software, or if you modify it.
34
+
35
+ For example, if you distribute copies of such a program, whether
36
+ gratis or for a fee, you must give the recipients all the rights that
37
+ you have. You must make sure that they, too, receive or can get the
38
+ source code. And you must show them these terms so they know their
39
+ rights.
40
+
41
+ We protect your rights with two steps: (1) copyright the software, and
42
+ (2) offer you this license which gives you legal permission to copy,
43
+ distribute and/or modify the software.
44
+
45
+ Also, for each author's protection and ours, we want to make certain
46
+ that everyone understands that there is no warranty for this free
47
+ software. If the software is modified by someone else and passed on, we
48
+ want its recipients to know that what they have is not the original, so
49
+ that any problems introduced by others will not reflect on the original
50
+ authors' reputations.
51
+
52
+ Finally, any free program is threatened constantly by software
53
+ patents. We wish to avoid the danger that redistributors of a free
54
+ program will individually obtain patent licenses, in effect making the
55
+ program proprietary. To prevent this, we have made it clear that any
56
+ patent must be licensed for everyone's free use or not licensed at all.
57
+
58
+ The precise terms and conditions for copying, distribution and
59
+ modification follow.
60
+
61
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
62
+
63
+ 0. This License applies to any program or other work which contains
64
+ a notice placed by the copyright holder saying it may be distributed
65
+ under the terms of this General Public License. The "Program", below,
66
+ refers to any such program or work, and a "work based on the Program"
67
+ means either the Program or any derivative work under copyright law:
68
+ that is to say, a work containing the Program or a portion of it,
69
+ either verbatim or with modifications and/or translated into another
70
+ language. (Hereinafter, translation is included without limitation in
71
+ the term "modification".) Each licensee is addressed as "you".
72
+
73
+ Activities other than copying, distribution and modification are not
74
+ covered by this License; they are outside its scope. The act of
75
+ running the Program is not restricted, and the output from the Program
76
+ is covered only if its contents constitute a work based on the
77
+ Program (independent of having been made by running the Program).
78
+ Whether that is true depends on what the Program does.
79
+
80
+ 1. You may copy and distribute verbatim copies of the Program's
81
+ source code as you receive it, in any medium, provided that you
82
+ conspicuously and appropriately publish on each copy an appropriate
83
+ copyright notice and disclaimer of warranty; keep intact all the
84
+ notices that refer to this License and to the absence of any warranty;
85
+ and give any other recipients of the Program a copy of this License
86
+ along with the Program.
87
+
88
+ You may charge a fee for the physical act of transferring a copy, and
89
+ you may at your option offer warranty protection in exchange for a fee.
90
+
91
+ 2. You may modify your copy or copies of the Program or any portion
92
+ of it, thus forming a work based on the Program, and copy and
93
+ distribute such modifications or work under the terms of Section 1
94
+ above, provided that you also meet all of these conditions:
95
+
96
+ a) You must cause the modified files to carry prominent notices
97
+ stating that you changed the files and the date of any change.
98
+
99
+ b) You must cause any work that you distribute or publish, that in
100
+ whole or in part contains or is derived from the Program or any
101
+ part thereof, to be licensed as a whole at no charge to all third
102
+ parties under the terms of this License.
103
+
104
+ c) If the modified program normally reads commands interactively
105
+ when run, you must cause it, when started running for such
106
+ interactive use in the most ordinary way, to print or display an
107
+ announcement including an appropriate copyright notice and a
108
+ notice that there is no warranty (or else, saying that you provide
109
+ a warranty) and that users may redistribute the program under
110
+ these conditions, and telling the user how to view a copy of this
111
+ License. (Exception: if the Program itself is interactive but
112
+ does not normally print such an announcement, your work based on
113
+ the Program is not required to print an announcement.)
114
+
115
+ These requirements apply to the modified work as a whole. If
116
+ identifiable sections of that work are not derived from the Program,
117
+ and can be reasonably considered independent and separate works in
118
+ themselves, then this License, and its terms, do not apply to those
119
+ sections when you distribute them as separate works. But when you
120
+ distribute the same sections as part of a whole which is a work based
121
+ on the Program, the distribution of the whole must be on the terms of
122
+ this License, whose permissions for other licensees extend to the
123
+ entire whole, and thus to each and every part regardless of who wrote it.
124
+
125
+ Thus, it is not the intent of this section to claim rights or contest
126
+ your rights to work written entirely by you; rather, the intent is to
127
+ exercise the right to control the distribution of derivative or
128
+ collective works based on the Program.
129
+
130
+ In addition, mere aggregation of another work not based on the Program
131
+ with the Program (or with a work based on the Program) on a volume of
132
+ a storage or distribution medium does not bring the other work under
133
+ the scope of this License.
134
+
135
+ 3. You may copy and distribute the Program (or a work based on it,
136
+ under Section 2) in object code or executable form under the terms of
137
+ Sections 1 and 2 above provided that you also do one of the following:
138
+
139
+ a) Accompany it with the complete corresponding machine-readable
140
+ source code, which must be distributed under the terms of Sections
141
+ 1 and 2 above on a medium customarily used for software interchange; or,
142
+
143
+ b) Accompany it with a written offer, valid for at least three
144
+ years, to give any third party, for a charge no more than your
145
+ cost of physically performing source distribution, a complete
146
+ machine-readable copy of the corresponding source code, to be
147
+ distributed under the terms of Sections 1 and 2 above on a medium
148
+ customarily used for software interchange; or,
149
+
150
+ c) Accompany it with the information you received as to the offer
151
+ to distribute corresponding source code. (This alternative is
152
+ allowed only for noncommercial distribution and only if you
153
+ received the program in object code or executable form with such
154
+ an offer, in accord with Subsection b above.)
155
+
156
+ The source code for a work means the preferred form of the work for
157
+ making modifications to it. For an executable work, complete source
158
+ code means all the source code for all modules it contains, plus any
159
+ associated interface definition files, plus the scripts used to
160
+ control compilation and installation of the executable. However, as a
161
+ special exception, the source code distributed need not include
162
+ anything that is normally distributed (in either source or binary
163
+ form) with the major components (compiler, kernel, and so on) of the
164
+ operating system on which the executable runs, unless that component
165
+ itself accompanies the executable.
166
+
167
+ If distribution of executable or object code is made by offering
168
+ access to copy from a designated place, then offering equivalent
169
+ access to copy the source code from the same place counts as
170
+ distribution of the source code, even though third parties are not
171
+ compelled to copy the source along with the object code.
172
+
173
+ 4. You may not copy, modify, sublicense, or distribute the Program
174
+ except as expressly provided under this License. Any attempt
175
+ otherwise to copy, modify, sublicense or distribute the Program is
176
+ void, and will automatically terminate your rights under this License.
177
+ However, parties who have received copies, or rights, from you under
178
+ this License will not have their licenses terminated so long as such
179
+ parties remain in full compliance.
180
+
181
+ 5. You are not required to accept this License, since you have not
182
+ signed it. However, nothing else grants you permission to modify or
183
+ distribute the Program or its derivative works. These actions are
184
+ prohibited by law if you do not accept this License. Therefore, by
185
+ modifying or distributing the Program (or any work based on the
186
+ Program), you indicate your acceptance of this License to do so, and
187
+ all its terms and conditions for copying, distributing or modifying
188
+ the Program or works based on it.
189
+
190
+ 6. Each time you redistribute the Program (or any work based on the
191
+ Program), the recipient automatically receives a license from the
192
+ original licensor to copy, distribute or modify the Program subject to
193
+ these terms and conditions. You may not impose any further
194
+ restrictions on the recipients' exercise of the rights granted herein.
195
+ You are not responsible for enforcing compliance by third parties to
196
+ this License.
197
+
198
+ 7. If, as a consequence of a court judgment or allegation of patent
199
+ infringement or for any other reason (not limited to patent issues),
200
+ conditions are imposed on you (whether by court order, agreement or
201
+ otherwise) that contradict the conditions of this License, they do not
202
+ excuse you from the conditions of this License. If you cannot
203
+ distribute so as to satisfy simultaneously your obligations under this
204
+ License and any other pertinent obligations, then as a consequence you
205
+ may not distribute the Program at all. For example, if a patent
206
+ license would not permit royalty-free redistribution of the Program by
207
+ all those who receive copies directly or indirectly through you, then
208
+ the only way you could satisfy both it and this License would be to
209
+ refrain entirely from distribution of the Program.
210
+
211
+ If any portion of this section is held invalid or unenforceable under
212
+ any particular circumstance, the balance of the section is intended to
213
+ apply and the section as a whole is intended to apply in other
214
+ circumstances.
215
+
216
+ It is not the purpose of this section to induce you to infringe any
217
+ patents or other property right claims or to contest validity of any
218
+ such claims; this section has the sole purpose of protecting the
219
+ integrity of the free software distribution system, which is
220
+ implemented by public license practices. Many people have made
221
+ generous contributions to the wide range of software distributed
222
+ through that system in reliance on consistent application of that
223
+ system; it is up to the author/donor to decide if he or she is willing
224
+ to distribute software through any other system and a licensee cannot
225
+ impose that choice.
226
+
227
+ This section is intended to make thoroughly clear what is believed to
228
+ be a consequence of the rest of this License.
229
+
230
+ 8. If the distribution and/or use of the Program is restricted in
231
+ certain countries either by patents or by copyrighted interfaces, the
232
+ original copyright holder who places the Program under this License
233
+ may add an explicit geographical distribution limitation excluding
234
+ those countries, so that distribution is permitted only in or among
235
+ countries not thus excluded. In such case, this License incorporates
236
+ the limitation as if written in the body of this License.
237
+
238
+ 9. The Free Software Foundation may publish revised and/or new versions
239
+ of the General Public License from time to time. Such new versions will
240
+ be similar in spirit to the present version, but may differ in detail to
241
+ address new problems or concerns.
242
+
243
+ Each version is given a distinguishing version number. If the Program
244
+ specifies a version number of this License which applies to it and "any
245
+ later version", you have the option of following the terms and conditions
246
+ either of that version or of any later version published by the Free
247
+ Software Foundation. If the Program does not specify a version number of
248
+ this License, you may choose any version ever published by the Free Software
249
+ Foundation.
250
+
251
+ 10. If you wish to incorporate parts of the Program into other free
252
+ programs whose distribution conditions are different, write to the author
253
+ to ask for permission. For software which is copyrighted by the Free
254
+ Software Foundation, write to the Free Software Foundation; we sometimes
255
+ make exceptions for this. Our decision will be guided by the two goals
256
+ of preserving the free status of all derivatives of our free software and
257
+ of promoting the sharing and reuse of software generally.
258
+
259
+ NO WARRANTY
260
+
261
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
262
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
263
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
264
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
265
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
266
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
267
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
268
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
269
+ REPAIR OR CORRECTION.
270
+
271
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
272
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
273
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
274
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
275
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
276
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
277
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
278
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
279
+ POSSIBILITY OF SUCH DAMAGES.
280
+
281
+ END OF TERMS AND CONDITIONS
282
+
283
+ How to Apply These Terms to Your New Programs
284
+
285
+ If you develop a new program, and you want it to be of the greatest
286
+ possible use to the public, the best way to achieve this is to make it
287
+ free software which everyone can redistribute and change under these terms.
288
+
289
+ To do so, attach the following notices to the program. It is safest
290
+ to attach them to the start of each source file to most effectively
291
+ convey the exclusion of warranty; and each file should have at least
292
+ the "copyright" line and a pointer to where the full notice is found.
293
+
294
+ One line to give the program's name and a brief idea of what it does.
295
+
296
+ Copyright (C) <year> <name of author>
297
+
298
+ This program is free software; you can redistribute it and/or modify
299
+ it under the terms of the GNU General Public License as published by
300
+ the Free Software Foundation; either version 2 of the License, or
301
+ (at your option) any later version.
302
+
303
+ This program is distributed in the hope that it will be useful,
304
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
305
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
306
+ GNU General Public License for more details.
307
+
308
+ You should have received a copy of the GNU General Public License
309
+ along with this program; if not, write to the Free Software
310
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
311
+
312
+ Also add information on how to contact you by electronic and paper mail.
313
+
314
+ If the program is interactive, make it output a short notice like this
315
+ when it starts in an interactive mode:
316
+
317
+ Gnomovision version 69, Copyright (C) year name of author
318
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
319
+ This is free software, and you are welcome to redistribute it
320
+ under certain conditions; type `show c' for details.
321
+
322
+ The hypothetical commands `show w' and `show c' should show the appropriate
323
+ parts of the General Public License. Of course, the commands you use may
324
+ be called something other than `show w' and `show c'; they could even be
325
+ mouse-clicks or menu items--whatever suits your program.
326
+
327
+ You should also get your employer (if you work as a programmer) or your
328
+ school, if any, to sign a "copyright disclaimer" for the program, if
329
+ necessary. Here is a sample; alter the names:
330
+
331
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
332
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
333
+
334
+ signature of Ty Coon, 1 April 1989
335
+
336
+ Ty Coon, President of Vice
337
+
338
+ This General Public License does not permit incorporating your program into
339
+ proprietary programs. If your program is a subroutine library, you may
340
+ consider it more useful to permit linking proprietary applications with the
341
+ library. If this is what you want to do, use the GNU Library General
342
+ Public License instead of this License.
@@ -0,0 +1,332 @@
1
+ require 'thread'
2
+ require 'thwait'
3
+ require 'mutex_m'
4
+ require 'monitor'
5
+ require 'sync'
6
+
7
+ $log = File.open('log.txt', 'w')
8
+
9
+ module ThreadingTestTools
10
+
11
+ class RaceConditionFound < RuntimeError
12
+ attr_reader :result_variables
13
+
14
+ def initialize(message, result_variables)
15
+ super(message)
16
+ @result_variables = result_variables
17
+ end
18
+ end
19
+
20
+ Object.module_eval <<-CODE_END
21
+ class Mutex
22
+ alias_method :lock_orig, :lock
23
+ end
24
+
25
+ module Mutex_m
26
+ alias_method :mu_lock_orig, :mu_lock
27
+ end
28
+
29
+ module MonitorMixin
30
+ alias_method :mon_enter_orig, :mon_enter
31
+ end
32
+
33
+ module Sync_m
34
+ alias_method :sync_lock_orig, :sync_lock
35
+ end
36
+ CODE_END
37
+
38
+ def enable_synchronizations
39
+ Object.module_eval <<-CODE_END
40
+ class Mutex
41
+ alias_method :lock, :lock_orig
42
+ end
43
+
44
+ module Mutex_m
45
+ alias_method :mu_lock, :mu_lock_orig
46
+ end
47
+
48
+ module MonitorMixin
49
+ alias_method :mon_enter, :mon_enter_orig
50
+ end
51
+
52
+ module Sync_m
53
+ alias_method :sync_lock, :sync_lock_orig
54
+ end
55
+ CODE_END
56
+ end
57
+
58
+ def disable_synchronizations
59
+ Object.module_eval <<-CODE_END
60
+ class Mutex
61
+ def lock
62
+ self
63
+ end
64
+ end
65
+
66
+ module Mutex_m
67
+ def mu_lock
68
+ self
69
+ end
70
+ end
71
+
72
+ module MonitorMixin
73
+ def mon_enter
74
+ self
75
+ end
76
+ end
77
+
78
+ module Sync_m
79
+ def sync_lock(m = EX)
80
+ self
81
+ end
82
+ end
83
+ CODE_END
84
+ end
85
+
86
+ def filter_action(event, file, line, id, classname)
87
+ ['call', 'c-call'].include?(event) && !['threading_test_tools.rb', 'thread.rb', 'thwait.rb', 'mutex_m.rb', 'monitor.rb', 'sync.rb'].include?(File.basename(file))
88
+ end
89
+
90
+ def check_race_condition(options = {}, &test)
91
+ data = options
92
+ data[:test] = test
93
+ analyze_race_condition_test(data)
94
+
95
+ assert_raise RaceConditionFound, 'No race condition could be found (with disabled synchronizations).' do
96
+ begin
97
+ $stdout.print '? R3T: Step 1/2 - Try '
98
+ disable_synchronizations
99
+ perform_race_condition_test(data)
100
+ ensure
101
+ $stdout.print "\b" * 22
102
+ end
103
+ end
104
+
105
+
106
+ assert_nothing_raised 'An unhandled race condition has been found (with enabled synchronizations).' do
107
+ begin
108
+ begin
109
+ $stdout.print '? R3T: Step 2/2 - Try '
110
+ enable_synchronizations
111
+ perform_race_condition_test(data)
112
+ ensure
113
+ $stdout.print "\b" * 22
114
+ end
115
+ rescue RaceConditionFound => e
116
+ if data[:create_ographs]
117
+ require 'ograph'
118
+ File.open('ograph_expected.dot', 'w') { |file| file.write ObjectGraph.graph(data[:expected_variables]) }
119
+ system('dot -Tpng < ograph_expected.dot > ograph_expected.png')
120
+ File.unlink('ograph_expected.dot')
121
+ File.open('ograph_race_condition.dot', 'w') { |file| file.write ObjectGraph.graph(e.result_variables) }
122
+ system('dot -Tpng < ograph_race_condition.dot > ograph_race_condition.png')
123
+ File.unlink('ograph_race_condition.dot')
124
+ end
125
+ raise e
126
+ end
127
+ end
128
+
129
+ ensure
130
+ $stdout.print ' ' * 40, "\b" * 40
131
+ enable_synchronizations
132
+ end
133
+
134
+ def analyze_race_condition_test(data)
135
+ data[:initial_variables] = extract_variables(data[:test])
136
+ actions = []
137
+ begin
138
+ set_trace_func lambda { |event, file, line, id, binding, classname|
139
+ return if !filter_action(event, file, line, id, classname)
140
+ actions << [event, file, line, id, classname]
141
+ }
142
+ data[:test].call
143
+ ensure
144
+ set_trace_func nil
145
+ end
146
+ data[:actions] = actions.uniq
147
+ data[:expected_variables] = extract_variables(data[:test])
148
+ end
149
+
150
+ def perform_race_condition_test(data)
151
+ count = data[:actions].size
152
+ digits = count.to_s.length
153
+ 0.upto(count - 1) do |index|
154
+ begin
155
+ display = sprintf "%#{digits}d/%#{digits}d", index, count
156
+ $stdout.print display
157
+ $stdout.flush
158
+ action = data[:actions][index]
159
+ restore_variables(data[:test], data[:initial_variables])
160
+ begin
161
+ set_trace_func lambda { |event, file, line, id, binding, classname|
162
+ if action == [event, file, line, id, classname]
163
+ Thread.critical = false
164
+ Thread.pass
165
+ Thread.critical = true
166
+ end
167
+ }
168
+ data[:test].call
169
+ result_variables = extract_variables(data[:test])
170
+ ensure
171
+ set_trace_func nil
172
+ end
173
+ message = []
174
+ if not data[:expected_variables].data_equal?(result_variables, message, {}, true)
175
+ raise RaceConditionFound.new("Race condition found when passing to next thread at #{action[1]}:#{action[2]}: #{message.join}", result_variables)
176
+ end
177
+ ensure
178
+ $stdout.print "\b" * display.size
179
+ end
180
+ end
181
+ end
182
+
183
+ def extract_variables(binding)
184
+ variables = {}
185
+ eval('local_variables', binding).each do |name|
186
+ variables[name] = Marshal.load(Marshal.dump(eval(name, binding)))
187
+ end
188
+ variables
189
+ end
190
+
191
+ def restore_variables(binding, variables)
192
+ variables.each do |name, value|
193
+ $variable_value = Marshal.load(Marshal.dump(value))
194
+ eval("#{name} = $variable_value", binding)
195
+ end
196
+ end
197
+
198
+ end
199
+
200
+ class Integer
201
+ def threads(&block)
202
+ threads = []
203
+ self.times do |i|
204
+ threads << Thread.start do
205
+ begin
206
+ Thread.critical = true
207
+ block.call(i)
208
+ ensure
209
+ Thread.critical = false
210
+ end
211
+ end
212
+ end
213
+ threads.map { |thread| thread.value }
214
+ end
215
+ end
216
+
217
+ class Object
218
+ attr_accessor :data_equal_ignore
219
+
220
+ def data_equal?(obj, message = nil, recursive_check = {})
221
+ return true if data_equal_ignore
222
+ if not self.class.data_equal?(obj.class, message, recursive_check)
223
+ !message.nil? and message.unshift '.class'
224
+ return false
225
+ end
226
+ return recursive_check[[self, obj]] if recursive_check.has_key?([self, obj])
227
+ recursive_check[[self, obj]] = true
228
+ self.instance_variables.each do |name|
229
+ if not self.instance_variable_get(name).data_equal?(obj.instance_variable_get(name), message, recursive_check)
230
+ !message.nil? and message.unshift ".#{name}"
231
+ recursive_check[[self, obj]] = false
232
+ return false
233
+ end
234
+ end
235
+ true
236
+ end
237
+ end
238
+
239
+ class Array
240
+ attr_accessor :data_equal_check_order
241
+
242
+ def data_equal?(obj, message = nil, recursive_check = {})
243
+ return true if data_equal_ignore
244
+ if not self.class.data_equal?(obj.class, message, recursive_check)
245
+ !message.nil? and message.unshift '.class'
246
+ return false
247
+ end
248
+ if not self.size.data_equal?(obj.size, message, recursive_check)
249
+ !message.nil? and message.unshift '.size'
250
+ return false
251
+ end
252
+ return recursive_check[[self, obj]] if recursive_check.has_key?([self, obj])
253
+ recursive_check[[self, obj]] = true
254
+ if not data_equal_check_order
255
+ other_indices = (0..(obj.size - 1)).to_a
256
+ self.each do |entry|
257
+ catch :match_found do
258
+ other_indices.each do |other_index|
259
+ if entry.data_equal?(obj[other_index], nil, recursive_check)
260
+ other_indices.delete(other_index)
261
+ throw :match_found
262
+ end
263
+ end
264
+ !message.nil? and message.unshift " has no corresponding entry for #{entry}."
265
+ recursive_check[[self, obj]] = false
266
+ return false
267
+ end
268
+ end
269
+ else
270
+ self.each_index do |index|
271
+ if not self[index].data_equal?(obj[index], message, recursive_check)
272
+ !message.nil? and message.unshift "[#{index}]"
273
+ recursive_check[[self, obj]] = false
274
+ return false
275
+ end
276
+ end
277
+ end
278
+ true
279
+ end
280
+ end
281
+
282
+ class Hash
283
+ def data_equal?(obj, message = nil, recursive_check = {}, no_brackets = false)
284
+ return true if data_equal_ignore
285
+ if not self.class.data_equal?(obj.class, message, recursive_check)
286
+ !message.nil? and message.unshift '.class'
287
+ return false
288
+ end
289
+ if not self.size.data_equal?(obj.size, message, recursive_check)
290
+ !message.nil? and message.unshift '.size'
291
+ return false
292
+ end
293
+ return recursive_check[[self, obj]] if recursive_check.has_key?([self, obj])
294
+ recursive_check[[self, obj]] = true
295
+ other_keys = obj.keys
296
+ self.each do |key, value|
297
+ catch :match_found do
298
+ other_keys.each_index do |index|
299
+ if key.data_equal?(other_keys[index], nil, recursive_check)
300
+ if value.data_equal?(obj[other_keys[index]], message, recursive_check)
301
+ other_keys.delete_at(index)
302
+ throw :match_found
303
+ else
304
+ !message.nil? and message.unshift(no_brackets ? key.to_s : "[#{key.to_s}]")
305
+ recursive_check[[self, obj]] = false
306
+ return false
307
+ end
308
+ end
309
+ end
310
+ !message.nil? and message.unshift " has no corresponding key for #{key.to_s}."
311
+ recursive_check[[self, obj]] = false
312
+ return false
313
+ end
314
+ end
315
+ true
316
+ end
317
+ end
318
+
319
+ %w(Class Date Exception FalseClass Float Integer NilClass Range Regexp String Struct Symbol Time TrueClass).each do |name|
320
+ eval <<-CODE_END
321
+ class #{name}
322
+ def data_equal?(obj, message = nil, recursive_check = {})
323
+ return true if data_equal_ignore
324
+ if not self == obj
325
+ !message.nil? and message.unshift " should be \#{self.to_s}, but was \#{obj.to_s}."
326
+ return false
327
+ end
328
+ true
329
+ end
330
+ end
331
+ CODE_END
332
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: R3T
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-07-24 00:00:00 +02:00
8
+ summary: R3T can help you to find, resolve and monitor race conditions.
9
+ require_paths:
10
+ - lib
11
+ email: mail@richard-musiol.de
12
+ homepage: http://r3t.rubyforge.org/
13
+ rubyforge_project:
14
+ description: Functions for use in unit tests to check for race conditions when using multiple threads. R3T reproducibly detects them by manually controlling the thread scheduler and can also check if synchronizations (Monitor/Mutex/Sync) do their work well.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Richard Musiol
31
+ files:
32
+ - GPL.txt
33
+ - lib/threading_test_tools.rb
34
+ test_files: []
35
+
36
+ rdoc_options: []
37
+
38
+ extra_rdoc_files: []
39
+
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ requirements: []
45
+
46
+ dependencies: []
47
+