2
# Spandex benchmark and test framework.
4
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
# Contact: Kari J. Kangas <kari.j.kangas@nokia.com>
8
# This framework is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU Lesser General Public License as published by the
10
# Free Software Foundation, version 2.1 of the License.
12
# This framework is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17
# You should have received a copy of the GNU Lesser General Public License
18
# along with this framework; if not, see <http://www.gnu.org/licenses/>.
25
from sct import bmbuilder
26
from sct.util import textutil
27
from sct.visualtest import image, report
29
################################################################################
32
def __init__( self, name, description='', status='UNDEFINED', priority='UNDEFINED' ):
34
self.description = description
38
return '%-50s Status: %10s' % (self.name, self.status)
40
def createTestCases( suite ):
42
for benchmark in suite.benchmarks:
43
testCases.append( TestCase( benchmark.name, description=benchmark.__doc__ ) )
46
# def runSuite( suite, target ):
47
# runDir = os.path.join( 'run', target )
48
# inputImagePath = os.path.join( runDir, 'images' )
49
# fileutil.cleanDir( inputImagePath )
50
# spandexInput = suite.generateSpandexInput( target )
51
# # Create the image directory
52
# imageDir = os.path.join( runDir, 'images' )
53
# fileutil.safeCreateDir( imageDir )
54
# runSpandex( spandexInput, runDir )
55
# tga2png.tga2png( imageDir, imageDir )
57
class VisualTestCase( bmbuilder.Benchmark ):
59
bmbuilder.Benchmark.__init__( self )
62
def permutate( stack, rest ):
69
if isinstance( attr, str ):
75
for name, value in zip( names, value ):
78
stack[names[0]] = value
79
for x in permutate( stack, rest ):
85
class VisualTestSuite( bmbuilder.Suite ):
86
def addTestCase( self, testCaseClass ):
87
if hasattr( testCaseClass, 'testValues' ):
88
for kwargs in permutate( {}, testCaseClass.testValues ):
89
self.addBenchmark( testCaseClass( **kwargs ) )
91
self.addBenchmark( testCaseClass() )
93
################################################################################
95
commandConfig.update( { 'compare' : '<candidate image path> <reference image path>',
96
'fetch' : '<path> <target>',
97
'generate' : '<target>',
98
#'prepare' : '<path> <target>',
100
#'show' : '<image paths>'
103
def handleCompareCommand( suite, options, candidateImagePath, referenceImagePath ):
104
testCases = createTestCases( suite )
105
comparer = image.getImageComparer( 'exact' )
107
candidate_image_loader = image.TestCaseImageLoader( candidateImagePath )
108
reference_image_loader = image.TestCaseImageLoader( referenceImagePath )
111
report.create_image_comparison_report( options.reportName, testCases, reference_image_loader, candidate_image_loader, comparer, options.summary )
113
report.create_image_comparison_report( options.reportName, testCases, reference_image_loader, candidate_image_loader, comparer, options.summary )
115
def handleFetchCommand( suite, options, path, target ):
116
srcImagePath = os.path.join( path )
117
dstImagePath = os.path.join( 'images', target )
118
if not os.path.exists( srcImagePath ):
119
console.exitWithError( 'Folder %s does not exist' % srcImagePath )
120
if os.path.exists( dstImagePath ):
121
if not console.confirm( 'ALL the images at %s will DELETED and images from %s will be copied there, OK?' % (dstImagePath, srcImagePath) ):
122
console.exitWithError( 'Stopped by user request' )
123
shutil.rmtree( dstImagePath )
124
os.makedirs( dstImagePath )
125
tga2png.tga2png( srcImagePath, dstImagePath )
127
def handleGenerateCommand( suite, options, target ):
129
suite.generateSpandexInputToFiles( target )
131
sys.stdout.write( suite.generateSpandexInput( target ) )
133
# def handlePrepareCommand( suite, options, path, target ):
134
# if os.path.exists( path ):
135
# if not console.confirm( '%s/benchmark.txt and everything under %s/Images will be deleted, OK?' % (path, path) ):
136
# console.exitWithError( 'Stopped by user request' )
137
# os.system( 'rm -f %s/benchmark.txt %s/images/*.*' % (path, path) )
139
# os.makedirs( '%s/images' % path )
140
# console.printInfo( '%s/images created' % path )
141
# # Generate benchmark.txt
142
# file( '%s/benchmark.txt' % path, 'w' ).write( suite.generateSpandexInput( target ) )
144
# def handleRunCommand( suite, options, targets ):
145
# for target in targets:
146
# runSuite( suite, target )
148
# if options.compare:
149
# if len( targets ) != 2:
150
# console.exitWithError( 'Need exactly two targets to compare' )
151
# candidateImagePath = os.path.join( 'run', targets[0], 'images' )
152
# referenceImagePath = os.path.join( 'run', targets[1], 'images' )
153
# handleCompareCommand( options, candidateImagePath, referenceImagePath )
156
def __init__( self ):
157
CLI.__init__( self, VisualTestSuite() )
159
self.parser.add_option( '-c', '--compare',
163
help='produce comparison report when running two targets' )
164
self.parser.add_option( '-r', '--report',
168
help='generate report' )
169
self.parser.add_option( '--report-name',
173
help='name of the report' )
174
self.parser.add_option( '-v', '--verbose',
178
help='print verbose progress information' )
179
self.parser.add_option( '', '--separate',
183
help='write benchmarks to separate files' )
184
self.parser.add_option( '', '--summary',
188
help='Create summary without images' )
191
return VRTCLI().run()