/ Check-in [961e79da]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add test script ext/rbu/rbu_round_trip.tcl. Uses "dbselftest" to test that "rbu" and "sqldiff" work together.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 961e79da73b4550b3e5b0f9a617133a76485db67
User & Date: dan 2017-03-07 20:03:25
Context
2017-03-08
11:44
Add the --preserve-rowids option to the ".dump" command in the CLI. check-in: c60aee24 user: drh tags: trunk
2017-03-07
20:03
Add test script ext/rbu/rbu_round_trip.tcl. Uses "dbselftest" to test that "rbu" and "sqldiff" work together. check-in: 961e79da user: dan tags: trunk
14:38
Performance optimization in the tokenizer/parser loop. check-in: 2cb71583 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added ext/rbu/rbu_round_trip.tcl.

            1  +##########################################################################
            2  +# 2016 Mar 8
            3  +#
            4  +# The author disclaims copyright to this source code.  In place of
            5  +# a legal notice, here is a blessing:
            6  +#
            7  +#    May you do good and not evil.
            8  +#    May you find forgiveness for yourself and forgive others.
            9  +#    May you share freely, never taking more than you give.
           10  +#
           11  +proc process_cmdline {} { 
           12  +  cmdline::process ::A $::argv {
           13  +    {make                 "try to build missing tools"}
           14  +    {verbose              "make more noise"}
           15  +    database
           16  +    database2
           17  +  } {
           18  + This script uses/tests the following tools:
           19  +
           20  +   dbselftest
           21  +   rbu
           22  +   sqldiff
           23  +   sqlite3
           24  + 
           25  + The user passes the names of two database files - a.db and b.db below - as
           26  + arguments. This program:
           27  +
           28  + 1. Runs [dbselftest --init] against both databases.
           29  + 2. Runs [sqldiff --rbu --vtab a.db b.db | sqlite3 <tmpname>.db] to create an 
           30  +    RBU database.
           31  + 3. Runs [rbu b.db <tmpname>.db] to patch b.db to a.db.
           32  + 4. Runs [sqldiff --table selftest a.db b.db] to check that the selftest
           33  +    tables are now identical.
           34  + 5. Runs [dbselftest] against both databases.
           35  +  }
           36  +}
           37  +
           38  +###########################################################################
           39  +###########################################################################
           40  +# Command line options processor. This is generic code that can be copied
           41  +# between scripts.
           42  +#
           43  +namespace eval cmdline {
           44  +  proc cmdline_error {O E {msg ""}} {
           45  +    if {$msg != ""} {
           46  +      puts stderr "Error: $msg"
           47  +      puts stderr ""
           48  +    }
           49  +  
           50  +    set L [list]
           51  +    foreach o $O {
           52  +      if {[llength $o]==1} {
           53  +        lappend L [string toupper $o]
           54  +      }
           55  +    }
           56  +  
           57  +    puts stderr "Usage: $::argv0 ?SWITCHES? $L"
           58  +    puts stderr ""
           59  +    puts stderr "Switches are:"
           60  +    foreach o $O {
           61  +      if {[llength $o]==3} {
           62  +        foreach {a b c} $o {}
           63  +        puts stderr [format "    -%-15s %s (default \"%s\")" "$a VAL" $c $b]
           64  +      } elseif {[llength $o]==2} {
           65  +        foreach {a b} $o {}
           66  +        puts stderr [format "    -%-15s %s" $a $b]
           67  +      }
           68  +    }
           69  +    puts stderr ""
           70  +    puts stderr $E
           71  +    exit -1
           72  +  }
           73  +  
           74  +  proc process {avar lArgs O E} {
           75  +    upvar $avar A
           76  +    set zTrailing ""       ;# True if ... is present in $O
           77  +    set lPosargs [list]
           78  +  
           79  +    # Populate A() with default values. Also, for each switch in the command
           80  +    # line spec, set an entry in the idx() array as follows:
           81  +    #
           82  +    #  {tblname t1 "table name to use"}  
           83  +    #      -> [set idx(-tblname) {tblname t1 "table name to use"}  
           84  +    #
           85  +    # For each position parameter, append its name to $lPosargs. If the ...
           86  +    # specifier is present, set $zTrailing to the name of the prefix.
           87  +    #
           88  +    foreach o $O {
           89  +      set nm [lindex $o 0]
           90  +      set nArg [llength $o]
           91  +      switch -- $nArg {
           92  +        1 {
           93  +          if {[string range $nm end-2 end]=="..."} {
           94  +            set zTrailing [string range $nm 0 end-3]
           95  +          } else {
           96  +            lappend lPosargs $nm
           97  +          }
           98  +        }
           99  +        2 {
          100  +          set A($nm) 0
          101  +          set idx(-$nm) $o
          102  +        }
          103  +        3 {
          104  +          set A($nm) [lindex $o 1]
          105  +          set idx(-$nm) $o
          106  +        }
          107  +        default {
          108  +          error "Error in command line specification"
          109  +        }
          110  +      }
          111  +    }
          112  +  
          113  +    # Set explicitly specified option values
          114  +    #
          115  +    set nArg [llength $lArgs]
          116  +    for {set i 0} {$i < $nArg} {incr i} {
          117  +      set opt [lindex $lArgs $i]
          118  +      if {[string range $opt 0 0]!="-" || $opt=="--"} break
          119  +      set c [array names idx "${opt}*"]
          120  +      if {[llength $c]==0} { cmdline_error $O $E "Unrecognized option: $opt"}
          121  +      if {[llength $c]>1}  { cmdline_error $O $E "Ambiguous option: $opt"}
          122  +  
          123  +      if {[llength $idx($c)]==3} {
          124  +        if {$i==[llength $lArgs]-1} {
          125  +          cmdline_error $O $E "Option requires argument: $c" 
          126  +        }
          127  +        incr i
          128  +        set A([lindex $idx($c) 0]) [lindex $lArgs $i]
          129  +      } else {
          130  +        set A([lindex $idx($c) 0]) 1
          131  +      }
          132  +    }
          133  +  
          134  +    # Deal with position arguments.
          135  +    #
          136  +    set nPosarg [llength $lPosargs]
          137  +    set nRem [expr $nArg - $i]
          138  +    if {$nRem < $nPosarg || ($zTrailing=="" && $nRem > $nPosarg)} {
          139  +      cmdline_error $O $E
          140  +    }
          141  +    for {set j 0} {$j < $nPosarg} {incr j} {
          142  +      set A([lindex $lPosargs $j]) [lindex $lArgs [expr $j+$i]]
          143  +    }
          144  +    if {$zTrailing!=""} {
          145  +      set A($zTrailing) [lrange $lArgs [expr $j+$i] end]
          146  +    }
          147  +  }
          148  +} ;# namespace eval cmdline
          149  +# End of command line options processor.
          150  +###########################################################################
          151  +###########################################################################
          152  +
          153  +process_cmdline
          154  +
          155  +# Check that the specified tool is present.
          156  +#
          157  +proc check_for_tool {tool} {
          158  +  if {[file exists $tool]==0 || [file executable $tool]==0} {
          159  +    puts stderr "Missing $tool... exiting. (run \[make $tool\])"
          160  +    exit -1
          161  +  }
          162  +}
          163  +
          164  +if {$A(make)} {
          165  +  if {$A(verbose)} { puts "building tools..." }
          166  +  exec make dbselftest rbu sqlite3 sqldiff
          167  +}
          168  +
          169  +check_for_tool dbselftest
          170  +check_for_tool rbu
          171  +check_for_tool sqlite3
          172  +check_for_tool sqldiff
          173  +
          174  +exec ./sqlite3 $A(database) "DROP TABLE selftest;"
          175  +exec ./sqlite3 $A(database2) "DROP TABLE selftest;"
          176  +
          177  +# Run [dbselftest --init] on both databases
          178  +if {$A(verbose)} { puts "Running \[dbselftest --init\]" }
          179  +exec ./dbselftest --init $A(database)
          180  +exec ./dbselftest --init $A(database2)
          181  +
          182  +# Create an RBU patch.
          183  +set tmpname "./rrt-[format %x [expr int(rand()*0x7FFFFFFF)]].db"
          184  +if {$A(verbose)} { puts "rbu database is $tmpname" }
          185  +exec ./sqldiff --rbu --vtab $A(database2) $A(database) | ./sqlite3 $tmpname
          186  +
          187  +# Run the [rbu] patch.
          188  +if {$A(verbose)} { puts "Running \[rbu]" }
          189  +exec ./rbu $A(database2) $tmpname
          190  +
          191  +set selftest_diff [exec ./sqldiff --table selftest $A(database) $A(database2)]
          192  +if {$selftest_diff != ""} {
          193  +  puts stderr "patching table \"selftest\" failed: $selftest_diff"
          194  +  exit -1
          195  +}
          196  +
          197  +# Run [dbselftest] on both databases
          198  +if {$A(verbose)} { puts "Running \[dbselftest]" }
          199  +exec ./dbselftest $A(database)
          200  +exec ./dbselftest $A(database2)
          201  +
          202  +# Remove the RBU database
          203  +file delete $tmpname
          204  +puts "round trip test successful."
          205  +