-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtress
executable file
·293 lines (266 loc) · 11.2 KB
/
gtress
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#! /usr/bin/env python
import sys
import os
import threading
from types import *
try:
import subprocess
except:
print "Importing `subprocess' module failed!"
sys.exit( 1 )
try:
import csv
except:
print "Importing `csv' module failed!"
sys.exit( 1 )
try:
import pygtk
pygtk.require( "2.0" )
import pango
import gobject
import gtk
except:
print "GTK/Pango/Glade not availible!"
sys.exit( 1 )
class SuiteList:
def __init__( self, path_ ):
self._suites = {}
self._candidates = {}
self._path = path_
try:
csvreader = csv.reader( open( self._path, "rb" ), delimiter = ';' )
for row in csvreader:
self._candidates[ row[0] ] = 0 # row[1]
except:
pass
def __del__( self ):
self.save()
def save( self ):
csvwriter = csv.writer( open( self._path, "wb" ), delimiter = ';' )
csvwriter.writerows( map( lambda e: [ e ], sorted( self._suites.keys() ) ) )
def set_suite( self, suite_, enabled_, tests_ ):
if enabled_:
self._suites[ suite_ ] = tests_
elif suite_ in self._suites:
del self._suites[ suite_ ]
def was_enabled( self, suite_ ):
return suite_ in self._candidates
def is_enabled( self, suite_ ):
return suite_ in self._suites
def run_tests( gtress_, jobs_ ):
try:
gtress_._child = subprocess.Popen( [ "./build/debug/tress/1exec", "-j", str( jobs_ ), "-F", gtress_._suiteList._path ], bufsize = 0, stdout = os.open( os.devnull, os.O_RDWR ), stderr = subprocess.PIPE )
stderr = gtress_._child.stderr
while True:
line = stderr.readline()
if line == "":
break;
print line.lstrip( " \t" ).strip( "\n" )
fields = map( lambda s : s.lstrip( " \t" ).strip( " \t" ), line.split( ": " ) )
if gtress_._suiteList.is_enabled( fields[0] ):
passed = fields[1].count( "." ) + fields[1].count( "," )
failed = fields[1].count( "[" )
gobject.idle_add( gtress_.update_passed, fields[0], passed, failed )
finally:
if gtress_._child != None:
gtress_._child.wait()
gtress_._child = None
class GTress:
def __init__( self, suiteList_ ):
self._child = None
self._thread = None
self._suiteList = suiteList_
self._currentFilter = ""
self._suiteMap = {}
gtk.gdk.threads_init()
self._gui = gtk.Builder()
self._gui.add_from_file( "gtress.ui" )
self._list = self._gui.get_object( "GUI_LIST" )
self._data = gtk.ListStore( str, int, bool, int, int, gtk.gdk.Color, str )
self._filter = self._data.filter_new()
self._filter.set_visible_func( self.apply_filter )
self._listSuiteNameColumn = gtk.TreeViewColumn( "suite names" )
self._listSuiteNameCellRenderer = gtk.CellRendererText()
self._listSuiteNameColumn.pack_start( self._listSuiteNameCellRenderer, True )
self._listSuiteNameColumn.add_attribute( self._listSuiteNameCellRenderer, "text", 0 )
self._listSuiteNameColumn.add_attribute( self._listSuiteNameCellRenderer, "background-gdk", 5 )
self._listSuiteNameColumn.set_sizing( gtk.TREE_VIEW_COLUMN_AUTOSIZE )
self._listSuiteNameColumn.set_resizable( True )
self._listSuiteNameColumn.set_expand( True )
self._listTestCountColumn = gtk.TreeViewColumn( "test count" )
self._listTestCountCellRenderer = gtk.CellRendererText()
self._listTestCountCellRenderer.set_property( "xalign", 1 )
self._listTestCountCellRenderer.set_property( "xpad", 8 )
self._listTestCountColumn.pack_start( self._listTestCountCellRenderer, True )
self._listTestCountColumn.add_attribute( self._listTestCountCellRenderer, "text", 1 )
self._listTestCountColumn.add_attribute( self._listTestCountCellRenderer, "background-gdk", 5 )
self._listTestCountColumn.set_sizing( gtk.TREE_VIEW_COLUMN_FIXED )
self._listTestCountColumn.set_fixed_width( 80 )
self._listTestCountColumn.set_resizable( False )
self._listTestCountColumn.set_expand( False )
self._listSuiteEnabledColumn = gtk.TreeViewColumn( "enabled" )
self._listSuiteEnabledCellRenderer = gtk.CellRendererToggle()
self._listSuiteEnabledCellRenderer.set_property( "activatable", True )
self._listSuiteEnabledCellRenderer.set_property( "xalign", 0.5 )
self._listSuiteEnabledColumn.pack_start( self._listSuiteEnabledCellRenderer, True )
self._listSuiteEnabledColumn.add_attribute( self._listSuiteEnabledCellRenderer, "active", 2 )
self._listSuiteEnabledColumn.add_attribute( self._listSuiteEnabledCellRenderer, "cell-background-gdk", 5 )
self._listSuiteEnabledCellRenderer.connect( "toggled", self.col2_toggled_cb, self._filter )
self._listSuiteEnabledColumn.set_sizing( gtk.TREE_VIEW_COLUMN_FIXED )
self._listSuiteEnabledColumn.set_fixed_width( 64 )
self._listSuiteEnabledColumn.set_resizable( False )
self._listSuiteEnabledColumn.set_expand( False )
self._listPassedColumn = gtk.TreeViewColumn( "passed" )
self._listPassedCellRenderer = gtk.CellRendererText()
self._listPassedCellRenderer.set_property( "xalign", 1 )
self._listPassedCellRenderer.set_property( "xpad", 8 )
self._listPassedColumn.pack_start( self._listPassedCellRenderer, True )
self._listPassedColumn.add_attribute( self._listPassedCellRenderer, "text", 3 )
self._listPassedColumn.add_attribute( self._listPassedCellRenderer, "background-gdk", 5 )
self._listPassedColumn.set_sizing( gtk.TREE_VIEW_COLUMN_FIXED )
self._listPassedColumn.set_fixed_width( 80 )
self._listPassedColumn.set_resizable( False )
self._listPassedColumn.set_expand( False )
self._listFailedColumn = gtk.TreeViewColumn( "failed" )
self._listFailedCellRenderer = gtk.CellRendererText()
self._listFailedCellRenderer.set_property( "xalign", 1 )
self._listFailedCellRenderer.set_property( "xpad", 8 )
self._listFailedColumn.pack_start( self._listFailedCellRenderer, True )
self._listFailedColumn.add_attribute( self._listFailedCellRenderer, "text", 4 )
self._listFailedColumn.add_attribute( self._listFailedCellRenderer, "background-gdk", 5 )
self._listFailedColumn.set_sizing( gtk.TREE_VIEW_COLUMN_FIXED )
self._listFailedColumn.set_fixed_width( 80 )
self._listFailedColumn.set_resizable( False )
self._listFailedColumn.set_expand( False )
self._list.append_column( self._listSuiteNameColumn )
self._list.append_column( self._listTestCountColumn )
self._list.append_column( self._listSuiteEnabledColumn )
self._list.append_column( self._listPassedColumn )
self._list.append_column( self._listFailedColumn )
self._list.get_selection().set_mode( gtk.SELECTION_MULTIPLE )
self._list.set_model( self._filter )
self._list.set_tooltip_column( 6 )
self._filterEdit = self._gui.get_object( "GUI_NAME_FILTER" )
self._gui.get_object( "GUI_QUIT" ).connect( "clicked", self.destroy )
self._jobs = self._gui.get_object( "GUI_JOBS" )
self._all = self._gui.get_object( "GUI_ALL" )
self._gui.connect_signals( self )
self._child = subprocess.Popen( [ "./build/debug/tress/1exec", "-L", "-v" ], stdout = subprocess.PIPE )
tests = self._child.stdout
totalTests = 0
totalSuites = 0
suiteNo = 0
for line in tests.readlines():
fields = line.lstrip( " \t" ).strip( "\n" ).split()
if ( fields[0] != "setup._argc" ) and ( fields[0] != "setup._argv[0]" ) and ( fields[0] != "total" ):
wasEnabled = self._suiteList.was_enabled( fields[0] )
if wasEnabled:
totalTests += int( fields[1] )
totalSuites += 1
self._data.append( [ fields[0], int( fields[1] ), wasEnabled, 0, 0, gtk.gdk.Color( 65535, 65535, 65535 ), None ] )
self._suiteList.set_suite( fields[0], wasEnabled, fields[1] )
self._suiteMap[fields[0]] = suiteNo
suiteNo += 1
self._child.wait()
self._child = None
self._totalTestCount = self._gui.get_object( "GUI_TOTAL_TEST_COUNT" )
self._totalEnabledSuites = self._gui.get_object( "GUI_TOTAL_ENABLED_SUITES" )
self._passed = self._gui.get_object( "GUI_PASSED" )
self._failed = self._gui.get_object( "GUI_FAILED" )
self._progress = self._gui.get_object( "GUI_PROGRESS" )
self._okStyle = self._progress.get_style().copy()
self._failStyle = self._okStyle.copy()
self._failColor = gtk.gdk.Color( 65535, 40000, 40000 )
self._failStyle.bg[gtk.STATE_NORMAL] = self._failColor
self._totalTestCount.set_text( str( totalTests ) )
self._totalEnabledSuites.set_text( str( totalSuites ) )
def update_passed( self, suite_, passed_, failed_ ):
self._data[self._suiteMap[suite_]][3] += passed_
self._data[self._suiteMap[suite_]][4] += failed_
if ( failed_ > 0 ):
self._data[self._suiteMap[suite_]][5] = self._failColor
self._progress.set_style( self._failStyle )
passed = int( self._passed.get_text() ) + passed_
failed = int( self._failed.get_text() ) + failed_
self._passed.set_text( str( passed ) )
self._failed.set_text( str( failed ) )
total = float( self._totalTestCount.get_text() )
self._progress.set_fraction( passed / total )
def col2_toggled_cb( self, cell, path_, model ):
path = self._filter.convert_path_to_child_path( path_ )
on = self._data[path][2] = not model[path_][2]
self._all.set_inconsistent( True )
totalModified = model[path_][1]
suite = 1
if ( not on ):
totalModified = -totalModified
suite = -suite;
self._totalTestCount.set_text( str( int( self._totalTestCount.get_text() ) + totalModified ) )
self._totalEnabledSuites.set_text( str( int( self._totalEnabledSuites.get_text() ) + suite ) )
return
def all_toggled( self, toggle_ ):
toggle_.set_inconsistent( False )
all = toggle_.get_active()
i = self._filter.get_iter_first()
totalModified = 0
suite = 0
while i != None:
if self._data[self._filter.convert_iter_to_child_iter( i )][2] != all:
totalModified += self._data[self._filter.convert_iter_to_child_iter( i )][1]
suite += 1
self._data[self._filter.convert_iter_to_child_iter( i )][2] = all
i = self._filter.iter_next( i )
if ( not all ):
totalModified = -totalModified
suite = -suite;
self._totalTestCount.set_text( str( int( self._totalTestCount.get_text() ) + totalModified ) )
self._totalEnabledSuites.set_text( str( int( self._totalEnabledSuites.get_text() ) + suite ) )
def apply_filter( self, model_, iter_ ):
visible = ( type( model_[iter_][0] ) != NoneType ) and ( model_[iter_][0].find( self._currentFilter ) >= 0 )
return visible
def filter_changed( self, edit_ ):
self._currentFilter = edit_.get_text()
self._filter.refilter()
def clear_filter( self, button_ ):
self._all.set_inconsistent( True )
self._currentFilter = ""
self._filterEdit.set_text( self._currentFilter )
self._filter.refilter()
def update_suite_list( self ):
for row in self._data:
self._suiteList.set_suite( row[0], row[2], row[1] )
def run( self, button_ ):
self.update_suite_list()
self._suiteList.save()
if self._thread != None:
self._thread.join()
self._thread = None
for row in self._data:
row[3] = 0
row[4] = 0
row[5] = gtk.gdk.Color( 65535, 65535, 65535 )
row[6] = None
self._progress.set_style( self._okStyle )
self._passed.set_text( "0" )
self._failed.set_text( "0" )
self._thread = threading.Thread( target = run_tests, args = [self, self._jobs.get_value()] )
self._thread.start()
def main( self ):
gtk.main()
def delete_event( self, widget, data = None ):
return False
def destroy( self, widget, data = None ):
if self._thread != None:
self._thread.join()
self._thread = None
if self._child != None:
self._child.wait()
self.update_suite_list()
gtk.main_quit()
def __del__( self ):
pass
if __name__ == "__main__":
suiteList = SuiteList( "tress.suites" )
gtress = GTress( suiteList )
gtress.main()
suiteList.save()