You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

264 lines
9.4 KiB

  1. #!/usr/bin/env python3
  2. # -*- Coding: UTF-8 -*-
  3. # ---------------------------------------------------------------------------
  4. # Open Asset Import Library (ASSIMP)
  5. # ---------------------------------------------------------------------------
  6. #
  7. # Copyright (c) 2006-2010, ASSIMP Development Team
  8. #
  9. # All rights reserved.
  10. #
  11. # Redistribution and use of this software in source and binary forms,
  12. # with or without modification, are permitted provided that the following
  13. # conditions are met:
  14. #
  15. # * Redistributions of source code must retain the above
  16. # copyright notice, this list of conditions and the
  17. # following disclaimer.
  18. #
  19. # * Redistributions in binary form must reproduce the above
  20. # copyright notice, this list of conditions and the
  21. # following disclaimer in the documentation and/or other
  22. # materials provided with the distribution.
  23. #
  24. # * Neither the name of the ASSIMP team, nor the names of its
  25. # contributors may be used to endorse or promote products
  26. # derived from this software without specific prior
  27. # written permission of the ASSIMP Development Team.
  28. #
  29. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. # ---------------------------------------------------------------------------
  41. """
  42. Run the regression test suite using the settings from settings.py.
  43. """
  44. import sys
  45. import os
  46. import subprocess
  47. import zipfile
  48. import collections
  49. import settings
  50. import utils
  51. # -------------------------------------------------------------------------------
  52. EXPECTED_FAILURE_NOT_MET, DATABASE_LENGTH_MISMATCH, \
  53. DATABASE_VALUE_MISMATCH, IMPORT_FAILURE, \
  54. FILE_NOT_READABLE, COMPARE_SUCCESS = range(6)
  55. messages = collections.defaultdict(lambda: "<unknown", {
  56. EXPECTED_FAILURE_NOT_MET:
  57. """Unexpected success during import\n\
  58. \tReturn code was 0""",
  59. DATABASE_LENGTH_MISMATCH:
  60. """Database mismatch: lengths don't match\n\
  61. \tExpected: {0} Actual: {1}""",
  62. DATABASE_VALUE_MISMATCH:
  63. """Database mismatch: """,
  64. IMPORT_FAILURE:
  65. """Unexpected failure during import\n\
  66. \tReturn code was {0}""",
  67. FILE_NOT_READABLE:
  68. """Unexpected failure reading file""",
  69. COMPARE_SUCCESS:
  70. """Results match archived reference dump in database\n\
  71. \tNumber of bytes compared: {0}"""
  72. })
  73. outfilename_output = "run_regression_suite_output.txt"
  74. outfilename_failur = "run_regression_suite_failures.csv"
  75. # -------------------------------------------------------------------------------
  76. class results:
  77. """ Handle formatting of results"""
  78. def __init__(self, zipin):
  79. """Init, given a ZIPed database """
  80. self.failures = []
  81. self.success = []
  82. self.zipin = zipin
  83. def fail(self, failfile, filename_expect, pp, msg, *args):
  84. """
  85. Report failure of a sub-test
  86. File f failed a test for pp config pp, failure notice is msg,
  87. *args is format()ting args for msg
  88. """
  89. print("[FAILURE] " + messages[msg].format(*args))
  90. self.failures.append((failfile, filename_expect, pp))
  91. def ok(self, f, pp, msg, *args):
  92. """
  93. Report success of a sub-test
  94. File f passed the test, msg is a happy success note,
  95. *args is format()ing args for msg.
  96. """
  97. print("[SUCCESS] " + messages[msg].format(*args))
  98. self.success.append(f)
  99. def report_results(self):
  100. """Write results to ../results/run_regression_suite_failures.txt"""
  101. print("\n" + ('='*60) + "\n" + "SUCCESS: {0}\nFAILURE: {1}\nPercentage good: {2}".format(
  102. len(self.success), len(self.failures), len(self.success)/(len(self.success)+len(self.failures)) ) +
  103. "\n" + ('='*60) + "\n")
  104. with open(os.path.join('..', 'results',outfilename_failur), "wt") as f:
  105. f.write("ORIGINAL FILE;EXPECTED DUMP\n")
  106. f.writelines(map(
  107. lambda x: x[0] + ' ' + x[2] + ";" + x[1] + "\n", self.failures))
  108. if self.failures:
  109. print("\nSee " + settings.results + "\\" + outfilename_failur
  110. + " for more details\n\n")
  111. # -------------------------------------------------------------------------------
  112. def mkoutputdir_andgetpath(fullpath, myhash, app):
  113. outfile = os.path.join(settings.results, "tmp", os.path.split(fullpath)[1] + "_" + myhash)
  114. try:
  115. os.mkdir(outfile)
  116. except OSError:
  117. pass
  118. outfile = os.path.join(outfile, app)
  119. return outfile
  120. # -------------------------------------------------------------------------------
  121. def process_dir(d, outfile_results, zipin, result):
  122. shellparams = {'stdout':outfile_results, 'stderr':outfile_results, 'shell':False}
  123. print("Processing directory " + d)
  124. for f in os.listdir(d):
  125. fullpath = os.path.join(d, f)
  126. if os.path.isdir(fullpath) and not f == ".svn":
  127. process_dir(fullpath, outfile_results, zipin, result)
  128. continue
  129. for pppreset in settings.pp_configs_to_test:
  130. filehash = utils.hashing(fullpath, pppreset)
  131. failure = False
  132. try:
  133. input_expected = zipin.open(filehash, "r").read()
  134. # empty dump files indicate 'expected import failure'
  135. if not len(input_expected):
  136. failure = True
  137. except KeyError:
  138. #print("Didn't find "+fullpath+" (Hash is "+filehash+") in database")
  139. continue
  140. # Ignore extensions via settings.py configured list
  141. # todo: Fix for multi dot extensions like .skeleton.xml
  142. ext = os.path.splitext(fullpath)[1].lower()
  143. if ext != "" and ext in settings.exclude_extensions:
  144. continue
  145. print("-"*60 + "\n " + os.path.realpath(fullpath) + " pp: " + pppreset)
  146. outfile_actual = mkoutputdir_andgetpath(fullpath, filehash, "ACTUAL")
  147. outfile_expect = mkoutputdir_andgetpath(fullpath, filehash, "EXPECT")
  148. outfile_results.write("assimp dump "+"-"*80+"\n")
  149. outfile_results.flush()
  150. command = [utils.assimp_bin_path,"dump",fullpath,outfile_actual,"-b","-s","-l"]+pppreset.split()
  151. r = subprocess.call(command, **shellparams)
  152. if r and not failure:
  153. result.fail(fullpath, outfile_expect, pppreset, IMPORT_FAILURE, r)
  154. continue
  155. elif failure and not r:
  156. result.fail(fullpath, outfile_expect, pppreset, EXPECTED_FAILURE_NOT_MET)
  157. continue
  158. with open(outfile_expect, "wb") as s:
  159. s.write(input_expected)
  160. try:
  161. with open(outfile_actual, "rb") as s:
  162. input_actual = s.read()
  163. except IOError:
  164. continue
  165. if len(input_expected) != len(input_actual):
  166. result.fail(fullpath, outfile_expect, pppreset, DATABASE_LENGTH_MISMATCH,
  167. len(input_expected), len(input_actual))
  168. continue
  169. outfile_results.write("assimp cmpdump "+"-"*80+"\n")
  170. outfile_results.flush()
  171. command = [utils.assimp_bin_path,'cmpdump',outfile_actual,outfile_expect]
  172. if subprocess.call(command, **shellparams) != 0:
  173. result.fail(fullpath, outfile_expect, pppreset, DATABASE_VALUE_MISMATCH)
  174. continue
  175. result.ok(fullpath, pppreset, COMPARE_SUCCESS,
  176. len(input_expected))
  177. # -------------------------------------------------------------------------------
  178. def del_folder_with_contents(folder):
  179. for root, dirs, files in os.walk(folder, topdown=False):
  180. for name in files:
  181. os.remove(os.path.join(root, name))
  182. for name in dirs:
  183. os.rmdir(os.path.join(root, name))
  184. # -------------------------------------------------------------------------------
  185. def run_test():
  186. utils.find_assimp_or_die()
  187. tmp_target_path = os.path.join(settings.results, "tmp")
  188. try:
  189. os.mkdir(tmp_target_path)
  190. except OSError as oerr:
  191. # clear contents if tmp folder exists already
  192. del_folder_with_contents(tmp_target_path)
  193. try:
  194. zipin = zipfile.ZipFile(settings.database_name + ".zip",
  195. "r", zipfile.ZIP_STORED)
  196. except IOError:
  197. print("Regression database ", settings.database_name,
  198. ".zip was not found")
  199. return
  200. res = results(zipin)
  201. with open(os.path.join(settings.results, outfilename_output), "wt") as outfile:
  202. for tp in settings.model_directories:
  203. process_dir(tp, outfile, zipin, res)
  204. res.report_results()
  205. # -------------------------------------------------------------------------------
  206. if __name__ == "__main__":
  207. run_test()
  208. input("Press any key to continue ...")
  209. # vim: ai ts=4 sts=4 et sw=4