runAllTests.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. # Small state machine
  13. def updateTestStatus(testStatusForThisBuild,newTestStatus):
  14. if testStatusForThisBuild == NOTESTFAILED:
  15. if newTestStatus == NOTESTFAILED:
  16. return(NOTESTFAILED)
  17. if newTestStatus == MAKEFAILED:
  18. return(MAKEFAILED)
  19. if newTestStatus == TESTFAILED:
  20. return(TESTFAILED)
  21. if testStatusForThisBuild == MAKEFAILED:
  22. if newTestStatus == NOTESTFAILED:
  23. return(MAKEFAILED)
  24. if newTestStatus == MAKEFAILED:
  25. return(MAKEFAILED)
  26. if newTestStatus == TESTFAILED:
  27. return(TESTFAILED)
  28. if testStatusForThisBuild == TESTFAILED:
  29. if newTestStatus == NOTESTFAILED:
  30. return(TESTFAILED)
  31. if newTestStatus == MAKEFAILED:
  32. return(TESTFAILED)
  33. if newTestStatus == TESTFAILED:
  34. return(TESTFAILED)
  35. if testStatusForThisBuild == FLOWFAILURE:
  36. return(testStatusForThisBuild)
  37. if testStatusForThisBuild == CALLFAILURE:
  38. return(testStatusForThisBuild)
  39. root = Path(os.getcwd()).parent.parent.parent
  40. def cartesian(*somelists):
  41. r=[]
  42. for element in itertools.product(*somelists):
  43. r.append(list(element))
  44. return(r)
  45. testFailed = 0
  46. init()
  47. parser = argparse.ArgumentParser(description='Parse test description')
  48. parser.add_argument('-i', nargs='?',type = str, default="testrunConfig.yaml",help="Config file")
  49. parser.add_argument('-r', nargs='?',type = str, default=root, help="Root folder")
  50. parser.add_argument('-n', nargs='?',type = int, default=0, help="ID value when launchign in parallel")
  51. args = parser.parse_args()
  52. with open(args.i,"r") as f:
  53. config=yaml.safe_load(f)
  54. #print(config)
  55. #print(config["IMPLIEDFLAGS"])
  56. flags = config["FLAGS"]
  57. onoffFlags = []
  58. for f in flags:
  59. onoffFlags.append(["-D" + f +"=ON","-D" + f +"=OFF"])
  60. allConfigs=cartesian(*onoffFlags)
  61. if DEBUGMODE:
  62. allConfigs=[allConfigs[0]]
  63. failedBuild = {}
  64. # Test all builds
  65. folderCreated=False
  66. def logFailedBuild(root,f):
  67. with open(os.path.join(fullTestFolder(root),"buildStatus_%d.txt" % args.n),"w") as status:
  68. for build in f:
  69. s = f[build]
  70. if s == MAKEFAILED:
  71. status.write("%s : Make failure\n" % build)
  72. if s == TESTFAILED:
  73. status.write("%s : Test failure\n" % build)
  74. if s == FLOWFAILURE:
  75. status.write("%s : Flow failure\n" % build)
  76. if s == CALLFAILURE:
  77. status.write("%s : Subprocess failure\n" % build)
  78. def buildAndTest(compiler):
  79. # Run all tests for AC6
  80. try:
  81. for core in config['CORES']:
  82. configNb = 0
  83. if compiler in config['CORES'][core]:
  84. for flagConfig in allConfigs:
  85. folderCreated = False
  86. configNb = configNb + 1
  87. buildStr = "build_%s_%s_%d" % (compiler,core,configNb)
  88. toUnset = None
  89. toSet = None
  90. if compiler in config['UNSET']:
  91. if core in config['UNSET'][compiler]:
  92. toUnset = config['UNSET'][compiler][core]
  93. if compiler in config['SET']:
  94. if core in config['SET'][compiler]:
  95. toSet = config['SET'][compiler][core]
  96. build = BuildConfig(toUnset,toSet,args.r,
  97. buildStr,
  98. config['COMPILERS'][core][compiler],
  99. config['TOOLCHAINS'][compiler],
  100. config['CORES'][core][compiler],
  101. config["CMAKE"]
  102. )
  103. flags = []
  104. if core in config["IMPLIEDFLAGS"]:
  105. flags += config["IMPLIEDFLAGS"][core]
  106. flags += flagConfig
  107. if compiler in config["IMPLIEDFLAGS"]:
  108. flags += config["IMPLIEDFLAGS"][compiler]
  109. build.createFolder()
  110. # Run all tests for the build
  111. testStatusForThisBuild = NOTESTFAILED
  112. try:
  113. # This is saving the flag configuration
  114. build.createArchive(flags)
  115. build.createCMake(flags)
  116. for test in config["TESTS"]:
  117. msg(test["testName"]+"\n")
  118. testClass=test["testClass"]
  119. test = build.getTest(testClass)
  120. fvp = None
  121. if core in config['FVP']:
  122. fvp = config['FVP'][core]
  123. newTestStatus = test.runAndProcess(compiler,fvp)
  124. testStatusForThisBuild = updateTestStatus(testStatusForThisBuild,newTestStatus)
  125. if testStatusForThisBuild != NOTESTFAILED:
  126. failedBuild[buildStr] = testStatusForThisBuild
  127. # Final script status
  128. testFailed = 1
  129. build.archiveResults()
  130. finally:
  131. build.cleanFolder()
  132. else:
  133. msg("No toolchain %s for core %s" % (compiler,core))
  134. except TestFlowFailure as flow:
  135. errorMsg("Error flow id %d\n" % flow.errorCode())
  136. failedBuild[buildStr] = FLOWFAILURE
  137. logFailedBuild(args.r,failedBuild)
  138. sys.exit(1)
  139. except CallFailure:
  140. errorMsg("Call failure\n")
  141. failedBuild[buildStr] = CALLFAILURE
  142. logFailedBuild(args.r,failedBuild)
  143. sys.exit(1)
  144. ############## Builds for all toolchains
  145. if not DEBUGMODE:
  146. preprocess()
  147. generateAllCCode()
  148. for t in config["TOOLCHAINS"]:
  149. msg("Testing toolchain %s\n" % t)
  150. buildAndTest(t)
  151. logFailedBuild(args.r,failedBuild)
  152. sys.exit(testFailed)