2
0

test.and.py 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 tests.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. from shutil import which
  53. if which("cmake") is None:
  54. print ( fg.RED + style.BRIGHT + "[ X ] Expected CMake 3.15+ (in {} or as command)".format(criticalCMake) + style.RESET_ALL )
  55. missingCritical = missingCritical + 1
  56. try:
  57. import yaml
  58. except ImportError as err:
  59. print ( fg.YELLOW + style.BRIGHT + "[ ! ] Trying to run pip install pyyaml ..." + style.RESET_ALL )
  60. subprocess.check_call([sys.executable, "-m", "pip", "install", "pyyaml"])
  61. try:
  62. import yaml
  63. except ImportError:
  64. print ( fg.RED + style.BRIGHT + "[ ! ] Please run pip install pyyaml, otherwise some tests will fail to validate" + style.RESET_ALL )
  65. missingCritical = missingCritical + 1
  66. try:
  67. jversion = subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT)
  68. pattern = '\"(\d+\.\d+).*\"'
  69. jversionTrim = re.search(pattern, jversion.decode("utf-8") ).groups()[0]
  70. except Exception:
  71. jversionTrim = ""
  72. # We could compare using 'Version' instead but it requires installing the 'packaging' package
  73. if jversionTrim < "1.6":
  74. 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 )
  75. missingOptional = missingOptional + 1
  76. if missingOptional > 0:
  77. print ( fg.YELLOW + style.BRIGHT + "{} optional component(s) could be better".format(missingOptional) + style.RESET_ALL )
  78. if missingCritical > 0:
  79. print ( fg.RED + style.BRIGHT + "{} critical component(s) are still missing!".format(missingCritical) + style.RESET_ALL )
  80. sys.exit(1)
  81. # Part 1 - Build, ...
  82. if os.name == 'nt':
  83. print (fg.CYAN + style.BRIGHT + "Prepare solution..." + style.RESET_ALL)
  84. subprocess.call(["prepare_solution_win.bat", "nopause", isJenkin])
  85. print (fg.CYAN + style.BRIGHT + "... done" + style.RESET_ALL)
  86. print (fg.CYAN + style.BRIGHT + "Build Release ..." + style.RESET_ALL )
  87. ret = subprocess.call(["build_win.bat", "Release", isJenkin])
  88. if ret != 0:
  89. if ret < 0:
  90. print ( "Killed by signal" + -ret )
  91. sys.exit(1)
  92. else:
  93. print ( fg.RED + style.BRIGHT + "Could not complete test execution!" + style.RESET_ALL )
  94. sys.exit(1)
  95. else:
  96. print ( fg.CYAN + style.BRIGHT + "... done" + style.RESET_ALL )
  97. print ( fg.CYAN + style.BRIGHT + "Build Debug ..." + style.RESET_ALL )
  98. ret = subprocess.call(["build_win.bat", "Debug", isJenkin])
  99. if ret != 0:
  100. if ret < 0:
  101. print ( "Killed by signal" + -ret )
  102. sys.exit(1)
  103. else:
  104. print ( fg.RED + style.BRIGHT + "Could not complete test execution!" + style.RESET_ALL )
  105. sys.exit(1)
  106. else:
  107. print ( fg.CYAN + style.BRIGHT + "... done" + style.RESET_ALL )
  108. azslcRelease = "bin/win_x64/Release/azslc.exe"
  109. if not os.path.isfile(azslcRelease):
  110. print ( "Release build failed (expected at {})".format(azslcRelease) )
  111. sys.exit(1)
  112. azslcDebug = "bin/win_x64/Debug/azslc.exe"
  113. if not os.path.isfile(azslcDebug):
  114. print ( "Debug build failed (expected at {})".format(azslcDebug) )
  115. sys.exit(1)
  116. if platform.system() == 'Darwin':
  117. print ( fg.CYAN + style.BRIGHT + "Prepare solution..." + style.RESET_ALL )
  118. subprocess.call(["./prepare_solution_darwin.sh"])
  119. print ( fg.CYAN + style.BRIGHT + "... done" + style.RESET_ALL )
  120. azslcRelease = "bin/darwin/release/azslc"
  121. if not os.path.isfile(azslcRelease):
  122. print ( "Release build failed (expected at {})".format(azslcRelease) )
  123. sys.exit(1)
  124. azslcDebug = "bin/darwin/debug/azslc"
  125. if not os.path.isfile(azslcDebug):
  126. print ( "Debug build failed (expected at {})".format(azslcDebug) )
  127. sys.exit(1)
  128. if platform.system() == 'Linux':
  129. print ( fg.CYAN + style.BRIGHT + "Prepare solution..." + style.RESET_ALL )
  130. subprocess.call(["./prepare_solution_linux.sh"])
  131. print ( fg.CYAN + style.BRIGHT + "... done" + style.RESET_ALL )
  132. azslcRelease = "bin/linux/release/azslc"
  133. if not os.path.isfile(azslcRelease):
  134. print ( "Release build failed (expected at {})".format(azslcRelease) )
  135. sys.exit(1)
  136. azslcDebug = "bin/linux/debug/azslc"
  137. if not os.path.isfile(azslcDebug):
  138. print ( "Debug build failed (expected at {})".format(azslcDebug) )
  139. sys.exit(1)
  140. # Part 2 - ... test and ...
  141. expectCorrect = 230
  142. allowIncorrect = 0
  143. testScriptModule = importlib.import_module("testapp")
  144. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  145. print ( fg.CYAN + style.BRIGHT + " Testing Release ..." + style.RESET_ALL )
  146. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  147. numAllTests = testScriptModule.runAll("./tests", testList, azslcRelease, 0, az3rdParty)
  148. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  149. print ( fg.GREEN + style.BRIGHT + "OK: {}".format(numAllTests.numPass) + style.RESET_ALL )
  150. print ( fg.YELLOW + style.BRIGHT + "TODO: {}".format(numAllTests.numTodo) + style.RESET_ALL )
  151. print ( fg.RED + style.BRIGHT + "FAILED: {}".format(numAllTests.numFail) + style.RESET_ALL )
  152. if numAllTests.numPass < expectCorrect:
  153. print ( fg.RED + style.BRIGHT + "Fix your code! (expected {} passing tests)".format(expectCorrect) + style.RESET_ALL )
  154. sys.exit(0)
  155. if numAllTests.numFail > allowIncorrect:
  156. 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 )
  157. sys.exit(1)
  158. print ( fg.CYAN + style.BRIGHT + " GOOD ENOUGH" + style.RESET_ALL )
  159. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  160. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  161. print ( fg.CYAN + style.BRIGHT + " Testing Debug ..." + style.RESET_ALL )
  162. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  163. numAllTests = testScriptModule.runAll("./tests", testList, azslcDebug, 0, az3rdParty)
  164. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL )
  165. print ( fg.GREEN + style.BRIGHT + "OK: {}".format(numAllTests.numPass) + style.RESET_ALL )
  166. print ( fg.YELLOW + style.BRIGHT + "TODO: {}".format(numAllTests.numTodo) + style.RESET_ALL )
  167. print ( fg.RED + style.BRIGHT + "FAILED: {}".format(numAllTests.numFail) + style.RESET_ALL )
  168. if numAllTests.numPass < expectCorrect:
  169. print ( fg.RED, style.BRIGHT + "Fix your code! (expected {} passing tests)".format(expectCorrect) + style.RESET_ALL)
  170. sys.exit(0)
  171. if numAllTests.numFail > allowIncorrect:
  172. 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)
  173. sys.exit(1)
  174. print ( fg.CYAN + style.BRIGHT + " GOOD ENOUGH" + style.RESET_ALL)
  175. print ( fg.CYAN + style.BRIGHT + "*****************************************************" + style.RESET_ALL)