blob: d1455ed6484162a26460c42122382d79cb0e11f9 [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
12
13
14# Small state machine
15def updateTestStatus(testStatusForThisBuild,newTestStatus):
16 if testStatusForThisBuild == NOTESTFAILED:
17 if newTestStatus == NOTESTFAILED:
18 return(NOTESTFAILED)
19 if newTestStatus == MAKEFAILED:
20 return(MAKEFAILED)
21 if newTestStatus == TESTFAILED:
22 return(TESTFAILED)
23 if testStatusForThisBuild == MAKEFAILED:
24 if newTestStatus == NOTESTFAILED:
25 return(MAKEFAILED)
26 if newTestStatus == MAKEFAILED:
27 return(MAKEFAILED)
28 if newTestStatus == TESTFAILED:
29 return(TESTFAILED)
30 if testStatusForThisBuild == TESTFAILED:
31 if newTestStatus == NOTESTFAILED:
32 return(TESTFAILED)
33 if newTestStatus == MAKEFAILED:
34 return(TESTFAILED)
35 if newTestStatus == TESTFAILED:
36 return(TESTFAILED)
37 if testStatusForThisBuild == FLOWFAILURE:
38 return(testStatusForThisBuild)
39 if testStatusForThisBuild == CALLFAILURE:
40 return(testStatusForThisBuild)
41
Christophe Favergeon830283b2020-04-27 14:51:08 +020042# Analyze the configuration flags (like loopunroll etc ...)
43def analyzeFlags(flags):
44
45 onoffFlags = []
46 for f in flags:
47 if type(f) is dict:
48 for var in f:
49 if type(f[var]) is bool:
50 if f[var]:
51 onoffFlags.append(["-D%s=ON" % (var)])
52 else:
53 onoffFlags.append(["-D%s=OFF" % (var)])
54 else:
55 onoffFlags.append(["-D%s=%s" % (var,f[var])])
56 else:
57 onoffFlags.append(["-D" + f +"=ON","-D" + f +"=OFF"])
58
59 allConfigs=cartesian(*onoffFlags)
60 return(allConfigs)
61
62# Extract the cmake for a specific compiler
63# and the flag configuration to use for this compiler.
64# This flags configuration will override the global one
65def analyzeToolchain(toolchain, globalConfig):
66 config=globalConfig
67 cmake=""
68 sim=True
69 if type(toolchain) is str:
70 cmake=toolchain
71 else:
72 for t in toolchain:
73 if type(t) is dict:
74 if "FLAGS" in t:
75 hasConfig=True
76 config = analyzeFlags(t["FLAGS"])
77 if "SIM" in t:
78 sim = t["SIM"]
79 if type(t) is str:
80 cmake=t
81 return(cmake,config,sim)
82
Christophe Favergeon512b1482020-02-07 11:25:11 +010083
84
85def cartesian(*somelists):
86 r=[]
87 for element in itertools.product(*somelists):
88 r.append(list(element))
89 return(r)
90
Christophe Favergeon830283b2020-04-27 14:51:08 +020091root = Path(os.getcwd()).parent.parent.parent
92
93
Christophe Favergeon512b1482020-02-07 11:25:11 +010094testFailed = 0
Christophe Favergeon2942a332020-01-20 14:18:48 +010095
96init()
97
Christophe Favergeon2942a332020-01-20 14:18:48 +010098parser = argparse.ArgumentParser(description='Parse test description')
Christophe Favergeon512b1482020-02-07 11:25:11 +010099parser.add_argument('-i', nargs='?',type = str, default="testrunConfig.yaml",help="Config file")
100parser.add_argument('-r', nargs='?',type = str, default=root, help="Root folder")
Christophe Favergeon830283b2020-04-27 14:51:08 +0200101parser.add_argument('-n', nargs='?',type = int, default=0, help="ID value when launching in parallel")
102parser.add_argument('-b', action='store_true', help="Benchmark mode")
103parser.add_argument('-f', nargs='?',type = str, default="desc.txt",help="Test description file")
104parser.add_argument('-p', nargs='?',type = str, default="FVP",help="Platform for running")
Christophe Favergeon2942a332020-01-20 14:18:48 +0100105
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200106parser.add_argument('-db', nargs='?',type = str,help="Benchmark database")
107parser.add_argument('-regdb', nargs='?',type = str,help="Regression database")
108parser.add_argument('-sqlite', nargs='?',default="/usr/bin/sqlite3",type = str,help="Regression database")
109
110parser.add_argument('-debug', action='store_true', help="Debug mode")
111
Christophe Favergeon2942a332020-01-20 14:18:48 +0100112args = parser.parse_args()
113
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200114if args.debug:
115 setDebugMode()
116
117# Create missing database files
118# if the db arguments are specified
119if args.db is not None:
120 if not os.path.exists(args.db):
121 createDb(args.sqlite,args.db)
122
123if args.regdb is not None:
124 if not os.path.exists(args.regdb):
125 createDb(args.sqlite,args.regdb)
126
127
Christophe Favergeon512b1482020-02-07 11:25:11 +0100128with open(args.i,"r") as f:
129 config=yaml.safe_load(f)
130
131#print(config)
132
133#print(config["IMPLIEDFLAGS"])
134
Christophe Favergeon512b1482020-02-07 11:25:11 +0100135
Christophe Favergeon830283b2020-04-27 14:51:08 +0200136
137
138flags = config["FLAGS"]
139allConfigs = analyzeFlags(flags)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100140
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200141if isDebugMode():
Christophe Favergeon512b1482020-02-07 11:25:11 +0100142 allConfigs=[allConfigs[0]]
Christophe Favergeon512b1482020-02-07 11:25:11 +0100143
144failedBuild = {}
145# Test all builds
146
147folderCreated=False
148
149def logFailedBuild(root,f):
150 with open(os.path.join(fullTestFolder(root),"buildStatus_%d.txt" % args.n),"w") as status:
151 for build in f:
152 s = f[build]
153 if s == MAKEFAILED:
154 status.write("%s : Make failure\n" % build)
155 if s == TESTFAILED:
156 status.write("%s : Test failure\n" % build)
157 if s == FLOWFAILURE:
158 status.write("%s : Flow failure\n" % build)
159 if s == CALLFAILURE:
160 status.write("%s : Subprocess failure\n" % build)
Christophe Favergeon2942a332020-01-20 14:18:48 +0100161
Christophe Favergeon00e50db2020-01-21 07:10:26 +0100162
Christophe Favergeon830283b2020-04-27 14:51:08 +0200163def buildAndTest(compiler,theConfig,cmake,sim):
Christophe Favergeon512b1482020-02-07 11:25:11 +0100164 # Run all tests for AC6
165 try:
166 for core in config['CORES']:
167 configNb = 0
168 if compiler in config['CORES'][core]:
Christophe Favergeon830283b2020-04-27 14:51:08 +0200169 msg("Testing Core %s\n" % core)
170 for flagConfig in theConfig:
Christophe Favergeon512b1482020-02-07 11:25:11 +0100171 folderCreated = False
172 configNb = configNb + 1
173 buildStr = "build_%s_%s_%d" % (compiler,core,configNb)
174 toUnset = None
Christophe Favergeon64b748b2020-02-20 08:58:06 +0000175 toSet = None
176
Christophe Favergeon830283b2020-04-27 14:51:08 +0200177 if 'UNSET' in config:
178 if compiler in config['UNSET']:
179 if core in config['UNSET'][compiler]:
180 toUnset = config['UNSET'][compiler][core]
Christophe Favergeon64b748b2020-02-20 08:58:06 +0000181
Christophe Favergeon830283b2020-04-27 14:51:08 +0200182 if 'SET' in config:
183 if compiler in config['SET']:
184 if core in config['SET'][compiler]:
185 toSet = config['SET'][compiler][core]
Christophe Favergeon64b748b2020-02-20 08:58:06 +0000186
187 build = BuildConfig(toUnset,toSet,args.r,
Christophe Favergeon512b1482020-02-07 11:25:11 +0100188 buildStr,
189 config['COMPILERS'][core][compiler],
Christophe Favergeon830283b2020-04-27 14:51:08 +0200190 cmake,
Christophe Favergeon512b1482020-02-07 11:25:11 +0100191 config['CORES'][core][compiler],
192 config["CMAKE"]
193 )
194
195 flags = []
196 if core in config["IMPLIEDFLAGS"]:
197 flags += config["IMPLIEDFLAGS"][core]
198 flags += flagConfig
199
200 if compiler in config["IMPLIEDFLAGS"]:
201 flags += config["IMPLIEDFLAGS"][compiler]
202
203 build.createFolder()
204 # Run all tests for the build
205 testStatusForThisBuild = NOTESTFAILED
206 try:
207 # This is saving the flag configuration
208 build.createArchive(flags)
Christophe Favergeon830283b2020-04-27 14:51:08 +0200209 msg("Config " + str(flagConfig) + "\n")
210
211 build.createCMake(flags,args.b,args.p)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100212 for test in config["TESTS"]:
213 msg(test["testName"]+"\n")
214 testClass=test["testClass"]
215 test = build.getTest(testClass)
216 fvp = None
Christophe Favergeon830283b2020-04-27 14:51:08 +0200217 if 'FVP' in config:
218 if core in config['FVP']:
219 fvp = config['FVP'][core]
220 if 'SIM' in config:
221 if core in config['SIM']:
222 fvp = config['SIM'][core]
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200223 newTestStatus = test.runAndProcess(compiler,fvp,sim,args.b,args.db,args.regdb)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100224 testStatusForThisBuild = updateTestStatus(testStatusForThisBuild,newTestStatus)
225 if testStatusForThisBuild != NOTESTFAILED:
226 failedBuild[buildStr] = testStatusForThisBuild
227 # Final script status
228 testFailed = 1
229 build.archiveResults()
230 finally:
231 build.cleanFolder()
232 else:
233 msg("No toolchain %s for core %s" % (compiler,core))
234
235 except TestFlowFailure as flow:
236 errorMsg("Error flow id %d\n" % flow.errorCode())
237 failedBuild[buildStr] = FLOWFAILURE
238 logFailedBuild(args.r,failedBuild)
239 sys.exit(1)
240 except CallFailure:
241 errorMsg("Call failure\n")
242 failedBuild[buildStr] = CALLFAILURE
243 logFailedBuild(args.r,failedBuild)
244 sys.exit(1)
Christophe Favergeon00e50db2020-01-21 07:10:26 +0100245
Christophe Favergeon512b1482020-02-07 11:25:11 +0100246############## Builds for all toolchains
Christophe Favergeon2942a332020-01-20 14:18:48 +0100247
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200248if not isDebugMode():
Christophe Favergeon830283b2020-04-27 14:51:08 +0200249 preprocess(args.f)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100250 generateAllCCode()
Christophe Favergeon1a668e02020-05-06 12:45:50 +0200251else:
252 msg("Debug Mode\n")
Christophe Favergeon2942a332020-01-20 14:18:48 +0100253
Christophe Favergeon512b1482020-02-07 11:25:11 +0100254for t in config["TOOLCHAINS"]:
Christophe Favergeon830283b2020-04-27 14:51:08 +0200255 cmake,localConfig,sim = analyzeToolchain(config["TOOLCHAINS"][t],allConfigs)
256 msg("Testing toolchain %s\n" % cmake)
257 buildAndTest(t,localConfig,cmake,sim)
258
Christophe Favergeon2942a332020-01-20 14:18:48 +0100259
Christophe Favergeon512b1482020-02-07 11:25:11 +0100260logFailedBuild(args.r,failedBuild)
261sys.exit(testFailed)
262