Torture test for Nautilus



Hi,

Along with the logging patch I sent, I'm now using a little torture test
for file operations (attached).  This simply creates a directory and
does stuff in it:  create files, write to them, create directories,
delete files, move files, etc.

You run the torture like this:

  python file-torture.py -o ~/torture

Some immediately interesting things:

- Nautilus doesn't survive very long if made to display the ~/torture
directory :)  There are some assertion failures and some "real" crashes.

- gnome-vfs-monitor performs very badly.  For a torture directory with
only 400 files in it, gnome-vfs-monitor already had a list of callbacks
with over 12,000 elements.  It spent all its time in g_list_append() and
in get_min_delay(), apparently freezing the GUI.

It is my hope that fixing these bugs will take care of many of the
"irreproducible" bugs about file browsing that people have been sending.

The torture program supports a "--seed" option that you can use to seed
the random number generator.  This is so that the sequence of "random"
torture steps will be reproducible.

  Federico
#!/usr/bin/env python
import random
import os
import sys
import optparse

output_dir = ""
random_gen = None

extensions = (".doc", ".gif", ".jpg", ".png", ".xls", ".odt", ".odp", ".ods", ".txt", ".zip", ".gz")

files = []
directories = []

def get_random_file_index ():
    n = len (files)
    if n == 0:
        return -1
    else:
        return random_gen.randrange (n)

def get_random_directory_index ():
    n = len (directories)
    if n == 0:
        return -1
    else:
        return random_gen.randrange (n)

def get_random_filename ():
    chars = []
    for i in range (20):
        chars.append ("abcdefghijklmnopqrstuvwxyz"[random_gen.randrange (26)])

    extension = extensions[random_gen.randrange (len (extensions))]
    filename = "".join (chars) + extension
    return filename

def get_random_path ():
    return os.path.join (output_dir, get_random_filename ())

def op_create_file ():
    filename = get_random_path ()
    files.append (filename)
    f = open (filename, "w")
    f.close ()

def op_move_file ():
    idx = get_random_file_index ()
    if idx == -1:
        return

    new_name = get_random_path ()
    old_name = files[idx]
    os.rename (old_name, new_name)
    files[idx] = new_name

def op_delete_file ():
    idx = get_random_file_index ()
    if idx == -1:
        return

    os.unlink (files[idx])
    files.pop (idx)

def op_write_file ():
    idx = get_random_file_index ()
    if idx == -1:
        return

    name = files[idx]
    f = open (name, "a")
    f.write ("blah blah blah blah blah blah blah\n")
    f.close ()

def op_create_dir ():
    name = get_random_path ()
    os.mkdir (name)
    directories.append (name)

def op_move_dir ():
    idx = get_random_directory_index ()
    if idx == -1:
        return

    new_name = get_random_path ()
    old_name = directories[idx]
    os.rename (old_name, new_name)
    directories[idx] = new_name

def op_delete_dir ():
    idx = get_random_directory_index ()
    if idx == -1:
        return

    os.rmdir (directories[idx])
    directories.pop (idx)

def op_file_to_dir ():
    idx = get_random_file_index ()
    if idx == -1:
        return

    name = files[idx]
    os.unlink (name)
    files.pop (idx)
    os.mkdir (name)
    directories.append (name)

def op_dir_to_file ():
    idx = get_random_directory_index ()
    if idx == -1:
        return

    name = directories[idx]
    os.rmdir (name)
    directories.pop (idx)
    f = open (name, "w")
    f.close ()
    files.append (name)

operations = (
    op_create_file,
    op_move_file,
    op_delete_file,
    op_write_file,
    op_create_dir,
    op_move_dir,
    op_delete_dir,
    op_file_to_dir,
    op_dir_to_file,
    )

def main ():
    option_parser = optparse.OptionParser (usage="usage: %prog -o <dirname>")
    option_parser.add_option ("-o",
                              "--output", dest="output",
                              metavar="FILE",
                              help="Name of output directory")
    option_parser.add_option ("-s",
                              "--seed", dest="seed",
                              metavar="NUMBER",
                              help="Random number seed")

    (options, args) = option_parser.parse_args ()

    if not options.output:
        print 'Please specify an output directory with "-o outputdir"'
        return 1

    if len (args) != 0:
        print 'No extra arguments are supported'
        return 1

    global output_dir
    global random_gen

    random_gen = random.Random ()
    if options.seed:
        random_gen.seed (int (options.seed))

    output_dir = options.output
    try:
        os.mkdir (output_dir)
    except:
        1 # nothing

    while True:
        op = operations [random_gen.randrange (len (operations))]
        op ()

    return 0

if __name__ == "__main__":
    sys.exit (main ())


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]