1 | # ---------------------------------------------------------------------- |
---|
2 | # COMPONENT: mainwin - main application window for regression tester |
---|
3 | # |
---|
4 | # This widget acts as the main window for the Rappture regression |
---|
5 | # tester. Constructor accepts the location of the new version to be |
---|
6 | # tested, and the location of a directory containg test xml files. |
---|
7 | # ====================================================================== |
---|
8 | # AUTHOR: Ben Rafferty, Purdue University |
---|
9 | # Copyright (c) 2010 Purdue Research Foundation |
---|
10 | # |
---|
11 | # See the file "license.terms" for information on usage and |
---|
12 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | # ====================================================================== |
---|
14 | package require Itk |
---|
15 | package require Rappture |
---|
16 | package require RapptureGUI |
---|
17 | |
---|
18 | namespace eval Rappture::Regression::MainWin { #forward declaration } |
---|
19 | |
---|
20 | itcl::class Rappture::Regression::MainWin { |
---|
21 | inherit itk::Toplevel |
---|
22 | |
---|
23 | constructor {tooldir testdir} { #defined later } |
---|
24 | public method runAll {} |
---|
25 | public method runSelected {} |
---|
26 | private method runTest {id} |
---|
27 | private method makeDriver {testxml} |
---|
28 | |
---|
29 | private variable _testdir |
---|
30 | private variable _tooldir |
---|
31 | private variable _toolxml |
---|
32 | |
---|
33 | } |
---|
34 | |
---|
35 | # TODO: figure out exactly what should go in here. |
---|
36 | itk::usual TestView { |
---|
37 | keep -background -foreground -font |
---|
38 | } |
---|
39 | |
---|
40 | itk::usual Panedwindow { |
---|
41 | keep -background |
---|
42 | } |
---|
43 | |
---|
44 | itcl::body Rappture::Regression::MainWin::constructor {tooldir testdir} { |
---|
45 | puts "Constructing MainWin." |
---|
46 | |
---|
47 | # TODO: Replace explicit constructor arguments with "args" |
---|
48 | # If tooldir is not given, use current directory. |
---|
49 | # If testdir is not given, look for it inside of tooldir. |
---|
50 | if {[file isdirectory $tooldir]} { |
---|
51 | set _tooldir $tooldir |
---|
52 | } else { |
---|
53 | # TODO: Properly format error messages |
---|
54 | error "Given tooldir is not a directory." |
---|
55 | } |
---|
56 | if {[file isdirectory $testdir]} { |
---|
57 | set _testdir $testdir |
---|
58 | } else { |
---|
59 | error "Given testdir is not a directory" |
---|
60 | } |
---|
61 | |
---|
62 | # TODO: Check other locations for tool.xml and throw error if not found |
---|
63 | set _toolxml [file join $tooldir tool.xml] |
---|
64 | |
---|
65 | itk_component add topBar { |
---|
66 | frame $itk_interior.topBar |
---|
67 | } |
---|
68 | itk_component add cmdLabel { |
---|
69 | label $itk_component(topBar).cmdLabel -text "Tool command:" |
---|
70 | } |
---|
71 | itk_component add cmdEntry { |
---|
72 | entry $itk_component(topBar).cmdEntry |
---|
73 | } |
---|
74 | itk_component add bRunAll { |
---|
75 | button $itk_component(topBar).bRunAll -text "Run all" \ |
---|
76 | -command [itcl::code $itk_interior runAll] |
---|
77 | } |
---|
78 | itk_component add bRunSelected { |
---|
79 | button $itk_component(topBar).bRunSelected -text "Run selected" \ |
---|
80 | -command [itcl::code $itk_interior runSelected] |
---|
81 | } |
---|
82 | pack $itk_component(cmdLabel) -side left |
---|
83 | pack $itk_component(cmdEntry) -side left -expand yes -fill x |
---|
84 | pack $itk_component(bRunAll) -side right |
---|
85 | pack $itk_component(bRunSelected) -side right |
---|
86 | pack $itk_component(topBar) -side top -fill x |
---|
87 | |
---|
88 | itk_component add pane { |
---|
89 | panedwindow $itk_interior.pane |
---|
90 | } |
---|
91 | itk_component add tree { |
---|
92 | Rappture::Regression::TestTree $itk_component(pane).tree $testdir |
---|
93 | } |
---|
94 | itk_component add view { |
---|
95 | Rappture::Regression::TestView $itk_component(pane).view |
---|
96 | } |
---|
97 | $itk_component(pane) add $itk_component(pane).tree -sticky nesw |
---|
98 | $itk_component(pane) add $itk_component(pane).view -sticky nesw |
---|
99 | # TODO: make panes scale proportionally when window grows |
---|
100 | pack $itk_component(pane) -side left -expand yes -fill both |
---|
101 | } |
---|
102 | |
---|
103 | # ---------------------------------------------------------------------- |
---|
104 | # USAGE: runAll |
---|
105 | # |
---|
106 | # When this method is invoked, all tests contained in the TestTree will |
---|
107 | # be ran sequentially. |
---|
108 | # ---------------------------------------------------------------------- |
---|
109 | itcl::body Rappture::Regression::MainWin::runAll {} { |
---|
110 | # TODO: Add force or ifneeded flag and propagate to runTest |
---|
111 | puts "Running all tests." |
---|
112 | set tests [$itk_component(tree) getTests] |
---|
113 | foreach id $tests { |
---|
114 | runTest $id |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | # ---------------------------------------------------------------------- |
---|
119 | # USAGE: runSelected |
---|
120 | # |
---|
121 | # When this method is invoked, all tests that are currently selected |
---|
122 | # will be ran. If a branch node (folder) is selected, all of its |
---|
123 | # descendant tests will be ran as well. |
---|
124 | # ---------------------------------------------------------------------- |
---|
125 | itcl::body Rappture::Regression::MainWin::runSelected {} { |
---|
126 | # TODO: Add force or ifneeded flag and propagate to runTest |
---|
127 | puts "Running selected tests." |
---|
128 | set selected [$itk_component(tree) getSelected] |
---|
129 | foreach id $selected { |
---|
130 | runTest $id |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | # ---------------------------------------------------------------------- |
---|
135 | # USAGE: runTest id |
---|
136 | # |
---|
137 | # Called by runAll and runSelected to run a single test at tree node |
---|
138 | # specified by the given id. In most cases, this method should not be |
---|
139 | # called directly. Results given by the new version are compared to |
---|
140 | # the test xml by the compare procedure in compare.tcl |
---|
141 | # ---------------------------------------------------------------------- |
---|
142 | itcl::body Rappture::Regression::MainWin::runTest {id} { |
---|
143 | # TODO: Add force or ifneeded flag and check the "ran" element of the |
---|
144 | # data array |
---|
145 | puts "Running test at node $id." |
---|
146 | array set data [$itk_component(tree) getData $id] |
---|
147 | set data(result) "In progress" |
---|
148 | $itk_component(tree) setData $id [array get data] |
---|
149 | |
---|
150 | set testxml $data(xmlfile) |
---|
151 | set driver [makeDriver $testxml] |
---|
152 | |
---|
153 | set tool [Rappture::Tool ::#auto $driver $_tooldir] |
---|
154 | set result "" |
---|
155 | foreach {status result} [eval $tool run] break |
---|
156 | set data(ran) yes |
---|
157 | if {$status == 0 && [Rappture::library isvalid $result]} { |
---|
158 | set golden [Rappture::library $testxml] |
---|
159 | set diffs [Rappture::Regression::compare $golden $result output] |
---|
160 | if {$diffs != ""} { |
---|
161 | set data(result) fail |
---|
162 | set data(diffs) $diffs |
---|
163 | } else { |
---|
164 | set data(result) pass |
---|
165 | } |
---|
166 | } else { |
---|
167 | set data(result) error |
---|
168 | } |
---|
169 | $itk_component(tree) setData $id [array get data] |
---|
170 | # TODO: Remove runfile |
---|
171 | } |
---|
172 | |
---|
173 | # ---------------------------------------------------------------------- |
---|
174 | # USAGE: makeDriver testxml |
---|
175 | # |
---|
176 | # Creates and returns a driver Rappture::library object to be used for |
---|
177 | # running the test specified by testxml. If any input elements are |
---|
178 | # present in the new tool.xml which do not exist in the test xml, use |
---|
179 | # the default value specified in the new tool.xml. |
---|
180 | # ---------------------------------------------------------------------- |
---|
181 | itcl::body Rappture::Regression::MainWin::makeDriver {testxml} { |
---|
182 | # Construct a driver file. |
---|
183 | # TODO: Pass through all inputs in the new tool.xml. If present in the |
---|
184 | # test xml, copy the value. If not, use the default from the new |
---|
185 | # tool.xml. |
---|
186 | # For now, just use test xml with the output deleted and command replaced |
---|
187 | set driver [Rappture::library $testxml] |
---|
188 | set cmd [[Rappture::library $_toolxml] get tool.command] |
---|
189 | $driver put tool.command $cmd |
---|
190 | $driver remove output |
---|
191 | return $driver |
---|
192 | } |
---|