#!/usr/bin/perl -w # generate_random_input.pl - Don Yang (uguu.org) # # Create a random editing session and see how homura would respond. # The intent is to see if we can trigger a crash with potentially bad input. use strict; use constant MAX_TIMESTAMPS => 10000; use constant MAX_EVENTS_PER_TIMESTAMP => 3; # Fix the random seed so that we can reproduce the input in case of a crash srand 42; # Return a random string sub RandomString() { my $s = ""; my $length = int(rand(10)) + 1; for(my $k = 0; $k < $length; $k++) { $s .= int(rand(2)); } return $s; } my @lines = (""); my $timestamp = 0; my $frame = 0; for(my $i = 0; $i < MAX_TIMESTAMPS; $i++) { # Output cursor event my $row = int(rand($#lines + 2)) + 1; my $column = int(rand(8)) + 1; print "Y${row}X${column}F${frame}T$timestamp\n"; my $events = int(rand(MAX_EVENTS_PER_TIMESTAMP)); for(my $j = 0; $j < $events; $j++) { my $type = int(rand(5)); $row = int(rand($#lines + 10)); if( $type == 0 ) { # Append $lines[$row] = "" unless defined $lines[$row]; $lines[$row] .= RandomString(); print "L", $row + 1, "E", (scalar @lines), "=", $lines[$row], "\n"; next; } if( $type == 1 && $row <= $#lines ) { # Delete splice @lines, $row, 1; for(my $k = 0; $k <= $#lines; $k++) { my $text = defined($lines[$k]) ? $lines[$k] : ""; print "L", $k + 1, "E", (scalar @lines), "=$text\n"; } next; } # Replace $lines[$row] = RandomString(); print "L", $row + 1, "E", (scalar @lines), "=", $lines[$row], "\n"; } # Update frame, occasionally update timestamp $frame++; $timestamp++ if rand > 0.5; }