node/reduction.rb
def reduction( pass )
		
		return false if pass > 4
		
		@current_pass = pass
		
		case @current_pass
			when 1

				p = [
					::Proc.new do
						@opts['print_message_comments']  = false

						@opts['uncomment_code_comments'] = @opts['print_code_comments'] = false
					end,
					::Proc.new do
						@opts['uncomment_code_comments'] = @opts['print_code_comments'] = true
					end,
					::Proc.new do
						@opts['uncomment_code_comments'] = @opts['print_code_comments'] = false
						
						line = ''
						@xmlcrashlog.generate_elems( @opts ).each do | elem |
							line << "try { tickle( #{elem} ); } catch(e){}\n" # some of these elems might not exist later on (due to @skip_elems) but we wont know yet (hence try/catch).
						end
						
						@opts['testcase_append_function'] = line << @opts['testcase_append_function']						
					end,
					::Proc.new do
						@opts['uncomment_code_comments'] = @opts['print_code_comments'] = true
						
						# XXX: @opts['testcase_append_function'] will already include the element tickle stuff from above.
						
						#line = ''
						#@xmlcrashlog.generate_elems( @opts ).each do | elem |
						#	line << "tickle( #{elem} );\n"
						#end
						#@opts['testcase_append_function'] = line << @opts['testcase_append_function']
					end
				]
				
				p.reverse!
				
				@genopts = SkipAndKeepItems.new( p )
				
				print_status( "Performing pass 1: Initial verification." )
			when 2
				
				@elems = SkipAndKeepItems.new( @xmlcrashlog.generate_elems( @opts ) )

				print_status( "Performing pass 2: Reducing elements (#{@elems.keeping.length} elements's)." )
			when 3

				@idxs = SkipAndKeepItems.new( @xmlcrashlog.generate_idxs( @opts, @elems.skipping ) )

				print_status( "Performing pass 3: Reducing idx's (#{@idxs.keeping.length} idx's)." )
			when 4
				print_status( "Performing pass 4: Final verification." )
		end
		
		if( @current_pass == 2 and @elems.keeping.length == 1 )
			success = true
		else
			# spin up a server to serve out the html testcase
			@reduction_server = Grinder::Core::Server.new( $server_address, $server_port, @browser_type, nil, self )
			
			@reduction_server.start

			# start a browser instance to visit /testcase_generate
			spawn_browser

			@reduction_server.wait
			
			kill_browser
			
			success = true
		end
		
		# print pass results (like above)
		case @current_pass
			when 1
				success = ( not @crash_hashes.empty? )
				if( success )
					print_status( "Finished pass 1: Successfully performed the initial verification." )
				else
					print_error( "Finished pass 1: Couldn't trigger a crash." )
				end
			when 2
				print_status( "Finished pass 2: Reduced elements to #{@elems.keeping.length}." )
			when 3
				print_status( "Finished pass 3: Reduced idx's to #{@idxs.keeping.length}." )
			when 4
				print_status( "Finished pass 4: Final verification." )
		end
		
		return success
	end
# pass 1: initial verification (find out if we can cause a crash, do we need to enable code comments, do we need to tickle?)
# pass 2: skip elements (find what elements we can skip to still cause a crash)
# pass 3: skip idxs (find out what idxs we can remove to still generate a crash)
# pass 4: final verification (finally verify the end result still generates a crash)
pass 1: initial verification (find out if we can cause a crash, do we need to enable code comments, do we need to tickle?)
pass 2: skip elements (find what elements we can skip to still cause a crash)
pass 3: skip idxs (find out what idxs we can remove to still generate a crash)
pass 4: final verification (finally verify the end result still generates a crash)
pass 1 : initial verification ( find out if we can cause a crash do we need to enable code comments do we need to tickle? ) pass 2 : skip elements ( find what elements we can skip to still cause a crash ) pass 3 : skip idxs ( find out what idxs we can remove to still generate a crash ) pass 4 : final verification ( finally verify the end result still generates a crash )
def reduction( pass )
		return false if pass > 4
		@current_pass = pass
		case @current_pass
			when 1
				p = [
					::Proc.new do
						@opts['print_message_comments']  = false
						@opts['uncomment_code_comments'] = @opts['print_code_comments'] = false
					end,
					::Proc.new do
						@opts['uncomment_code_comments'] = @opts['print_code_comments'] = true
					end,
					::Proc.new do
						@opts['uncomment_code_comments'] = @opts['print_code_comments'] = false
						line = ''
						@xmlcrashlog.generate_elems( @opts ).each do | elem |
							line << "try { tickle( #{elem} ); } catch(e){}\n" 
						end
						@opts['testcase_append_function'] = line << @opts['testcase_append_function']						
					end,
					::Proc.new do
						@opts['uncomment_code_comments'] = @opts['print_code_comments'] = true
					end
				]
				p.reverse!
				@genopts = SkipAndKeepItems.new( p )
				print_status( "Performing pass 1: Initial verification." )
			when 2
				@elems = SkipAndKeepItems.new( @xmlcrashlog.generate_elems( @opts ) )
				print_status( "Performing pass 2: Reducing elements (#{@elems.keeping.length} elements's)." )
			when 3
				@idxs = SkipAndKeepItems.new( @xmlcrashlog.generate_idxs( @opts, @elems.skipping ) )
				print_status( "Performing pass 3: Reducing idx's (#{@idxs.keeping.length} idx's)." )
			when 4
				print_status( "Performing pass 4: Final verification." )
		end
		if( @current_pass == 2 and @elems.keeping.length == 1 )
			success = true
		else
			@reduction_server = Grinder::Core::Server.new( $server_address, $server_port, @browser_type, nil, self )
			@reduction_server.start
			spawn_browser
			@reduction_server.wait
			kill_browser
			success = true
		end
		case @current_pass
			when 1
				success = ( not @crash_hashes.empty? )
				if( success )
					print_status( "Finished pass 1: Successfully performed the initial verification." )
				else
					print_error( "Finished pass 1: Couldn't trigger a crash." )
				end
			when 2
				print_status( "Finished pass 2: Reduced elements to #{@elems.keeping.length}." )
			when 3
				print_status( "Finished pass 3: Reduced idx's to #{@idxs.keeping.length}." )
			when 4
				print_status( "Finished pass 4: Final verification." )
		end
		return success
	end
def reduction ( pass ) return false if pass > 4 @current_pass = pass case @current_pass when 1 p = [ :: Proc . new do @opts [ 'print_message_comments' ] = false @opts [ 'uncomment_code_comments' ] = @opts [ 'print_code_comments' ] = false end , :: Proc . new do @opts [ 'uncomment_code_comments' ] = @opts [ 'print_code_comments' ] = true end , :: Proc . new do @opts [ 'uncomment_code_comments' ] = @opts [ 'print_code_comments' ] = false line = '' @xmlcrashlog . generate_elems ( @opts ) . each do | elem | line << "try { tickle( #{elem} ); } catch(e){}\n" end @opts [ 'testcase_append_function' ] = line << @opts [ 'testcase_append_function' ] end , :: Proc . new do @opts [ 'uncomment_code_comments' ] = @opts [ 'print_code_comments' ] = true end ] p . reverse! @genopts = SkipAndKeepItems . new ( p ) print_status ( "Performing pass 1: Initial verification." ) when 2 @elems = SkipAndKeepItems . new ( @xmlcrashlog . generate_elems ( @opts ) ) print_status ( "Performing pass 2: Reducing elements (#{@elems.keeping.length} elements's)." ) when 3 @idxs = SkipAndKeepItems . new ( @xmlcrashlog . generate_idxs ( @opts , @elems . skipping ) ) print_status ( "Performing pass 3: Reducing idx's (#{@idxs.keeping.length} idx's)." ) when 4 print_status ( "Performing pass 4: Final verification." ) end if ( @current_pass == 2 and @elems . keeping . length == 1 ) success = true else @reduction_server = Grinder :: Core :: Server . new ( $server_address , $server_port , @browser_type , nil , self ) @reduction_server . start spawn_browser @reduction_server . wait kill_browser success = true end case @current_pass when 1 success = ( not @crash_hashes . empty? ) if ( success ) print_status ( "Finished pass 1: Successfully performed the initial verification." ) else print_error ( "Finished pass 1: Couldn't trigger a crash." ) end when 2 print_status ( "Finished pass 2: Reduced elements to #{@elems.keeping.length}." ) when 3 print_status ( "Finished pass 3: Reduced idx's to #{@idxs.keeping.length}." ) when 4 print_status ( "Finished pass 4: Final verification." ) end return success end
pass 1: initial verification (find out if we can cause a crash, do we need to enable code comments, do we need to tickle?)
pass 1 : initial verification ( find out if we can cause a crash do we need to enable code comments do we need to tickle? )
# some of these elems might not exist later on (due to @skip_elems) but we wont know yet (hence try/catch). # XXX: @opts['testcase_append_function'] will already include the element tickle stuff from above. #line = '' #@xmlcrashlog.generate_elems( @opts ).each do | elem | #	line << "tickle( #{elem} );\n" #end #@opts['testcase_append_function'] = line << @opts['testcase_append_function'] # spin up a server to serve out the html testcase # start a browser instance to visit /testcase_generate # print pass results (like above)
pass