Changeset 2031 for trunk/tester


Ignore:
Timestamp:
Jan 14, 2011 8:07:13 AM (9 years ago)
Author:
braffert
Message:

Regression tester: refactoring so that the test class contains references to the relevant library objects. Cuts down on the number of times that new library objects are created. Also, keep a persistent resultspage widget rather than destroying and recreating upon new selection. Beginning to work on inputs tab.

Location:
trunk/tester
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/tester/example/tests/test3.xml

    r2012 r2031  
    5252    </input>
    5353    <output>
     54        <string id="asdf"><current>asdf</current></string>
    5455        <curve id="f12">
    5556            <about>
  • trunk/tester/resultspage.tcl

    r2027 r2031  
    2020    itk_option define -clearcommand clearCommand ClearCommand ""
    2121    itk_option define -appname appName AppName ""
     22    itk_option define -promptcommand promptCommand PromptCommand ""
    2223
    2324    constructor {args} { # defined below }
     
    2526
    2627    public method load {xmlobj}
    27     public method clear {}
     28    public method clear {args}
    2829    public method download {option args}
    2930    public method resultset {}
     
    4344    private variable _plotlist ""
    4445
    45     # TODO: ???
    46     public variable promptcommand ""
    4746}
    4847
     
    116115        Rappture::ResultSet $f.rset \
    117116            -clearcommand [itcl::code $this clear] \
    118             -settingscommand [itcl::code $this _plot] 
     117            -settingscommand [itcl::code $this _plot]
    119118    }
    120119    pack $itk_component(resultset) -expand yes -fill both
     
    129128        itcl::delete object $obj
    130129    }
     130}
     131
     132# -----------------------------------------------------------------------
     133# CONFIGURATION OPTION: -promptcommand
     134#
     135# Forward the ResultsPage's promptcommand to the child ResultSet.
     136# -----------------------------------------------------------------------
     137itcl::configbody Rappture::ResultsPage::promptcommand {
     138    $itk_component(resultset) configure \
     139        -promptcommand $itk_option(-promptcommand)
    131140}
    132141 
     
    398407}
    399408
    400 
    401 itcl::body Rappture::ResultsPage::clear {} {
    402     foreach obj $_runs {
    403         itcl::delete object $obj
     409# -----------------------------------------------------------------------
     410# USAGE: clear ?-nodelete?
     411#
     412# Discards all results previously loaded into the results page.  Any
     413# library objects that have been loaded will be destroyed unless the
     414# -nodelete option is used.
     415# -----------------------------------------------------------------------
     416itcl::body Rappture::ResultsPage::clear {args} {
     417    if {[lsearch $args "-nodelete"] == -1} {
     418        foreach obj $_runs {
     419            itcl::delete object $obj
     420        }
    404421    }
    405422    set _runs ""
  • trunk/tester/test.tcl

    r2026 r2031  
    2828    private variable _result ""
    2929    private variable _runfile ""
     30    private variable _testobj ""
     31    private variable _toolobj ""
     32    private variable _runobj ""
    3033
    3134    public method getAdded {}
     
    3437    public method getResult {}
    3538    public method getRunfile {}
     39    public method getRunobj {}
     40    public method getTestobj {}
    3641    public method getTestxml {}
    3742    public method hasRan {}
     
    5459    set _toolxml $toolxml
    5560    set _testxml $testxml
     61    set _toolobj [Rappture::library $toolxml]
     62    if {![Rappture::library isvalid $_toolobj]} {
     63        error "$toolxml does not represent a valid library object"
     64    }
     65    set _testobj [Rappture::library $testxml]
     66    if {![Rappture::library isvalid $_testobj]} {
     67        error "$testxml does not represent a valid library object"
     68    }
     69    # HACK: Add a new input to differentiate between results
     70    $_testobj put input.run.current "Golden"
    5671}
    5772
     
    121136    }
    122137    return $_runfile
     138}
     139
     140# -----------------------------------------------------------------------
     141# USAGE: getRunobj
     142#
     143# Returns the library object generated by the previous run of the test.
     144# Throws an error if the test has not been ran.
     145# -----------------------------------------------------------------------
     146itcl::body Rappture::Tester::Test::getRunobj {} {
     147    if {!$_ran} {
     148        error "Test has not yet been ran."
     149    }
     150    return $_runobj
    123151}
    124152
     
    131159itcl::body Rappture::Tester::Test::getTestxml {} {
    132160    return $_testxml
     161}
     162
     163# ----------------------------------------------------------------------
     164# USAGE: getTestobj
     165#
     166# Returns the test library object containing the set of golden results.
     167# ----------------------------------------------------------------------
     168itcl::body Rappture::Tester::Test::getTestobj {} {
     169    return $_testobj
    133170}
    134171
     
    156193        error "Test has not yet been ran."
    157194    }
    158     set oldlib [Rappture::library $_testxml]
    159     set newlib [Rappture::library $_runfile]
    160     $newlib put test.label [$oldlib get test.label]
    161     $newlib put test.description [$oldlib get test.description]
     195    $_runobj put test.label [$_testobj get test.label]
     196    $_runobj put test.description [$_testobj get test.description]
    162197    set fid [open $_testxml w]
    163198    puts $fid "<?xml version=\"1.0\"?>"
     
    181216    set driver [makeDriver]
    182217    set tool [Rappture::Tool ::#auto $driver [file dirname $_toolxml]]
    183     foreach {status result} [eval $tool run] break
     218    foreach {status _runobj} [eval $tool run] break
    184219    set _ran yes
    185     if {$status == 0 && [Rappture::library isvalid $result]} {
    186         set golden [Rappture::library $_testxml]
    187         set _diffs [diffs $golden $result]
    188         set _missing [missing $golden $result]
    189         set _added [added $golden $result]
     220    if {$status == 0 && [Rappture::library isvalid $_runobj]} {
     221        # HACK: Add a new input to differentiate between results
     222        $_runobj put input.run.current "Test result"
     223        set _diffs [diffs $_testobj $_runobj]
     224        set _missing [missing $_testobj $_runobj]
     225        set _added [added $_testobj $_runobj]
    190226        set _runfile [$tool getRunFile]
    191227        if {$_diffs == "" && $_missing == "" && $_added == ""} {
     
    274310# ----------------------------------------------------------------------
    275311itcl::body Rappture::Tester::Test::makeDriver {} {
    276     set toolobj [Rappture::library $_toolxml]
    277     set golden [Rappture::library $_testxml]
    278312    set driver [Rappture::library $_toolxml]
    279     return [merge $toolobj $golden $driver]
     313    return [merge $_toolobj $_testobj $driver]
    280314}
    281315
  • trunk/tester/tester.tcl

    r2030 r2031  
    110110# ----------------------------------------------------------------------
    111111proc Rappture::Tester::selectionHandler {args} {
     112    puts sh
    112113    global lastsel
    113114    set test [.tree getTest]
  • trunk/tester/testtree.tcl

    r2030 r2031  
    3333    inherit itk::Widget
    3434
    35     public variable selectcommand ""
    36     public variable testdir ""
    37     public variable toolxml ""
     35    itk_option define -selectcommand selectCommand SelectCommand ""
     36    itk_option define -testdir testDir TestDir ""
     37    itk_option define -toolxml toolXml ToolXml ""
    3838
    3939    constructor {args} { #defined later }
     
    109109    eval itk_initialize $args
    110110
    111     if {$testdir == ""} {
     111    if {$itk_option(-testdir) == ""} {
    112112        error "no -testdir configuration option given."
    113113    }
    114     if {$toolxml == ""} {
     114    if {$itk_option(-toolxml) == ""} {
    115115        error "no -toolxml configuration option given."
    116116    }
     
    121121# ----------------------------------------------------------------------
    122122itcl::configbody Rappture::Tester::TestTree::testdir {
    123     populate
     123    if {$itk_option(-toolxml) != ""} {
     124        populate
     125    }
    124126}
    125127
    126128itcl::configbody Rappture::Tester::TestTree::toolxml {
    127     populate
     129    if {$itk_option(-testdir) != ""} {
     130        populate
     131    }
    128132}
    129133
     
    135139itcl::configbody Rappture::Tester::TestTree::selectcommand {
    136140    $itk_component(treeview) configure -selectcommand \
    137         "[itcl::code $this updateLabel]; $selectcommand"
     141        "[itcl::code $this updateLabel]; $itk_option(-selectcommand)"
    138142}
    139143
     
    254258    set icon [Rappture::icon molvis-3dorth]
    255259    # TODO: Descend through subdirectories inside testdir?
    256     foreach testxml [glob -nocomplain -directory $testdir *.xml] {
     260    foreach testxml [glob -nocomplain -directory $itk_option(-testdir) *.xml] {
    257261        set lib [Rappture::library $testxml]
    258262        set testpath [$lib get test.label]
    259263        if {$testpath != ""} {
    260             set test [Rappture::Tester::Test ::#auto $toolxml $testxml]
     264            set test [Rappture::Tester::Test ::#auto \
     265                $itk_option(-toolxml) $testxml]
    261266            $itk_component(treeview) insert end $testpath -data \
    262267                 [list test $test] -icons "$icon $icon" \
     
    279284        runTest $id
    280285    }
    281     eval $selectcommand -refresh
     286    eval $itk_option(-selectcommand) -refresh
    282287}
    283288
  • trunk/tester/testview.tcl

    r2030 r2031  
    3737    protected method showDescription {text}
    3838    protected method showStatus {text}
    39     protected method updateAnalyzer {args}
    40     protected method updateInfo {runfile}
     39    protected method updateResults {args}
     40    protected method updateInfo {args}
     41    protected method updateInputs {args}
    4142
    4243}
     
    7172    }
    7273    $itk_component(tabs) insert end "Results" -ipady 25 -fill both
    73     $itk_component(tabs) insert end "Info" -ipady 25 -fill both \
     74    $itk_component(tabs) insert end "Info" -ipady 25 -fill both -state disabled
     75    $itk_component(tabs) insert end "Inputs" -ipady 25 -fill both \
    7476        -state disabled
    7577
    76     #itk_component add analyzer {
    77     #    Rappture::ResultsPage $itk_component(tabs).analyzer
    78     #}
    79     #$itk_component(tabs) tab configure "Results" \
    80     #    -window $itk_component(tabs).analyzer
     78    itk_component add results {
     79        Rappture::ResultsPage $itk_component(tabs).results
     80    }
     81    $itk_component(tabs) tab configure "Results" \
     82        -window $itk_component(tabs).results
    8183
    8284    itk_component add info {
     
    8587    $itk_component(tabs) tab configure "Info" -window $itk_component(info)
    8688    pack $itk_component(tabs) -expand yes -fill both -side top
     89
     90    itk_component add inputs {
     91        blt::treeview $itk_component(tabs).inputs -separator . -autocreate true
     92    } {
     93        keep -foreground -font -cursor
     94    }
     95    $itk_component(tabs) tab configure "Inputs" -window $itk_component(inputs)
    8796
    8897    eval itk_initialize $args
     
    107116                Error {showStatus "Error while running test."}
    108117            }
    109             if {[$test getRunfile] != ""} {
    110                 # HACK: Add a new input to differentiate between golden and
    111                 # test result.  Otherwise, the slider at the bottom won't
    112                 # be enabled.
    113                 set golden [Rappture::library [$test getTestxml]]
    114                 $golden put input.run.current "Golden"
    115                 set runfile [Rappture::library [$test getRunfile]]
    116                 $runfile put input.run.current "Test result"
    117                 updateAnalyzer $golden $runfile
    118                 updateInfo $test
    119             } else {
    120                 updateInfo
    121             }
     118            updateInfo $test
    122119        } else {
    123120            showStatus "Test has not yet ran."
    124121            updateInfo
    125             if {[$test getTestxml] != ""} {
    126                 updateAnalyzer [Rappture::library [$test getTestxml]]
    127             }
    128         }
    129         set descr [[Rappture::library [$test getTestxml]] get test.description]
     122        }
     123        updateResults $test
     124        updateInputs $test
     125        set descr [[$test getTestobj] get test.description]
    130126        if {$descr == ""} {
    131127            set descr "No description."
     
    148144# ----------------------------------------------------------------------
    149145itcl::body Rappture::Tester::TestView::reset {} {
    150     updateAnalyzer
     146    updateResults
    151147    updateInfo
     148    updateInputs
    152149    showStatus ""
    153150    showDescription ""
     
    183180
    184181# ----------------------------------------------------------------------
    185 # USAGE: updateAnalyzer ?<lib> <lib>...?
     182# USAGE: updateResults ?test?
    186183#
    187184# Clears the analyzer and loads the given library objects.  Used to load
     
    189186# analyzer space if no arguments are given.
    190187# ----------------------------------------------------------------------
    191 itcl::body Rappture::Tester::TestView::updateAnalyzer {args} {
    192     # HACK: Strange errors happen when the same widget is cleared and
    193     # loaded with new data.  Instead, destroy the results page and
    194     # create a new one.
    195     catch {
    196         $itk_component(analyzer) clear
    197         destroy $itk_component(analyzer)
    198     }
    199     itk_component add analyzer {
    200         Rappture::ResultsPage $itk_component(tabs).analyzer
    201     }
    202     $itk_component(tabs) tab configure "Results" \
    203         -window $itk_component(analyzer)
    204     foreach lib $args {
    205         $itk_component(analyzer) load $lib
    206     }
     188itcl::body Rappture::Tester::TestView::updateResults {args} {
     189    $itk_component(results) clear -nodelete
     190    if {[llength $args] == 0} {
     191        # Already cleared, do nothing.
     192    } elseif {[llength $args] == 1} {
     193        $itk_component(results) load [$test getTestobj]
     194        if {[$test hasRan]} {
     195            $itk_component(results) load [$test getRunobj]
     196        }
     197    }
     198       
    207199}
    208200
     
    217209    if {[llength $args] == 0} {
    218210        $itk_component(info) delete 0.0 end
    219         # TODO: Switch back to results tab.  Why doesn't this work?
    220211        set index [$itk_component(tabs) index -name "Results"]
    221212        $itk_component(tabs) select $index
    222213        $itk_component(tabs) focus $index
    223214        $itk_component(tabs) tab configure "Info" -state disabled
    224         return
    225215    } elseif {[llength $args] == 1} {
    226216        set testxml [$test getTestxml]
     
    239229        }
    240230    } else {
    241         error "wrong # args: should be \"updateInfo ?data?\""
    242     }
    243 }
    244 
     231        error "wrong # args: should be \"updateInfo ?test?\""
     232    }
     233}
     234
     235itcl::body Rappture::Tester::TestView::updateInputs {args} {
     236    if {[llength $args] == 0} {
     237        set index [$itk_component(tabs) index -name "Results"]
     238        $itk_component(tabs) select $index
     239        $itk_component(tabs) focus $index
     240        $itk_component(tabs) tab configure "Inputs" -state disabled
     241    } elseif {[llength $args] == 1} {
     242        $itk_component(tabs) tab configure "Inputs" -state normal
     243    } else {
     244        error "wrong # args: should be \"updateInfo ?test?\""
     245    }
     246}
     247
Note: See TracChangeset for help on using the changeset viewer.