source: trunk/tester/tester.tcl @ 2008

Last change on this file since 2008 was 2008, checked in by braffert, 13 years ago

Developing regression tester.

  • Property svn:executable set to *
File size: 5.7 KB
Line 
1#! /bin/sh
2# ----------------------------------------------------------------------
3# RAPPTURE REGRESSION TESTER
4#
5# This program will read a set of test xml files typically located in
6# a tool's "tests" subdirectory, and provide an interactive test suite.
7# The test xml files should contain a complete set of inputs and outputs
8# for one run of an application.  In each test xml, a label must be
9# located at the path test.label.  Test labels may be organized
10# hierarchically by using dots to separate components of the test label
11# (example: roomtemp.1eV).  A description may optionally be located at
12# the path test.description.  Input arguments are the path to the
13# tool.xml of the version being tested, and the path the the directory
14# containing a set of test xml files.  If the arguments are missing,
15# the program will attempt to locate them automatically.
16#
17# USAGE: tester.tcl ?-tool tool.xml? ?-testdir tests?
18# ======================================================================
19#  AUTHOR:  Ben Rafferty, Purdue University
20#  Copyright (c) 2010  Purdue Research Foundation
21#
22#  See the file "license.terms" for information on usage and
23#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
24# ======================================================================
25#\
26exec tclsh "$0" $*
27# ----------------------------------------------------------------------
28# wish executes everything from here on...
29
30# TODO: Won't need this once tied in with the rest of the package
31lappend auto_path [file dirname $argv0]
32
33package require Itk
34package require Rappture
35package require RapptureGUI
36
37Rappture::getopts argv params {
38    value -tool ""
39    value -testdir ""
40}
41
42# If tool.xml and test directory locations are not given, try to find them.
43if {$params(-tool) == ""} {
44    if {[file exists tool.xml]} {
45        set params(-tool) tool.xml
46    } elseif {[file exists [file join rappture tool.xml]]} {
47        set params(-tool) [file join rappture tool.xml]
48    } else {
49        error "Cannot find tool.xml"
50    }
51}
52
53if {$params(-testdir) == ""} {
54    set tooldir [file dirname $params(-tool)]
55    if {[file isdirectory [file join $tooldir tests]]} {
56        set params(-testdir) [file join $tooldir tests]
57    } elseif {[file isdirectory [file join [file dirname $tooldir] tests]]} {
58        set params(-testdir) [file join [file dirname $tooldir] tests]
59    } else {
60        error "Cannot find test directory."
61    }
62}
63
64# ----------------------------------------------------------------------
65# INITIALIZE WINDOW
66# ----------------------------------------------------------------------
67wm title . "Rappture Regression Tester"
68panedwindow .pw
69.pw add [Rappture::Tester::TestTree .tree \
70    -testdir $params(-testdir) \
71    -command Rappture::Tester::runSelected \
72    -selectcommand Rappture::Tester::selectionHandler]
73.pw add [Rappture::Tester::TestView .view $params(-tool)]
74pack .pw -expand yes -fill both
75
76# ----------------------------------------------------------------------
77# USAGE: runAll ?-force?
78#
79# When this method is invoked, all tests contained in the TestTree will
80# be ran sequentially.
81# ----------------------------------------------------------------------
82proc Rappture::Tester::runAll {args} {
83    foreach id [.tree getTests] {
84        runTest $id $args
85    }
86    .view update [.tree getData focus]
87}
88
89# ----------------------------------------------------------------------
90# USAGE: runSelected ?-force?
91#
92# When this method is invoked, all tests that are currently selected
93# will be ran.  If a branch node (folder) is selected, all of its
94# descendant tests will be ran as well.
95# TODO: Parallel exection
96# ----------------------------------------------------------------------
97proc Rappture::Tester::runSelected {args} {
98    foreach id [.tree getSelected] {
99        runTest $id $args
100    }
101    .view update [.tree getData focus]
102}
103
104# ----------------------------------------------------------------------
105# USAGE: runTest id ?-force?
106#
107# Called by runAll and runSelected to run a single test at the tree node
108# specified by the given ide.  In most cases, this method should not be
109# called directly.  A driver object is generated by the makeDriver
110# procedure in compare.tcl, and the results given by the new version are
111# compared to the golden result by the compare procedure in compare.tcl
112# ----------------------------------------------------------------------
113proc Rappture::Tester::runTest {id args} {
114    array set data [.tree getData $id]
115    global params
116    if {$data(ran) && [lsearch -exact $args "-force"] == -1} {
117        # Already ran. Skip.
118        return
119    }
120    set data(result) "Running"
121    .tree setData $id [array get data]
122
123    set driver [Rappture::Tester::makeDriver $params(-tool) $data(testxml)]
124    set tool [Rappture::Tool ::#auto $driver [file dirname $params(-tool)]]
125    foreach {status result} [eval $tool run] break
126    set data(ran) yes
127    if {$status == 0 && [Rappture::library isvalid $result]} {
128        set golden [Rappture::library $data(testxml)]
129        set diffs [Rappture::Tester::compare $golden $result output]
130        if {$diffs == ""} {
131            set data(result) Pass
132        } else {
133            set data(result) Fail
134        }
135        set data(diffs) $diffs
136        set data(runfile) [$tool getRunFile]
137    } else {
138        set data(result) Error
139        set data(runfile) ""
140    }
141    .tree setData $id [array get data]
142}
143
144# ----------------------------------------------------------------------
145# USAGE: selectionHandler
146#
147# Used internally to communicate between the test tree and the right
148# hand side viewer.  Upon selecting a new tree node, pass the focused
149# node's data to the right hand side.
150# ----------------------------------------------------------------------
151proc Rappture::Tester::selectionHandler {} {
152    .view update [.tree getData focus]
153}
154
Note: See TracBrowser for help on using the repository browser.