blob: 12d1e3e1f7b72f281523ad8de668fefcebdab0e9 [file] [log] [blame]
Christophe Favergeon2942a332020-01-20 14:18:48 +01001import os
2import os.path
3import subprocess
4import colorama
5from colorama import init,Fore, Back, Style
6import argparse
Christophe Favergeon512b1482020-02-07 11:25:11 +01007from TestScripts.Regression.Commands import *
8import yaml
9import sys
10import itertools
11from pathlib import Path
Christophe Favergeon8cb37302020-05-13 13:06:58 +020012import sqlite3
Christophe Favergeon512b1482020-02-07 11:25:11 +010013
Christophe Favergeon8cb37302020-05-13 13:06:58 +020014# Command to get last runid
15lastID="""SELECT runid FROM RUN ORDER BY runid DESC LIMIT 1
16"""
17
18addNewIDCmd="""INSERT INTO RUN VALUES(?,date('now'))
19"""
20
21benchID = 0
22regID = 0
23
24def getLastRunID(c):
25 r=c.execute(lastID)
26 result=r.fetchone()
27 if result is None:
28 return(0)
29 else:
30 return(int(result[0]))
31
32def addNewID(c,newid):
33 c.execute(addNewIDCmd,(newid,))
34 c.commit()
Christophe Favergeon512b1482020-02-07 11:25:11 +010035
36# Small state machine
37def updateTestStatus(testStatusForThisBuild,newTestStatus):
38 if testStatusForThisBuild == NOTESTFAILED:
39 if newTestStatus == NOTESTFAILED:
40 return(NOTESTFAILED)
41 if newTestStatus == MAKEFAILED:
42 return(MAKEFAILED)
43 if newTestStatus == TESTFAILED:
44 return(TESTFAILED)
45 if testStatusForThisBuild == MAKEFAILED:
46 if newTestStatus == NOTESTFAILED:
47 return(MAKEFAILED)
48 if newTestStatus == MAKEFAILED:
49 return(MAKEFAILED)
50 if newTestStatus == TESTFAILED:
51 return(TESTFAILED)
52 if testStatusForThisBuild == TESTFAILED:
53 if newTestStatus == NOTESTFAILED:
54 return(TESTFAILED)
55 if newTestStatus == MAKEFAILED:
56 return(TESTFAILED)
57 if newTestStatus == TESTFAILED:
58 return(TESTFAILED)
59 if testStatusForThisBuild == FLOWFAILURE:
60 return(testStatusForThisBuild)
61 if testStatusForThisBuild == CALLFAILURE:
62 return(testStatusForThisBuild)
63
Christophe Favergeon830283b2020-04-27 14:51:08 +020064# Analyze the configuration flags (like loopunroll etc ...)
65def analyzeFlags(flags):
66
67 onoffFlags = []
68 for f in flags:
69 if type(f) is dict:
70 for var in f:
71 if type(f[var]) is bool:
72 if f[var]:
73 onoffFlags.append(["-D%s=ON" % (var)])
74 else:
75 onoffFlags.append(["-D%s=OFF" % (var)])
76 else:
77 onoffFlags.append(["-D%s=%s" % (var,f[var])])
78 else:
79 onoffFlags.append(["-D" + f +"=ON","-D" + f +"=OFF"])
80
81 allConfigs=cartesian(*onoffFlags)
82 return(allConfigs)
83
84# Extract the cmake for a specific compiler
85# and the flag configuration to use for this compiler.
86# This flags configuration will override the global one
87def analyzeToolchain(toolchain, globalConfig):
88 config=globalConfig
89 cmake=""
90 sim=True
91 if type(toolchain) is str:
92 cmake=toolchain
93 else:
94 for t in toolchain:
95 if type(t) is dict:
96 if "FLAGS" in t:
97 hasConfig=True
98 config = analyzeFlags(t["FLAGS"])
99 if "SIM" in t:
100 sim = t["SIM"]
101 if type(t) is str:
102 cmake=t
103 return(cmake,config,sim)
104
Christophe Favergeon512b1482020-02-07 11:25:11 +0100105
106
107def cartesian(*somelists):
108 r=[]
109 for element in itertools.product(*somelists):
110 r.append(list(element))
111 return(r)
112
Christophe Favergeon830283b2020-04-27 14:51:08 +0200113root = Path(os.getcwd()).parent.parent.parent
114
115
Christophe Favergeon512b1482020-02-07 11:25:11 +0100116testFailed = 0
Christophe Favergeon2942a332020-01-20 14:18:48 +0100117
118init()
119
Christophe Favergeon2942a332020-01-20 14:18:48 +0100120parser = argparse.ArgumentParser(description='Parse test description')
Christophe Favergeon512b1482020-02-07 11:25:11 +0100121parser.add_argument('-i', nargs='?',type = str, default="testrunConfig.yaml",help="Config file")
122parser.add_argument('-r', nargs='?',type = str, default=root, help="Root folder")
Christophe Favergeon830283b2020-04-27 14:51:08 +0200123parser.add_argument('-n', nargs='?',type = int, default=0, help="ID value when launching in parallel")
124parser.add_argument('-b', action='store_true', help="Benchmark mode")
125parser.add_argument('-f', nargs='?',type = str, default="desc.txt",help="Test description file")
126parser.add_argument('-p', nargs='?',type = str, default="FVP",help="Platform for running")
Christophe Favergeon2942a332020-01-20 14:18:48 +0100127
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200128parser.add_argument('-db', nargs='?',type = str,help="Benchmark database")
129parser.add_argument('-regdb', nargs='?',type = str,help="Regression database")
130parser.add_argument('-sqlite', nargs='?',default="/usr/bin/sqlite3",type = str,help="Regression database")
131
132parser.add_argument('-debug', action='store_true', help="Debug mode")
133
Christophe Favergeon2942a332020-01-20 14:18:48 +0100134args = parser.parse_args()
135
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200136if args.debug:
137 setDebugMode()
138
139# Create missing database files
140# if the db arguments are specified
141if args.db is not None:
142 if not os.path.exists(args.db):
143 createDb(args.sqlite,args.db)
144
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200145 conn = sqlite3.connect(args.db)
146 try:
147 currentID = getLastRunID(conn)
148 benchID = currentID + 1
149 addNewID(conn,benchID)
150 finally:
151 conn.close()
152
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200153if args.regdb is not None:
154 if not os.path.exists(args.regdb):
155 createDb(args.sqlite,args.regdb)
156
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200157 conn = sqlite3.connect(args.regdb)
158 try:
159 currentID = getLastRunID(conn)
160 regID = currentID + 1
161 addNewID(conn,regID)
162 finally:
163 conn.close()
164
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200165
Christophe Favergeon512b1482020-02-07 11:25:11 +0100166with open(args.i,"r") as f:
167 config=yaml.safe_load(f)
168
169#print(config)
170
171#print(config["IMPLIEDFLAGS"])
172
Christophe Favergeon512b1482020-02-07 11:25:11 +0100173
Christophe Favergeon830283b2020-04-27 14:51:08 +0200174
175
176flags = config["FLAGS"]
177allConfigs = analyzeFlags(flags)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100178
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200179if isDebugMode():
Christophe Favergeon512b1482020-02-07 11:25:11 +0100180 allConfigs=[allConfigs[0]]
Christophe Favergeon512b1482020-02-07 11:25:11 +0100181
182failedBuild = {}
183# Test all builds
184
185folderCreated=False
186
187def logFailedBuild(root,f):
188 with open(os.path.join(fullTestFolder(root),"buildStatus_%d.txt" % args.n),"w") as status:
189 for build in f:
190 s = f[build]
191 if s == MAKEFAILED:
192 status.write("%s : Make failure\n" % build)
193 if s == TESTFAILED:
194 status.write("%s : Test failure\n" % build)
195 if s == FLOWFAILURE:
196 status.write("%s : Flow failure\n" % build)
197 if s == CALLFAILURE:
198 status.write("%s : Subprocess failure\n" % build)
Christophe Favergeon2942a332020-01-20 14:18:48 +0100199
Christophe Favergeon00e50db2020-01-21 07:10:26 +0100200
Christophe Favergeon830283b2020-04-27 14:51:08 +0200201def buildAndTest(compiler,theConfig,cmake,sim):
Christophe Favergeon512b1482020-02-07 11:25:11 +0100202 # Run all tests for AC6
203 try:
204 for core in config['CORES']:
205 configNb = 0
206 if compiler in config['CORES'][core]:
Christophe Favergeon830283b2020-04-27 14:51:08 +0200207 msg("Testing Core %s\n" % core)
208 for flagConfig in theConfig:
Christophe Favergeon512b1482020-02-07 11:25:11 +0100209 folderCreated = False
210 configNb = configNb + 1
211 buildStr = "build_%s_%s_%d" % (compiler,core,configNb)
212 toUnset = None
Christophe Favergeon64b748b2020-02-20 08:58:06 +0000213 toSet = None
214
Christophe Favergeon830283b2020-04-27 14:51:08 +0200215 if 'UNSET' in config:
216 if compiler in config['UNSET']:
217 if core in config['UNSET'][compiler]:
218 toUnset = config['UNSET'][compiler][core]
Christophe Favergeon64b748b2020-02-20 08:58:06 +0000219
Christophe Favergeon830283b2020-04-27 14:51:08 +0200220 if 'SET' in config:
221 if compiler in config['SET']:
222 if core in config['SET'][compiler]:
223 toSet = config['SET'][compiler][core]
Christophe Favergeon64b748b2020-02-20 08:58:06 +0000224
225 build = BuildConfig(toUnset,toSet,args.r,
Christophe Favergeon512b1482020-02-07 11:25:11 +0100226 buildStr,
227 config['COMPILERS'][core][compiler],
Christophe Favergeon830283b2020-04-27 14:51:08 +0200228 cmake,
Christophe Favergeon512b1482020-02-07 11:25:11 +0100229 config['CORES'][core][compiler],
230 config["CMAKE"]
231 )
232
233 flags = []
234 if core in config["IMPLIEDFLAGS"]:
235 flags += config["IMPLIEDFLAGS"][core]
236 flags += flagConfig
237
238 if compiler in config["IMPLIEDFLAGS"]:
239 flags += config["IMPLIEDFLAGS"][compiler]
240
241 build.createFolder()
242 # Run all tests for the build
243 testStatusForThisBuild = NOTESTFAILED
244 try:
245 # This is saving the flag configuration
246 build.createArchive(flags)
Christophe Favergeon830283b2020-04-27 14:51:08 +0200247 msg("Config " + str(flagConfig) + "\n")
248
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200249 build.createCMake(core,flags,args.b,args.p)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100250 for test in config["TESTS"]:
251 msg(test["testName"]+"\n")
252 testClass=test["testClass"]
253 test = build.getTest(testClass)
254 fvp = None
Christophe Favergeon830283b2020-04-27 14:51:08 +0200255 if 'FVP' in config:
256 if core in config['FVP']:
257 fvp = config['FVP'][core]
258 if 'SIM' in config:
259 if core in config['SIM']:
260 fvp = config['SIM'][core]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200261 newTestStatus = test.runAndProcess(compiler,fvp,sim,args.b,args.db,args.regdb,benchID,regID)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100262 testStatusForThisBuild = updateTestStatus(testStatusForThisBuild,newTestStatus)
263 if testStatusForThisBuild != NOTESTFAILED:
264 failedBuild[buildStr] = testStatusForThisBuild
265 # Final script status
266 testFailed = 1
267 build.archiveResults()
268 finally:
269 build.cleanFolder()
270 else:
271 msg("No toolchain %s for core %s" % (compiler,core))
272
273 except TestFlowFailure as flow:
274 errorMsg("Error flow id %d\n" % flow.errorCode())
275 failedBuild[buildStr] = FLOWFAILURE
276 logFailedBuild(args.r,failedBuild)
277 sys.exit(1)
278 except CallFailure:
279 errorMsg("Call failure\n")
280 failedBuild[buildStr] = CALLFAILURE
281 logFailedBuild(args.r,failedBuild)
282 sys.exit(1)
Christophe Favergeon00e50db2020-01-21 07:10:26 +0100283
Christophe Favergeon512b1482020-02-07 11:25:11 +0100284############## Builds for all toolchains
Christophe Favergeon2942a332020-01-20 14:18:48 +0100285
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200286if not isDebugMode():
Christophe Favergeon830283b2020-04-27 14:51:08 +0200287 preprocess(args.f)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100288 generateAllCCode()
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200289else:
290 msg("Debug Mode\n")
Christophe Favergeon2942a332020-01-20 14:18:48 +0100291
Christophe Favergeon512b1482020-02-07 11:25:11 +0100292for t in config["TOOLCHAINS"]:
Christophe Favergeon830283b2020-04-27 14:51:08 +0200293 cmake,localConfig,sim = analyzeToolchain(config["TOOLCHAINS"][t],allConfigs)
294 msg("Testing toolchain %s\n" % cmake)
295 buildAndTest(t,localConfig,cmake,sim)
296
Christophe Favergeon2942a332020-01-20 14:18:48 +0100297
Christophe Favergeon512b1482020-02-07 11:25:11 +0100298logFailedBuild(args.r,failedBuild)
299sys.exit(testFailed)
300