Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 1 | import os |
| 2 | import os.path |
| 3 | import subprocess |
| 4 | import colorama |
| 5 | from colorama import init,Fore, Back, Style |
| 6 | import argparse |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 7 | from TestScripts.Regression.Commands import * |
| 8 | import yaml |
| 9 | import sys |
| 10 | import itertools |
| 11 | from pathlib import Path |
| 12 | |
| 13 | |
| 14 | # Small state machine |
| 15 | def 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 Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 42 | # Analyze the configuration flags (like loopunroll etc ...) |
| 43 | def 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 |
| 65 | def 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 Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 83 | |
| 84 | |
| 85 | def cartesian(*somelists): |
| 86 | r=[] |
| 87 | for element in itertools.product(*somelists): |
| 88 | r.append(list(element)) |
| 89 | return(r) |
| 90 | |
Christophe Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 91 | root = Path(os.getcwd()).parent.parent.parent |
| 92 | |
| 93 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 94 | testFailed = 0 |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 95 | |
| 96 | init() |
| 97 | |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 98 | parser = argparse.ArgumentParser(description='Parse test description') |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 99 | parser.add_argument('-i', nargs='?',type = str, default="testrunConfig.yaml",help="Config file") |
| 100 | parser.add_argument('-r', nargs='?',type = str, default=root, help="Root folder") |
Christophe Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 101 | parser.add_argument('-n', nargs='?',type = int, default=0, help="ID value when launching in parallel") |
| 102 | parser.add_argument('-b', action='store_true', help="Benchmark mode") |
| 103 | parser.add_argument('-f', nargs='?',type = str, default="desc.txt",help="Test description file") |
| 104 | parser.add_argument('-p', nargs='?',type = str, default="FVP",help="Platform for running") |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 105 | |
| 106 | args = parser.parse_args() |
| 107 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 108 | with open(args.i,"r") as f: |
| 109 | config=yaml.safe_load(f) |
| 110 | |
| 111 | #print(config) |
| 112 | |
| 113 | #print(config["IMPLIEDFLAGS"]) |
| 114 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 115 | |
Christophe Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 116 | |
| 117 | |
| 118 | flags = config["FLAGS"] |
| 119 | allConfigs = analyzeFlags(flags) |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 120 | |
| 121 | if DEBUGMODE: |
| 122 | allConfigs=[allConfigs[0]] |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 123 | |
| 124 | failedBuild = {} |
| 125 | # Test all builds |
| 126 | |
| 127 | folderCreated=False |
| 128 | |
| 129 | def 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 Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 141 | |
Christophe Favergeon | 00e50db | 2020-01-21 07:10:26 +0100 | [diff] [blame] | 142 | |
Christophe Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 143 | def buildAndTest(compiler,theConfig,cmake,sim): |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 144 | # Run all tests for AC6 |
| 145 | try: |
| 146 | for core in config['CORES']: |
| 147 | configNb = 0 |
| 148 | if compiler in config['CORES'][core]: |
Christophe Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 149 | msg("Testing Core %s\n" % core) |
| 150 | for flagConfig in theConfig: |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 151 | folderCreated = False |
| 152 | configNb = configNb + 1 |
| 153 | buildStr = "build_%s_%s_%d" % (compiler,core,configNb) |
| 154 | toUnset = None |
Christophe Favergeon | 64b748b | 2020-02-20 08:58:06 +0000 | [diff] [blame] | 155 | toSet = None |
| 156 | |
Christophe Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 157 | if 'UNSET' in config: |
| 158 | if compiler in config['UNSET']: |
| 159 | if core in config['UNSET'][compiler]: |
| 160 | toUnset = config['UNSET'][compiler][core] |
Christophe Favergeon | 64b748b | 2020-02-20 08:58:06 +0000 | [diff] [blame] | 161 | |
Christophe Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 162 | if 'SET' in config: |
| 163 | if compiler in config['SET']: |
| 164 | if core in config['SET'][compiler]: |
| 165 | toSet = config['SET'][compiler][core] |
Christophe Favergeon | 64b748b | 2020-02-20 08:58:06 +0000 | [diff] [blame] | 166 | |
| 167 | build = BuildConfig(toUnset,toSet,args.r, |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 168 | buildStr, |
| 169 | config['COMPILERS'][core][compiler], |
Christophe Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 170 | cmake, |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 171 | 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 Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 189 | msg("Config " + str(flagConfig) + "\n") |
| 190 | |
| 191 | build.createCMake(flags,args.b,args.p) |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 192 | for test in config["TESTS"]: |
| 193 | msg(test["testName"]+"\n") |
| 194 | testClass=test["testClass"] |
| 195 | test = build.getTest(testClass) |
| 196 | fvp = None |
Christophe Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 197 | 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 Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 204 | 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 Favergeon | 00e50db | 2020-01-21 07:10:26 +0100 | [diff] [blame] | 225 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 226 | ############## Builds for all toolchains |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 227 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 228 | if not DEBUGMODE: |
Christophe Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 229 | preprocess(args.f) |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 230 | generateAllCCode() |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 231 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 232 | for t in config["TOOLCHAINS"]: |
Christophe Favergeon | 830283b | 2020-04-27 14:51:08 +0200 | [diff] [blame^] | 233 | cmake,localConfig,sim = analyzeToolchain(config["TOOLCHAINS"][t],allConfigs) |
| 234 | msg("Testing toolchain %s\n" % cmake) |
| 235 | buildAndTest(t,localConfig,cmake,sim) |
| 236 | |
| 237 | exit(1) |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 238 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame] | 239 | logFailedBuild(args.r,failedBuild) |
| 240 | sys.exit(testFailed) |
| 241 | |