mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-23 12:55:44 +03:00
Add torture scripts + standard layout files
This commit is contained in:
parent
0c959e8661
commit
033249423f
4 changed files with 6841 additions and 0 deletions
49
test/scripts/README.rst
Normal file
49
test/scripts/README.rst
Normal file
|
@ -0,0 +1,49 @@
|
|||
Torture for Mirall
|
||||
==================
|
||||
|
||||
This is a set of scripts comprising of two parts:
|
||||
|
||||
* ``torture_gen_layout.pl``: Generation of layout files (random)
|
||||
* ``torture_create_files.pl``: Generation of a real file tree based on the
|
||||
layout files (deterministic)
|
||||
|
||||
These scripts allow to produce a data set with the following criteria:
|
||||
|
||||
* realistic in naming
|
||||
* realistic in file size
|
||||
* realistic in structural size
|
||||
|
||||
without checking in the actual data. Instead, a layout file that gets generated
|
||||
once (reference.lay) is checked in. This makes it possible to produce
|
||||
standardized benchmarks for mirall. It allows allows to check for files gone
|
||||
missing in action and other kinds of corruption produced during sync run.
|
||||
|
||||
``torture_create_files.pl`` can be fine tuned via variables in the script
|
||||
header. It sources its file names from ``dict`` wordlist, file extensions and
|
||||
other parameters can be added as needed. The defaults should be reasonable
|
||||
in terms of size.
|
||||
|
||||
The ``references/`` directory contains default folder layouts.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
In order to create a reference layout and create a tree from it::
|
||||
|
||||
./torture_create_files.pl > reference.lay
|
||||
./torture_gen_layout.pl reference.lay <targetdir>
|
||||
|
||||
|
||||
TODO
|
||||
----
|
||||
|
||||
* Based on the layout file, write a validator that checks files for existence
|
||||
and size without requiring a full reference tree to be created via
|
||||
``./torture_gen_layout.pl``.
|
||||
|
||||
* The current file naming is fairly tame (i.e. almost within ASCII range).
|
||||
Extending it randomly is dangerous, we first need to filter all
|
||||
characters forbidden by various OSes. Or maybe not, because we want to
|
||||
see what happens? :-). Anyway, you have been warned.
|
||||
|
||||
|
6698
test/scripts/references/default.lay
Normal file
6698
test/scripts/references/default.lay
Normal file
File diff suppressed because it is too large
Load diff
23
test/scripts/torture_create_files.pl
Executable file
23
test/scripts/torture_create_files.pl
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use File::Path qw(make_path);
|
||||
use File::Basename qw(dirname);
|
||||
|
||||
if (scalar @ARGV < 2) {
|
||||
print "Usage: $0 input.lay <offsetdir>\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
my ($file, $offset_dir) = @ARGV;
|
||||
|
||||
open FILE, "<", $file or die $!;
|
||||
while (<FILE>) {
|
||||
my ($fillfile, $size) = split(/:/, $_);
|
||||
$fillfile = $offset_dir . '/' . $fillfile;
|
||||
my $dir = dirname $fillfile;
|
||||
if (!-d $dir) { make_path $dir; }
|
||||
open FILLFILE, ">", $fillfile;
|
||||
print "writing $fillfile with $size bytes\n...";
|
||||
print FILLFILE 0x01 x $size;
|
||||
close FILLFILE;
|
||||
}
|
71
test/scripts/torture_gen_layout.pl
Executable file
71
test/scripts/torture_gen_layout.pl
Executable file
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use Data::Random::WordList;
|
||||
|
||||
############################################################################
|
||||
|
||||
# Which extensions to randomly assign
|
||||
my @exts = ('txt', 'pdf', 'html', 'docx', 'xlsx', 'pptx', 'odt', 'ods', 'odp');
|
||||
# Maximum depth of the target structure
|
||||
my $depth = 4;
|
||||
# Maximum amount of subfolders within a folder
|
||||
my $max_subfolder = 10;
|
||||
# Maximum amount of files within a folder
|
||||
my $max_files_per_folder = 100;
|
||||
# Maximum file size
|
||||
my $max_file_size = 1024**2;
|
||||
|
||||
############################################################################
|
||||
|
||||
sub gen_entries($)
|
||||
{
|
||||
my ($count) = @_;
|
||||
my $wl = new Data::Random::WordList( wordlist => '/usr/share/dict/words' );
|
||||
my @rand_words = $wl->get_words($count);
|
||||
foreach(@rand_words) {
|
||||
$_ =~ s/\'//g;
|
||||
}
|
||||
$wl->close();
|
||||
return @rand_words;
|
||||
}
|
||||
|
||||
sub create_subdir($)
|
||||
{
|
||||
my ($depth) = @_;
|
||||
$depth--;
|
||||
my %dir_tree = ( );
|
||||
|
||||
my @dirs = gen_entries(int(rand($max_subfolders)));
|
||||
my @files = gen_entries(int(rand($max_files_per_folder)));
|
||||
|
||||
foreach my $file(@files) {
|
||||
$dir_tree{$file} = int(rand($max_file_size));
|
||||
}
|
||||
|
||||
if ($depth > 0) {
|
||||
foreach my $dir(@dirs) {
|
||||
$dir_tree{$dir} = create_subdir($depth);
|
||||
}
|
||||
}
|
||||
|
||||
return \%dir_tree;
|
||||
}
|
||||
|
||||
sub create_dir_listing(@)
|
||||
{
|
||||
my ($tree, $prefix) = @_;
|
||||
foreach my $key(keys %$tree) {
|
||||
my $entry = $tree->{$key};
|
||||
#print "$entry:".scalar $entry.":".ref $entry."\n";
|
||||
if (ref $entry eq "HASH") {
|
||||
create_dir_listing($tree->{$key}, "$prefix/$key");
|
||||
} else {
|
||||
my $ext = @exts[rand @exts];
|
||||
print "$prefix/$key.$ext:$entry\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
srand();
|
||||
my $dir = create_subdir($depth);
|
||||
create_dir_listing($dir, '.');
|
Loading…
Reference in a new issue