~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/randgen/gengrammar.pl

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# Copyright (C) 2009 Sun Microsystems, Inc. All rights reserved.  Use
 
4
# is subject to license terms.
 
5
#
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; version 2 of the License.
 
9
#
 
10
# This program is distributed in the hope that it will be useful, but
 
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
13
# General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 
18
# USA
 
19
 
 
20
use lib 'lib';
 
21
use lib "$ENV{RQG_HOME}/lib";
 
22
use strict;
 
23
 
 
24
use GenTest;
 
25
use GenTest::Constants;
 
26
use GenTest::Grammar;
 
27
 
 
28
use Getopt::Long;
 
29
 
 
30
$| = 1;
 
31
 
 
32
my ($grammar_file, $mask, $mask_level, $thread_id, $help);
 
33
 
 
34
my @ARGV_saved = @ARGV;
 
35
 
 
36
my $opt_result = GetOptions(
 
37
        'grammar=s' => \$grammar_file,
 
38
        'mask=i' => \$mask,
 
39
        'mask-level=i' => \$mask_level,
 
40
        'thread-id=i' => \$thread_id
 
41
);
 
42
 
 
43
help() if !$opt_result || $help || not defined $grammar_file;
 
44
 
 
45
my $grammar = GenTest::Grammar->new( grammar_file => $grammar_file );
 
46
 
 
47
my $top_grammar = ($mask_level > 0) ? $grammar->topGrammar($mask_level, "thread".$thread_id, "query") : $grammar;
 
48
 
 
49
if ($mask > 0) {
 
50
        my $masked_grammar = $top_grammar->mask($mask);
 
51
        $grammar = $grammar->patch($masked_grammar);
 
52
}
 
53
 
 
54
print $grammar->toString();
 
55
 
 
56
exit(0);
 
57
 
 
58
sub help {
 
59
        print <<EOF
 
60
$0 - Dump a grammar after applying masking
 
61
 
 
62
        --grammar   : Grammar file to use for generating the queries (REQUIRED);
 
63
        --mask      : A seed to a random mask used to mask (reeduce) the grammar.
 
64
        --mask-level: How many levels deep the mask is applied (default 1)
 
65
        --help      : This help message
 
66
EOF
 
67
        ;
 
68
        exit(1);
 
69
}
 
70