test.and.py 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Copyright (c) Contributors to the Open 3D Engine Project.
  5. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. SPDX-License-Identifier: Apache-2.0 OR MIT
  7. """
  8. import sys
  9. import os
  10. import platform
  11. import datetime
  12. import subprocess
  13. from subprocess import check_output
  14. import os.path
  15. import shutil
  16. from argparse import ArgumentParser
  17. from os.path import join, normpath, basename
  18. import re
  19. import importlib
  20. sys.path.append("tests")
  21. from clr import *
  22. testList = ['Syntax', 'Semantic', 'Advanced', 'Samples']
  23. os.system('') # activate VT100 mode for windows console
  24. azslcRelease = ""
  25. azslcDebug = ""
  26. az3rdParty = ""
  27. parser = ArgumentParser()
  28. parser.add_argument(
  29. '--j', dest='jenkin',
  30. action='store_true', default=False,
  31. help="Use jenkin configuration to build and test",
  32. )
  33. parser.add_argument(
  34. '--dev', dest='atomDev',
  35. type=str,
  36. help="The path of atom dev(to locate DXC-az version), If not specified, default windows 10 Dxc.exe will be used",
  37. )
  38. args = parser.parse_args()
  39. isJenkin = "OFF"
  40. if args.jenkin is True:
  41. isJenkin = "ON"
  42. if args.atomDev is not None:
  43. az3rdParty = args.atomDev + "/Gems/Atom/Asset/Shader/External"
  44. # Part 0 - Prerequisites
  45. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  46. print ( fg.CYAN + style.BRIGHT + " Building AZSLc ..." + style.RESET_ALL )
  47. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  48. missingCritical = 0
  49. missingOptional = 0
  50. # Windows
  51. if os.name == 'nt':
  52. criticalCMake = "../lib/CMake/bin/cmake.exe"
  53. if not os.path.isfile(criticalCMake):
  54. from shutil import which
  55. if which("cmake") is None:
  56. print ( fg.RED + style.BRIGHT + "[ X ] Expected CMake 3.15+ (in {} or as command)".format(criticalCMake) + style.RESET_ALL )
  57. missingCritical = missingCritical + 1
  58. criticalBoostD = "../lib/boost_1_70_0/"
  59. criticalBoostH = criticalBoostD + "boost/regex/regex_traits.hpp"
  60. criticalBoostL = criticalBoostD + "libs/boost_regex-vc141-mt-x64-1_70.dll"
  61. if not os.path.isfile(criticalBoostH) or not os.path.isfile(criticalBoostL):
  62. print ( fg.RED + style.BRIGHT + "[ X ] Expected Boost 1.70 in {}".format(criticalBoostD) + style.RESET_ALL )
  63. print ( fg.RED + style.BRIGHT + " - All relevant headers required for {}".format(criticalBoostH) + style.RESET_ALL )
  64. print ( fg.RED + style.BRIGHT + " - All Boost-Regex libraries, for example {}".format(criticalBoostL) + style.RESET_ALL )
  65. missingCritical = missingCritical + 1
  66. try:
  67. import yaml
  68. except ImportError as err:
  69. print ( fg.YELLOW + style.BRIGHT + "[ ! ] Trying to run pip install pyyaml ..." + style.RESET_ALL )
  70. subprocess.check_call([sys.executable, "-m", "pip", "install", "pyyaml"])
  71. try:
  72. import yaml
  73. except ImportError:
  74. print ( fg.RED + style.BRIGHT + "[ ! ] Please run pip install pyyaml, otherwise some tests will fail to validate" + style.RESET_ALL )
  75. missingCritical = missingCritical + 1
  76. try:
  77. jversion = subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT)
  78. pattern = '\"(\d+\.\d+).*\"'
  79. jversionTrim = re.search(pattern, jversion.decode("utf-8") ).groups()[0]
  80. except Exception:
  81. jversionTrim = ""
  82. # We could compare using 'Version' instead but it requires installing the 'packaging' package
  83. if jversionTrim < "1.6":
  84. print ( fg.YELLOW + style.BRIGHT + "[ ! ] You need java (JDK 1.6 or newer) if you want to rebuild the ANTLR4 generated grammar files" + style.RESET_ALL )
  85. missingOptional = missingOptional + 1
  86. if missingOptional > 0:
  87. print ( fg.YELLOW + style.BRIGHT + "{} optional component(s) could be better".format(missingOptional) + style.RESET_ALL )
  88. if missingCritical > 0:
  89. print ( fg.RED + style.BRIGHT + "{} critical component(s) are still missing!".format(missingCritical) + style.RESET_ALL )
  90. sys.exit(1)
  91. # Part 1 - Build, ...
  92. if os.name == 'nt':
  93. print (fg.CYAN + style.BRIGHT + "Prepare solution..." + style.RESET_ALL)
  94. subprocess.call(["prepare_solution_win.bat", "nopause", isJenkin])
  95. print (fg.CYAN + style.BRIGHT + "... done" + style.RESET_ALL)
  96. print (fg.CYAN + style.BRIGHT + "Build Release ..." + style.RESET_ALL )
  97. ret = subprocess.call(["build_win.bat", "Release", isJenkin])
  98. if ret != 0:
  99. if ret < 0:
  100. print ( "Killed by signal" + -ret )
  101. sys.exit(1)
  102. else:
  103. print ( fg.RED + style.BRIGHT + "Could not complete test execution!" + style.RESET_ALL )
  104. sys.exit(1)
  105. else:
  106. print ( fg.CYAN + style.BRIGHT + "... done" + style.RESET_ALL )
  107. print ( fg.CYAN + style.BRIGHT + "Build Debug ..." + style.RESET_ALL )
  108. ret = subprocess.call(["build_win.bat", "Debug", isJenkin])
  109. if ret != 0:
  110. if ret < 0:
  111. print ( "Killed by signal" + -ret )
  112. sys.exit(1)
  113. else:
  114. print ( fg.RED + style.BRIGHT + "Could not complete test execution!" + style.RESET_ALL )
  115. sys.exit(1)
  116. else:
  117. print ( fg.CYAN + style.BRIGHT + "... done" + style.RESET_ALL )
  118. azslcRelease = "bin/win_x64/Release/azslc.exe"
  119. if not os.path.isfile(azslcRelease):
  120. print ( "Release build failed (expected at {})".format(azslcRelease) )
  121. sys.exit(1)
  122. azslcDebug = "bin/win_x64/Debug/azslc.exe"
  123. if not os.path.isfile(azslcDebug):
  124. print ( "Debug build failed (expected at {})".format(azslcDebug) )
  125. sys.exit(1)
  126. if platform.system() == 'Darwin':
  127. print ( fg.CYAN + style.BRIGHT + "Prepare solution..." + style.RESET_ALL )
  128. subprocess.call(["./prepare_solution_darwin.sh"])
  129. print ( fg.CYAN + style.BRIGHT + "... done" + style.RESET_ALL )
  130. azslcRelease = "bin/darwin/release/azslc"
  131. if not os.path.isfile(azslcRelease):
  132. print ( "Release build failed (expected at {})".format(azslcRelease) )
  133. sys.exit(1)
  134. azslcDebug = "bin/darwin/debug/azslc"
  135. if not os.path.isfile(azslcDebug):
  136. print ( "Debug build failed (expected at {})".format(azslcDebug) )
  137. sys.exit(1)
  138. if platform.system() == 'Linux':
  139. print ( fg.CYAN + style.BRIGHT + "Prepare solution..." + style.RESET_ALL )
  140. subprocess.call(["./prepare_solution_linux.sh"])
  141. print ( fg.CYAN + style.BRIGHT + "... done" + style.RESET_ALL )
  142. azslcRelease = "bin/linux/release/azslc"
  143. if not os.path.isfile(azslcRelease):
  144. print ( "Release build failed (expected at {})".format(azslcRelease) )
  145. sys.exit(1)
  146. azslcDebug = "bin/linux/debug/azslc"
  147. if not os.path.isfile(azslcDebug):
  148. print ( "Debug build failed (expected at {})".format(azslcDebug) )
  149. sys.exit(1)
  150. # Part 2 - ... test and ...
  151. expectCorrect = 230
  152. allowIncorrect = 0
  153. testScriptModule = importlib.import_module("testapp")
  154. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  155. print ( fg.CYAN + style.BRIGHT + " Testing Release ..." + style.RESET_ALL )
  156. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  157. numAllTests = testScriptModule.runAll("./tests", testList, azslcRelease, 0, az3rdParty)
  158. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  159. print ( fg.GREEN + style.BRIGHT + "OK: {}".format(numAllTests.numPass) + style.RESET_ALL )
  160. print ( fg.YELLOW + style.BRIGHT + "TODO: {}".format(numAllTests.numTodo) + style.RESET_ALL )
  161. print ( fg.RED + style.BRIGHT + "FAILED: {}".format(numAllTests.numFail) + style.RESET_ALL )
  162. if numAllTests.numPass < expectCorrect:
  163. print ( fg.RED + style.BRIGHT + "Fix your code! (expected {} passing tests)".format(expectCorrect) + style.RESET_ALL )
  164. sys.exit(0)
  165. if numAllTests.numFail > allowIncorrect:
  166. print ( fg.RED + style.BRIGHT + "Wow, we shouldn't ship with that many broken tests! (allows {} tests to be failing)".format(allowIncorrect) + style.RESET_ALL )
  167. sys.exit(1)
  168. print ( fg.CYAN + style.BRIGHT + " GOOD ENOUGH" + style.RESET_ALL )
  169. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  170. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  171. print ( fg.CYAN + style.BRIGHT + " Testing Debug ..." + style.RESET_ALL )
  172. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  173. numAllTests = testScriptModule.runAll("./tests", testList, azslcDebug, 0, az3rdParty)
  174. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  175. print ( fg.GREEN + style.BRIGHT + "OK: {}".format(numAllTests.numPass) + style.RESET_ALL )
  176. print ( fg.YELLOW + style.BRIGHT + "TODO: {}".format(numAllTests.numTodo) + style.RESET_ALL )
  177. print ( fg.RED + style.BRIGHT + "FAILED: {}".format(numAllTests.numFail) + style.RESET_ALL )
  178. if numAllTests.numPass < expectCorrect:
  179. print ( fg.RED, style.BRIGHT + "Fix your code! (expected {} passing tests)".format(expectCorrect) + style.RESET_ALL)
  180. sys.exit(0)
  181. if numAllTests.numFail > allowIncorrect:
  182. print ( fg.RED + style.BRIGHT + "Wow, we shouldn't ship with that many broken tests! (allows {} tests to be failing)".format(allowIncorrect) + style.RESET_ALL)
  183. sys.exit(1)
  184. print ( fg.CYAN + style.BRIGHT + " GOOD ENOUGH" + style.RESET_ALL)
  185. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL)