blob: 816f70b9390faedb44b780e35f61b115f4a279a6 [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
106args = parser.parse_args()
107
Christophe Favergeon512b1482020-02-07 11:25:11 +0100108with open(args.i,"r") as f:
109 config=yaml.safe_load(f)
110
111#print(config)
112
113#print(config["IMPLIEDFLAGS"])
114
Christophe Favergeon512b1482020-02-07 11:25:11 +0100115
Christophe Favergeon830283b2020-04-27 14:51:08 +0200116
117
118flags = config["FLAGS"]
119allConfigs = analyzeFlags(flags)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100120
121if DEBUGMODE:
122 allConfigs=[allConfigs[0]]
Christophe Favergeon512b1482020-02-07 11:25:11 +0100123
124failedBuild = {}
125# Test all builds
126
127folderCreated=False
128
129def logFailedBuild(root,f):
130 with open(os.path.join(fullTestFolder(root),"buildStatus_%d.txt" % args.n),"w") as status:
131 for build in f:
132 s = f[build]
133 if s == MAKEFAILED:
134 status.write("%s : Make failure\n" % build)
135 if s == TESTFAILED:
136 status.write("%s : Test failure\n" % build)
137 if s == FLOWFAILURE:
138 status.write("%s : Flow failure\n" % build)
139 if s == CALLFAILURE:
140 status.write("%s : Subprocess failure\n" % build)
Christophe Favergeon2942a332020-01-20 14:18:48 +0100141
Christophe Favergeon00e50db2020-01-21 07:10:26 +0100142
Christophe Favergeon830283b2020-04-27 14:51:08 +0200143def buildAndTest(compiler,theConfig,cmake,sim):
Christophe Favergeon512b1482020-02-07 11:25:11 +0100144 # Run all tests for AC6
145 try:
146 for core in config['CORES']:
147 configNb = 0
148 if compiler in config['CORES'][core]:
Christophe Favergeon830283b2020-04-27 14:51:08 +0200149 msg("Testing Core %s\n" % core)
150 for flagConfig in theConfig:
Christophe Favergeon512b1482020-02-07 11:25:11 +0100151 folderCreated = False
152 configNb = configNb + 1
153 buildStr = "build_%s_%s_%d" % (compiler,core,configNb)
154 toUnset = None
Christophe Favergeon64b748b2020-02-20 08:58:06 +0000155 toSet = None
156
Christophe Favergeon830283b2020-04-27 14:51:08 +0200157 if 'UNSET' in config:
158 if compiler in config['UNSET']:
159 if core in config['UNSET'][compiler]:
160 toUnset = config['UNSET'][compiler][core]
Christophe Favergeon64b748b2020-02-20 08:58:06 +0000161
Christophe Favergeon830283b2020-04-27 14:51:08 +0200162 if 'SET' in config:
163 if compiler in config['SET']:
164 if core in config['SET'][compiler]:
165 toSet = config['SET'][compiler][core]
Christophe Favergeon64b748b2020-02-20 08:58:06 +0000166
167 build = BuildConfig(toUnset,toSet,args.r,
Christophe Favergeon512b1482020-02-07 11:25:11 +0100168 buildStr,
169 config['COMPILERS'][core][compiler],
Christophe Favergeon830283b2020-04-27 14:51:08 +0200170 cmake,
Christophe Favergeon512b1482020-02-07 11:25:11 +0100171 config['CORES'][core][compiler],
172 config["CMAKE"]
173 )
174
175 flags = []
176 if core in config["IMPLIEDFLAGS"]:
177 flags += config["IMPLIEDFLAGS"][core]
178 flags += flagConfig
179
180 if compiler in config["IMPLIEDFLAGS"]:
181 flags += config["IMPLIEDFLAGS"][compiler]
182
183 build.createFolder()
184 # Run all tests for the build
185 testStatusForThisBuild = NOTESTFAILED
186 try:
187 # This is saving the flag configuration
188 build.createArchive(flags)
Christophe Favergeon830283b2020-04-27 14:51:08 +0200189 msg("Config " + str(flagConfig) + "\n")
190
191 build.createCMake(flags,args.b,args.p)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100192 for test in config["TESTS"]:
193 msg(test["testName"]+"\n")
194 testClass=test["testClass"]
195 test = build.getTest(testClass)
196 fvp = None
Christophe Favergeon830283b2020-04-27 14:51:08 +0200197 if 'FVP' in config:
198 if core in config['FVP']:
199 fvp = config['FVP'][core]
200 if 'SIM' in config:
201 if core in config['SIM']:
202 fvp = config['SIM'][core]
203 newTestStatus = test.runAndProcess(compiler,fvp,sim)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100204 testStatusForThisBuild = updateTestStatus(testStatusForThisBuild,newTestStatus)
205 if testStatusForThisBuild != NOTESTFAILED:
206 failedBuild[buildStr] = testStatusForThisBuild
207 # Final script status
208 testFailed = 1
209 build.archiveResults()
210 finally:
211 build.cleanFolder()
212 else:
213 msg("No toolchain %s for core %s" % (compiler,core))
214
215 except TestFlowFailure as flow:
216 errorMsg("Error flow id %d\n" % flow.errorCode())
217 failedBuild[buildStr] = FLOWFAILURE
218 logFailedBuild(args.r,failedBuild)
219 sys.exit(1)
220 except CallFailure:
221 errorMsg("Call failure\n")
222 failedBuild[buildStr] = CALLFAILURE
223 logFailedBuild(args.r,failedBuild)
224 sys.exit(1)
Christophe Favergeon00e50db2020-01-21 07:10:26 +0100225
Christophe Favergeon512b1482020-02-07 11:25:11 +0100226############## Builds for all toolchains
Christophe Favergeon2942a332020-01-20 14:18:48 +0100227
Christophe Favergeon512b1482020-02-07 11:25:11 +0100228if not DEBUGMODE:
Christophe Favergeon830283b2020-04-27 14:51:08 +0200229 preprocess(args.f)
Christophe Favergeon512b1482020-02-07 11:25:11 +0100230 generateAllCCode()
Christophe Favergeon2942a332020-01-20 14:18:48 +0100231
Christophe Favergeon512b1482020-02-07 11:25:11 +0100232for t in config["TOOLCHAINS"]:
Christophe Favergeon830283b2020-04-27 14:51:08 +0200233 cmake,localConfig,sim = analyzeToolchain(config["TOOLCHAINS"][t],allConfigs)
234 msg("Testing toolchain %s\n" % cmake)
235 buildAndTest(t,localConfig,cmake,sim)
236
237exit(1)
Christophe Favergeon2942a332020-01-20 14:18:48 +0100238
Christophe Favergeon512b1482020-02-07 11:25:11 +0100239logFailedBuild(args.r,failedBuild)
240sys.exit(testFailed)
241