blob: e67531a1a6183c4b78d8eb06c0ff12e846e5fb56 [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
42root = Path(os.getcwd()).parent.parent.parent
43
44
45def cartesian(*somelists):
46 r=[]
47 for element in itertools.product(*somelists):
48 r.append(list(element))
49 return(r)
50
51testFailed = 0
Christophe Favergeon2942a332020-01-20 14:18:48 +010052
53init()
54
Christophe Favergeon2942a332020-01-20 14:18:48 +010055parser = argparse.ArgumentParser(description='Parse test description')
Christophe Favergeon512b1482020-02-07 11:25:11 +010056parser.add_argument('-i', nargs='?',type = str, default="testrunConfig.yaml",help="Config file")
57parser.add_argument('-r', nargs='?',type = str, default=root, help="Root folder")
58parser.add_argument('-n', nargs='?',type = int, default=0, help="ID value when launchign in parallel")
Christophe Favergeon2942a332020-01-20 14:18:48 +010059
60args = parser.parse_args()
61
Christophe Favergeon2942a332020-01-20 14:18:48 +010062
Christophe Favergeon512b1482020-02-07 11:25:11 +010063with open(args.i,"r") as f:
64 config=yaml.safe_load(f)
65
66#print(config)
67
68#print(config["IMPLIEDFLAGS"])
69
70flags = config["FLAGS"]
71onoffFlags = []
72for f in flags:
73 onoffFlags.append(["-D" + f +"=ON","-D" + f +"=OFF"])
74
75allConfigs=cartesian(*onoffFlags)
76
77if DEBUGMODE:
78 allConfigs=[allConfigs[0]]
79
80
81failedBuild = {}
82# Test all builds
83
84folderCreated=False
85
86def logFailedBuild(root,f):
87 with open(os.path.join(fullTestFolder(root),"buildStatus_%d.txt" % args.n),"w") as status:
88 for build in f:
89 s = f[build]
90 if s == MAKEFAILED:
91 status.write("%s : Make failure\n" % build)
92 if s == TESTFAILED:
93 status.write("%s : Test failure\n" % build)
94 if s == FLOWFAILURE:
95 status.write("%s : Flow failure\n" % build)
96 if s == CALLFAILURE:
97 status.write("%s : Subprocess failure\n" % build)
Christophe Favergeon2942a332020-01-20 14:18:48 +010098
Christophe Favergeon00e50db2020-01-21 07:10:26 +010099
Christophe Favergeon512b1482020-02-07 11:25:11 +0100100def buildAndTest(compiler):
101 # Run all tests for AC6
102 try:
103 for core in config['CORES']:
104 configNb = 0
105 if compiler in config['CORES'][core]:
106 for flagConfig in allConfigs:
107 folderCreated = False
108 configNb = configNb + 1
109 buildStr = "build_%s_%s_%d" % (compiler,core,configNb)
110 toUnset = None
Christophe Favergeon64b748b2020-02-20 08:58:06 +0000111 toSet = None
112
Christophe Favergeon512b1482020-02-07 11:25:11 +0100113 if compiler in config['UNSET']:
114 if core in config['UNSET'][compiler]:
115 toUnset = config['UNSET'][compiler][core]
Christophe Favergeon64b748b2020-02-20 08:58:06 +0000116
117 if compiler in config['SET']:
118 if core in config['SET'][compiler]:
119 toSet = config['SET'][compiler][core]
120
121 build = BuildConfig(toUnset,toSet,args.r,
Christophe Favergeon512b1482020-02-07 11:25:11 +0100122 buildStr,
123 config['COMPILERS'][core][compiler],
124 config['TOOLCHAINS'][compiler],
125 config['CORES'][core][compiler],
126 config["CMAKE"]
127 )
128
129 flags = []
130 if core in config["IMPLIEDFLAGS"]:
131 flags += config["IMPLIEDFLAGS"][core]
132 flags += flagConfig
133
134 if compiler in config["IMPLIEDFLAGS"]:
135 flags += config["IMPLIEDFLAGS"][compiler]
136
137 build.createFolder()
138 # Run all tests for the build
139 testStatusForThisBuild = NOTESTFAILED
140 try:
141 # This is saving the flag configuration
142 build.createArchive(flags)
143
144 build.createCMake(flags)
145 for test in config["TESTS"]:
146 msg(test["testName"]+"\n")
147 testClass=test["testClass"]
148 test = build.getTest(testClass)
149 fvp = None
150 if core in config['FVP']:
151 fvp = config['FVP'][core]
152 newTestStatus = test.runAndProcess(compiler,fvp)
153 testStatusForThisBuild = updateTestStatus(testStatusForThisBuild,newTestStatus)
154 if testStatusForThisBuild != NOTESTFAILED:
155 failedBuild[buildStr] = testStatusForThisBuild
156 # Final script status
157 testFailed = 1
158 build.archiveResults()
159 finally:
160 build.cleanFolder()
161 else:
162 msg("No toolchain %s for core %s" % (compiler,core))
163
164 except TestFlowFailure as flow:
165 errorMsg("Error flow id %d\n" % flow.errorCode())
166 failedBuild[buildStr] = FLOWFAILURE
167 logFailedBuild(args.r,failedBuild)
168 sys.exit(1)
169 except CallFailure:
170 errorMsg("Call failure\n")
171 failedBuild[buildStr] = CALLFAILURE
172 logFailedBuild(args.r,failedBuild)
173 sys.exit(1)
Christophe Favergeon00e50db2020-01-21 07:10:26 +0100174
Christophe Favergeon512b1482020-02-07 11:25:11 +0100175############## Builds for all toolchains
Christophe Favergeon2942a332020-01-20 14:18:48 +0100176
Christophe Favergeon512b1482020-02-07 11:25:11 +0100177if not DEBUGMODE:
178 preprocess()
179 generateAllCCode()
Christophe Favergeon2942a332020-01-20 14:18:48 +0100180
Christophe Favergeon512b1482020-02-07 11:25:11 +0100181for t in config["TOOLCHAINS"]:
182 msg("Testing toolchain %s\n" % t)
183 buildAndTest(t)
Christophe Favergeon2942a332020-01-20 14:18:48 +0100184
Christophe Favergeon512b1482020-02-07 11:25:11 +0100185logFailedBuild(args.r,failedBuild)
186sys.exit(testFailed)
187