Skip to content

Commit

Permalink
--strict_fields option V1 for runall/gendata/gentest added
Browse files Browse the repository at this point in the history
  • Loading branch information
berntm committed Nov 15, 2011
1 parent cc63e30 commit fe61226
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
6 changes: 4 additions & 2 deletions gendata.pl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use Getopt::Long;

my ($spec_file, $config_file, $debug, $engine, $help, $dsn, $rows, $varchar_len,
$views, $server_id, $seed, $short_column_names, $notnull);
$views, $server_id, $seed, $short_column_names, $notnull, $strict_fields);

my $opt_result = GetOptions(
'help' => \$help,
Expand All @@ -43,7 +43,8 @@
'varchar-length=i' => \$varchar_len,
'server-id=i' > \$server_id,
'notnull' => \$notnull,
'short_column_names' => \$short_column_names
'short_column_names' => \$short_column_names,
'strict_fields' => \$strict_fields
);

if (defined $config_file) {
Expand All @@ -66,6 +67,7 @@
varchar_length => $varchar_len,
server_id => $server_id,
notnull => $notnull,
strict_fields => $strict_fields,
short_column_names => $short_column_names);


Expand Down
2 changes: 2 additions & 0 deletions gentest.pl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
'valgrind-xml',
'notnull',
'short_column_names',
'strict_fields',
'debug',
'logfile=s',
'logconf=s',
Expand Down Expand Up @@ -131,6 +132,7 @@
'sqltrace',
'notnull',
'short_column_names',
'strict_fields',
'logfile',
'logconf',
'report-tt-logdir',
Expand Down
3 changes: 2 additions & 1 deletion lib/GenTest/App/GenTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ sub run {
views => $self->config->views,
varchar_length => $self->config->property('varchar-length'),
sqltrace => $self->config->sqltrace,
short_column_names=> $self->config->short_column_names,
short_column_names => $self->config->short_column_names,
strict_fields => $self->config->strict_fields,
notnull => $self->config->notnull);
}
$gendata_result = $datagen->run();
Expand Down
40 changes: 29 additions & 11 deletions lib/GenTest/App/Gendata.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use constant FIELD_AUTO_INCREMENT => 6;
use constant FIELD_SQL => 7;
use constant FIELD_INDEX_SQL => 8;
use constant FIELD_NAME => 9;
use constant FIELD_DEFAULT => 10;

use constant TABLE_ROW => 0;
use constant TABLE_ENGINE => 1;
Expand Down Expand Up @@ -72,6 +73,7 @@ use constant GD_SERVER_ID => 8;
use constant GD_SQLTRACE => 9;
use constant GD_NOTNULL => 10;
use constant GD_SHORT_COLUMN_NAMES => 11;
use constant GD_STRICT_FIELDS => 12;

sub new {
my $class = shift;
Expand All @@ -87,6 +89,7 @@ sub new {
'varchar_length' => GD_VARCHAR_LENGTH,
'notnull' => GD_NOTNULL,
'short_column_names' => GD_SHORT_COLUMN_NAMES,
'strict_fields' => GD_STRICT_FIELDS,
'server_id' => GD_SERVER_ID,
'sqltrace' => GD_SQLTRACE},@_);

Expand Down Expand Up @@ -154,6 +157,11 @@ sub short_column_names {
}


sub strict_fields {
return $_[0]->[GD_STRICT_FIELDS];
}


sub run {
my ($self) = @_;

Expand Down Expand Up @@ -219,12 +227,22 @@ sub run {
croak "Dates and times are severly broken. Cannot be used for other than MySQL/Drizzle";
}
}
$field_perms[FIELD_NULLABILITY] = $fields->{null} || $fields->{nullability} || [ (defined $self->[GD_NOTNULL] ? 'NOT NULL' : undef) ];
$field_perms[FIELD_SIGN] = $fields->{sign} || [ undef ];
$field_perms[FIELD_INDEX] = $fields->{indexes} || $fields->{keys} || [ undef, 'KEY' ];
$field_perms[FIELD_CHARSET] = $fields->{charsets} || [ undef ];
$field_perms[FIELD_COLLATION] = $fields->{collations} || [ undef ];
if ($self->strict_fields) {
$field_perms[FIELD_NULLABILITY] = $fields->{null} || $fields->{nullability} || [ undef ];
$field_perms[FIELD_DEFAULT] = $fields->{default} || [ undef ];
$field_perms[FIELD_SIGN] = $fields->{sign} || [ undef ];
$field_perms[FIELD_INDEX] = $fields->{indexes} || $fields->{keys} || [ undef ];
$field_perms[FIELD_CHARSET] = $fields->{charsets} || [ undef ];
$field_perms[FIELD_COLLATION] = $fields->{collations} || [ undef ];
} else {
$field_perms[FIELD_NULLABILITY] = $fields->{null} || $fields->{nullability} || [ (defined $self->[GD_NOTNULL] ? 'NOT NULL' : undef) ];
$field_perms[FIELD_SIGN] = $fields->{sign} || [ undef ];
$field_perms[FIELD_INDEX] = $fields->{indexes} || $fields->{keys} || [ undef, 'KEY' ];
$field_perms[FIELD_CHARSET] = $fields->{charsets} || [ undef ];
$field_perms[FIELD_COLLATION] = $fields->{collations} || [ undef ];
}


$data_perms[DATA_NUMBER] = $data->{numbers} || ['digit', 'digit', 'digit', 'digit', (defined $self->[GD_NOTNULL] ? 'digit' : 'null') ]; # 20% NULL values
$data_perms[DATA_STRING] = $data->{strings} || ['letter', 'letter', 'letter', 'letter', (defined $self->[GD_NOTNULL] ? 'letter' : 'null') ];
$data_perms[DATA_BLOB] = $data->{blobs} || [ 'data', 'data', 'data', 'data', (defined $self->[GD_NOTNULL] ? 'data' : 'null') ];
Expand Down Expand Up @@ -260,7 +278,7 @@ sub run {

my @fields = (undef);

foreach my $cycle (FIELD_TYPE, FIELD_NULLABILITY, FIELD_SIGN, FIELD_INDEX, FIELD_CHARSET, FIELD_COLLATION) {
foreach my $cycle (FIELD_TYPE, FIELD_NULLABILITY, FIELD_DEFAULT, FIELD_SIGN, FIELD_INDEX, FIELD_CHARSET, FIELD_COLLATION) {
@fields = map {
my $old_field = $_;
if (not defined $field_perms[$cycle]) {
Expand Down Expand Up @@ -298,7 +316,7 @@ sub run {
# $field_copy[FIELD_INDEX] = 'nokey' if $field_copy[FIELD_INDEX] eq '';

my $field_name;
if ($self->[GD_SHORT_COLUMN_NAMES]) {
if ($self->short_column_names) {
$field_name = 'c'.($field_no++);
} else {
$field_name = "col_".join('_', grep { $_ ne '' } @field_copy);
Expand Down Expand Up @@ -347,11 +365,11 @@ sub run {

$fields[$field_id]->[FIELD_SQL] = "`$field_name` ". join(' ' , grep { $_ ne '' } @field_copy);

if ($field_copy[FIELD_TYPE] =~ m{timestamp}sio ) {
if (defined $self->[GD_NOTNULL]) {
$field->[FIELD_SQL] .= ' NOT NULL';
if (!$self->strict_fields && $field_copy[FIELD_TYPE] =~ m{timestamp}sio ) {
if (defined $self->[GD_NOTNULL]) {
$field->[FIELD_SQL] .= ' NOT NULL';
} else {
$field->[FIELD_SQL] .= ' NULL DEFAULT 0';
$field->[FIELD_SQL] .= ' NULL DEFAULT 0';
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion runall-new.pl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
$start_dirty, $filter, $build_thread, $sqltrace, $testname,
$report_xml_tt, $report_xml_tt_type, $report_xml_tt_dest,
$notnull, $logfile, $logconf, $report_tt_logdir, $querytimeout, $no_mask,
$short_column_names);
$short_column_names, $strict_fields);

my $gendata=''; ## default simple gendata

Expand Down Expand Up @@ -106,6 +106,7 @@
'gendata:s' => \$gendata,
'notnull' => \$notnull,
'short_column_names' => \$short_column_names,
'strict_fields' => \$strict_fields,
'seed=s' => \$seed,
'mask=i' => \$mask,
'mask-level=i' => \$mask_level,
Expand Down Expand Up @@ -385,6 +386,7 @@
'filter',
'notnull',
'short_column_names',
'strict_fields',
'valgrind',
'valgrind-xml',
'testname',
Expand Down Expand Up @@ -441,6 +443,7 @@
$gentestProps->filter($filter) if defined $filter;
$gentestProps->notnull($notnull) if defined $notnull;
$gentestProps->short_coulmn_names($short_column_names) if defined $short_column_names;
$gentestProps->strict_fields($strict_fields) if defined $strict_fields;
$gentestProps->valgrind(1) if $valgrind;
$gentestProps->sqltrace($sqltrace) if $sqltrace;
$gentestProps->querytimeout($querytimeout) if defined $querytimeout;
Expand Down
4 changes: 3 additions & 1 deletion runall.pl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
$start_dirty, $filter, $build_thread, $testname, $report_xml_tt,
$report_xml_tt_type, $report_xml_tt_dest, $notnull, $sqltrace,
$lcov, $transformers, $logfile, $logconf, $report_tt_logdir,$querytimeout,
$short_column_names);
$short_column_names, $strict_fields);

my $threads = my $default_threads = 10;
my $queries = my $default_queries = 1000;
Expand Down Expand Up @@ -106,6 +106,7 @@
'skip-gendata' => \$skip_gendata,
'notnull' => \$notnull,
'short_column_names' => \$short_column_names,
'strict_fields' => \$strict_fields,
'seed=s' => \$seed,
'mask=i' => \$mask,
'mask-level=i' => \$mask_level,
Expand Down Expand Up @@ -420,6 +421,7 @@
push @gentest_options, "--gendata=$gendata" if not defined $skip_gendata;
push @gentest_options, "--notnull" if defined $notnull;
push @gentest_options, "--short_column_names" if defined $short_column_names;
push @gentest_options, "--strict_fields" if defined $strict_fields;
push @gentest_options, "--engine=$engine" if defined $engine;
push @gentest_options, "--rpl_mode=$rpl_mode" if defined $rpl_mode;
push @gentest_options, map {'--validator='.$_} split(/,/,$validators) if defined $validators;
Expand Down

0 comments on commit fe61226

Please sign in to comment.