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 | |
| 42 | root = Path(os.getcwd()).parent.parent.parent |
| 43 | |
| 44 | |
| 45 | def cartesian(*somelists): |
| 46 | r=[] |
| 47 | for element in itertools.product(*somelists): |
| 48 | r.append(list(element)) |
| 49 | return(r) |
| 50 | |
| 51 | testFailed = 0 |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 52 | |
| 53 | init() |
| 54 | |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 55 | parser = argparse.ArgumentParser(description='Parse test description') |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame^] | 56 | parser.add_argument('-i', nargs='?',type = str, default="testrunConfig.yaml",help="Config file") |
| 57 | parser.add_argument('-r', nargs='?',type = str, default=root, help="Root folder") |
| 58 | parser.add_argument('-n', nargs='?',type = int, default=0, help="ID value when launchign in parallel") |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 59 | |
| 60 | args = parser.parse_args() |
| 61 | |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 62 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame^] | 63 | with open(args.i,"r") as f: |
| 64 | config=yaml.safe_load(f) |
| 65 | |
| 66 | #print(config) |
| 67 | |
| 68 | #print(config["IMPLIEDFLAGS"]) |
| 69 | |
| 70 | flags = config["FLAGS"] |
| 71 | onoffFlags = [] |
| 72 | for f in flags: |
| 73 | onoffFlags.append(["-D" + f +"=ON","-D" + f +"=OFF"]) |
| 74 | |
| 75 | allConfigs=cartesian(*onoffFlags) |
| 76 | |
| 77 | if DEBUGMODE: |
| 78 | allConfigs=[allConfigs[0]] |
| 79 | |
| 80 | |
| 81 | failedBuild = {} |
| 82 | # Test all builds |
| 83 | |
| 84 | folderCreated=False |
| 85 | |
| 86 | def 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 Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 98 | |
Christophe Favergeon | 00e50db | 2020-01-21 07:10:26 +0100 | [diff] [blame] | 99 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame^] | 100 | def 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 Favergeon | 00e50db | 2020-01-21 07:10:26 +0100 | [diff] [blame] | 167 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame^] | 168 | ############## Builds for all toolchains |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 169 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame^] | 170 | if not DEBUGMODE: |
| 171 | preprocess() |
| 172 | generateAllCCode() |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 173 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame^] | 174 | for t in config["TOOLCHAINS"]: |
| 175 | msg("Testing toolchain %s\n" % t) |
| 176 | buildAndTest(t) |
Christophe Favergeon | 2942a33 | 2020-01-20 14:18:48 +0100 | [diff] [blame] | 177 | |
Christophe Favergeon | 512b148 | 2020-02-07 11:25:11 +0100 | [diff] [blame^] | 178 | logFailedBuild(args.r,failedBuild) |
| 179 | sys.exit(testFailed) |
| 180 | |