4 from random import randint
8 # - Correctly handle errors
9 # - Launch VLC in a separate thread and detect hangs
10 # - Correct path handling
15 def play_mangled( filename, logfile ):
17 vlc_pid = os.spawnvp( os.P_NOWAIT, "./vlc",
18 [ "vlc", "-I", "logger", "--quiet", "--stop-time", "1",
19 filename , "vlc:quit", "--logfile", logfile ])
20 ( exit_pid, exit_status ) = os.waitpid( vlc_pid, 0 )
21 os.chdir( "test/mangle" )
22 l.debug( "VLC exited with status %i" % exit_status )
25 def mangle_file( filename, header_size, percentage , new_file):
26 shutil.copyfile( filename, new_file )
27 file = open ( new_file, "r+" )
28 for i in range( header_size ):
30 if( randint(0, 100/percentage) == 0 ):
31 file.write( "%i" % randint (0, 255 ));
35 def process_file_once( file, header_size ):
36 suffix = randint( 0, 65535 )
37 new_file = conf["temp_folder"] + conf["prefix"] + "%i" % suffix
38 log_file = conf["temp_folder"] + conf["log_prefix"] + "%i" % suffix
40 mangle_file( file, header_size, conf["mangle_ratio"], new_file )
41 status = play_mangled( new_file, log_file )
46 l.info( "Potential crash detected : %i, saving results" % suffix )
48 shutil.move( new_file , conf["crashdir"] )
49 shutil.move( log_file , conf["crashdir"] )
51 l.error( "Unable to move file" )
53 def process_file( file, source, header_size ):
54 l.info( "Starting work on " + file )
56 if( len( glob.glob( conf["inputdir"] + "/" + file ) ) == 0 ):
57 l.warn( "%s does not exist in %s" % (file, conf["inputdir"] ) )
58 if( VLCUtil.downloadFile( file, source, conf["inputdir"], l ) != 0 ):
59 l.error( "Unable to download %s" % file )
62 for i in range( conf["loops"] ):
63 process_file_once( conf["inputdir"] + "/" + file, header_size )
65 l = VLCUtil.getLogger( "Mangle" )
68 conf["inputdir"] = "input"
69 conf["crashdir"] = "crashers"
70 conf["temp_folder"] = "/tmp/"
71 conf["prefix"] = "mangle."
72 conf["log_prefix"] = "vlc-log."
73 conf["mangle_ratio"] = 4 # Change X% of bytes within header
76 l.debug( "Creating folders" )
79 os.makedirs( conf["crashdir"] )
80 os.makedirs( conf["inputdir"] )
81 os.makedirs( conf["temp_folder"] )
87 process_file( "bl.mp4", "ftp://streams.videolan.org/streams-videolan/reference/mp4", 3000 )
88 process_file( "Win98Crash.mov", "ftp://streams.videolan.org/streams-videolan/reference/mov", 3000 )
89 process_file( "x264.avi", "ftp://streams.videolan.org/streams-videolan/reference/avi", 3000 )
90 process_file( "batidadomontoya.wmv", "ftp://streams.videolan.org/streams-videolan/reference/asf", 3000 )
91 process_file( "tarzan.ogm", "ftp://streams.videolan.org/streams-videolan/reference/ogm", 3000 )