runAllTests.py 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. import os
  2. import os.path
  3. import subprocess
  4. import colorama
  5. from colorama import init,Fore, Back, Style
  6. import argparse
  7. from TestScripts.Regression.Commands import *
  8. import yaml
  9. import sys
  10. import itertools
  11. from pathlib import Path
  12. import sqlite3
  13. # Command to get last runid
  14. lastID="""SELECT runid FROM RUN ORDER BY runid DESC LIMIT 1
  15. """
  16. addNewIDCmd="""INSERT INTO RUN VALUES(?,date('now'))
  17. """
  18. benchID = 0
  19. regID = 0
  20. def getLastRunID(c):
  21. r=c.execute(lastID)
  22. result=r.fetchone()
  23. if result is None:
  24. return(0)
  25. else:
  26. return(int(result[0]))
  27. def addNewID(c,newid):
  28. c.execute(addNewIDCmd,(newid,))
  29. c.commit()
  30. # Small state machine
  31. def updateTestStatus(testStatusForThisBuild,newTestStatus):
  32. if testStatusForThisBuild == NOTESTFAILED:
  33. if newTestStatus == NOTESTFAILED:
  34. return(NOTESTFAILED)
  35. if newTestStatus == MAKEFAILED:
  36. return(MAKEFAILED)
  37. if newTestStatus == TESTFAILED:
  38. return(TESTFAILED)
  39. if testStatusForThisBuild == MAKEFAILED:
  40. if newTestStatus == NOTESTFAILED:
  41. return(MAKEFAILED)
  42. if newTestStatus == MAKEFAILED:
  43. return(MAKEFAILED)
  44. if newTestStatus == TESTFAILED:
  45. return(TESTFAILED)
  46. if testStatusForThisBuild == TESTFAILED:
  47. if newTestStatus == NOTESTFAILED:
  48. return(TESTFAILED)
  49. if newTestStatus == MAKEFAILED:
  50. return(TESTFAILED)
  51. if newTestStatus == TESTFAILED:
  52. return(TESTFAILED)
  53. if testStatusForThisBuild == FLOWFAILURE:
  54. return(testStatusForThisBuild)
  55. if testStatusForThisBuild == CALLFAILURE:
  56. return(testStatusForThisBuild)
  57. # Analyze the configuration flags (like loopunroll etc ...)
  58. def analyzeFlags(flags):
  59. onoffFlags = []
  60. for f in flags:
  61. if type(f) is dict:
  62. for var in f:
  63. if type(f[var]) is bool:
  64. if f[var]:
  65. onoffFlags.append(["-D%s=ON" % (var)])
  66. else:
  67. onoffFlags.append(["-D%s=OFF" % (var)])
  68. else:
  69. onoffFlags.append(["-D%s=%s" % (var,f[var])])
  70. else:
  71. onoffFlags.append(["-D" + f +"=ON","-D" + f +"=OFF"])
  72. allConfigs=cartesian(*onoffFlags)
  73. return(allConfigs)
  74. # Extract the cmake for a specific compiler
  75. # and the flag configuration to use for this compiler.
  76. # This flags configuration will override the global one
  77. def analyzeToolchain(toolchain, globalConfig):
  78. config=globalConfig
  79. cmake=""
  80. sim=True
  81. if type(toolchain) is str:
  82. cmake=toolchain
  83. else:
  84. for t in toolchain:
  85. if type(t) is dict:
  86. if "FLAGS" in t:
  87. hasConfig=True
  88. config = analyzeFlags(t["FLAGS"])
  89. if "SIM" in t:
  90. sim = t["SIM"]
  91. if type(t) is str:
  92. cmake=t
  93. return(cmake,config,sim)
  94. def cartesian(*somelists):
  95. r=[]
  96. for element in itertools.product(*somelists):
  97. r.append(list(element))
  98. return(r)
  99. root = Path(os.getcwd()).parent.parent.parent
  100. testFailed = 0
  101. init()
  102. parser = argparse.ArgumentParser(description='Parse test description')
  103. parser.add_argument('-i', nargs='?',type = str, default="testrunConfig.yaml",help="Config file")
  104. parser.add_argument('-r', nargs='?',type = str, default=root, help="Root folder")
  105. parser.add_argument('-n', nargs='?',type = int, default=0, help="ID value when launching in parallel")
  106. parser.add_argument('-b', action='store_true', help="Benchmark mode")
  107. parser.add_argument('-f', nargs='?',type = str, default="desc.txt",help="Test description file")
  108. parser.add_argument('-p', nargs='?',type = str, default="FVP",help="Platform for running")
  109. parser.add_argument('-db', nargs='?',type = str,help="Benchmark database")
  110. parser.add_argument('-regdb', nargs='?',type = str,help="Regression database")
  111. parser.add_argument('-sqlite', nargs='?',default="/usr/bin/sqlite3",type = str,help="Regression database")
  112. parser.add_argument('-debug', action='store_true', help="Debug mode")
  113. parser.add_argument('-keep', action='store_true', help="Keep build folder")
  114. args = parser.parse_args()
  115. if args.debug:
  116. setDebugMode()
  117. if args.keep:
  118. setKeepBuildFolder()
  119. # Create missing database files
  120. # if the db arguments are specified
  121. if args.db is not None:
  122. if not os.path.exists(args.db):
  123. createDb(args.sqlite,args.db)
  124. conn = sqlite3.connect(args.db)
  125. try:
  126. currentID = getLastRunID(conn)
  127. benchID = currentID + 1
  128. addNewID(conn,benchID)
  129. finally:
  130. conn.close()
  131. if args.regdb is not None:
  132. if not os.path.exists(args.regdb):
  133. createDb(args.sqlite,args.regdb)
  134. conn = sqlite3.connect(args.regdb)
  135. try:
  136. currentID = getLastRunID(conn)
  137. regID = currentID + 1
  138. addNewID(conn,regID)
  139. finally:
  140. conn.close()
  141. with open(args.i,"r") as f:
  142. config=yaml.safe_load(f)
  143. #print(config)
  144. #print(config["IMPLIEDFLAGS"])
  145. flags = config["FLAGS"]
  146. allConfigs = analyzeFlags(flags)
  147. if isDebugMode():
  148. allConfigs=[allConfigs[0]]
  149. failedBuild = {}
  150. # Test all builds
  151. folderCreated=False
  152. def logFailedBuild(root,f):
  153. with open(os.path.join(fullTestFolder(root),"buildStatus_%d.txt" % args.n),"w") as status:
  154. for build in f:
  155. s = f[build]
  156. if s == MAKEFAILED:
  157. status.write("%s : Make failure\n" % build)
  158. if s == TESTFAILED:
  159. status.write("%s : Test failure\n" % build)
  160. if s == FLOWFAILURE:
  161. status.write("%s : Flow failure\n" % build)
  162. if s == CALLFAILURE:
  163. status.write("%s : Subprocess failure\n" % build)
  164. def buildAndTest(compiler,theConfig,cmake,sim):
  165. # Run all tests for AC6
  166. try:
  167. for core in config['CORES']:
  168. configNb = 0
  169. if compiler in config['CORES'][core]:
  170. msg("Testing Core %s\n" % core)
  171. for flagConfig in theConfig:
  172. folderCreated = False
  173. configNb = configNb + 1
  174. buildStr = "build_%s_%s_%d" % (compiler,core,configNb)
  175. toUnset = None
  176. toSet = None
  177. if 'UNSET' in config:
  178. if compiler in config['UNSET']:
  179. if core in config['UNSET'][compiler]:
  180. toUnset = config['UNSET'][compiler][core]
  181. if 'SET' in config:
  182. if compiler in config['SET']:
  183. if core in config['SET'][compiler]:
  184. toSet = config['SET'][compiler][core]
  185. build = BuildConfig(toUnset,toSet,args.r,
  186. buildStr,
  187. config['COMPILERS'][core][compiler],
  188. cmake,
  189. config['CORES'][core][compiler],
  190. config["CMAKE"]
  191. )
  192. flags = []
  193. if core in config["IMPLIEDFLAGS"]:
  194. flags += config["IMPLIEDFLAGS"][core]
  195. flags += flagConfig
  196. if compiler in config["IMPLIEDFLAGS"]:
  197. flags += config["IMPLIEDFLAGS"][compiler]
  198. build.createFolder()
  199. # Run all tests for the build
  200. testStatusForThisBuild = NOTESTFAILED
  201. try:
  202. # This is saving the flag configuration
  203. build.createArchive(flags)
  204. msg("Config " + str(flagConfig) + "\n")
  205. build.createCMake(core,flags,args.b,args.p)
  206. for test in config["TESTS"]:
  207. msg(test["testName"]+"\n")
  208. testClass=test["testClass"]
  209. test = build.getTest(testClass)
  210. fvp = None
  211. if 'FVP' in config:
  212. if core in config['FVP']:
  213. fvp = config['FVP'][core]
  214. if 'SIM' in config:
  215. if core in config['SIM']:
  216. fvp = config['SIM'][core]
  217. newTestStatus = test.runAndProcess(compiler,fvp,sim,args.b,args.db,args.regdb,benchID,regID)
  218. testStatusForThisBuild = updateTestStatus(testStatusForThisBuild,newTestStatus)
  219. if testStatusForThisBuild != NOTESTFAILED:
  220. failedBuild[buildStr] = testStatusForThisBuild
  221. # Final script status
  222. testFailed = 1
  223. build.archiveResults()
  224. finally:
  225. build.cleanFolder()
  226. else:
  227. msg("No toolchain %s for core %s" % (compiler,core))
  228. except TestFlowFailure as flow:
  229. errorMsg("Error flow id %d\n" % flow.errorCode())
  230. failedBuild[buildStr] = FLOWFAILURE
  231. logFailedBuild(args.r,failedBuild)
  232. sys.exit(1)
  233. except CallFailure:
  234. errorMsg("Call failure\n")
  235. failedBuild[buildStr] = CALLFAILURE
  236. logFailedBuild(args.r,failedBuild)
  237. sys.exit(1)
  238. ############## Builds for all toolchains
  239. if not isDebugMode():
  240. preprocess(args.f)
  241. generateAllCCode()
  242. else:
  243. msg("Debug Mode\n")
  244. for t in config["TOOLCHAINS"]:
  245. cmake,localConfig,sim = analyzeToolchain(config["TOOLCHAINS"][t],allConfigs)
  246. msg("Testing toolchain %s\n" % cmake)
  247. buildAndTest(t,localConfig,cmake,sim)
  248. logFailedBuild(args.r,failedBuild)
  249. sys.exit(testFailed)