blob: 08f9f986270e6d66369950bde688693d8a0d9d25 [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
111 if compiler in config['UNSET']:
112 if core in config['UNSET'][compiler]:
113 toUnset = config['UNSET'][compiler][core]
114 build = BuildConfig(toUnset,args.r,
115 buildStr,
116 config['COMPILERS'][core][compiler],
117 config['TOOLCHAINS'][compiler],
118 config['CORES'][core][compiler],
119 config["CMAKE"]
120 )
121
122 flags = []
123 if core in config["IMPLIEDFLAGS"]:
124 flags += config["IMPLIEDFLAGS"][core]
125 flags += flagConfig
126
127 if compiler in config["IMPLIEDFLAGS"]:
128 flags += config["IMPLIEDFLAGS"][compiler]
129
130 build.createFolder()
131 # Run all tests for the build
132 testStatusForThisBuild = NOTESTFAILED
133 try:
134 # This is saving the flag configuration
135 build.createArchive(flags)
136
137 build.createCMake(flags)
138 for test in config["TESTS"]:
139 msg(test["testName"]+"\n")
140 testClass=test["testClass"]
141 test = build.getTest(testClass)
142 fvp = None
143 if core in config['FVP']:
144 fvp = config['FVP'][core]
145 newTestStatus = test.runAndProcess(compiler,fvp)
146 testStatusForThisBuild = updateTestStatus(testStatusForThisBuild,newTestStatus)
147 if testStatusForThisBuild != NOTESTFAILED:
148 failedBuild[buildStr] = testStatusForThisBuild
149 # Final script status
150 testFailed = 1
151 build.archiveResults()
152 finally:
153 build.cleanFolder()
154 else:
155 msg("No toolchain %s for core %s" % (compiler,core))
156
157 except TestFlowFailure as flow:
158 errorMsg("Error flow id %d\n" % flow.errorCode())
159 failedBuild[buildStr] = FLOWFAILURE
160 logFailedBuild(args.r,failedBuild)
161 sys.exit(1)
162 except CallFailure:
163 errorMsg("Call failure\n")
164 failedBuild[buildStr] = CALLFAILURE
165 logFailedBuild(args.r,failedBuild)
166 sys.exit(1)
Christophe Favergeon00e50db2020-01-21 07:10:26 +0100167
Christophe Favergeon512b1482020-02-07 11:25:11 +0100168############## Builds for all toolchains
Christophe Favergeon2942a332020-01-20 14:18:48 +0100169
Christophe Favergeon512b1482020-02-07 11:25:11 +0100170if not DEBUGMODE:
171 preprocess()
172 generateAllCCode()
Christophe Favergeon2942a332020-01-20 14:18:48 +0100173
Christophe Favergeon512b1482020-02-07 11:25:11 +0100174for t in config["TOOLCHAINS"]:
175 msg("Testing toolchain %s\n" % t)
176 buildAndTest(t)
Christophe Favergeon2942a332020-01-20 14:18:48 +0100177
Christophe Favergeon512b1482020-02-07 11:25:11 +0100178logFailedBuild(args.r,failedBuild)
179sys.exit(testFailed)
180