malformed_test.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/python
  2. #
  3. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  4. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. #
  6. import os
  7. import sys
  8. import time
  9. import subprocess
  10. from optparse import OptionParser
  11. # You can run different runtime by changing the arg '-r':
  12. # python malformed_test.py -r /path/to/iwasm
  13. # python malformed_test.py -r /path/to/wasmtime
  14. # python malformed_test.py -r "/path/to/wasmer run"
  15. optParser = OptionParser()
  16. optParser.add_option("-r", "--run", dest="run",
  17. default="iwasm",
  18. help="specify a runtime [path/to]([iwasm] / wasmtime / wasmer run)")
  19. (options, args) = optParser.parse_args()
  20. #optParser.usage = "%prog [options]"
  21. succ_cnt = 0
  22. fail_cnt = 0
  23. test_start = time.time()
  24. for root, dirs, files in os.walk("."):
  25. for file in files:
  26. if len(file.split('.')) < 2 or file.split('.')[1] != 'wasm':
  27. continue
  28. filepath=os.path.join(root, file)
  29. cmd = options.run + " " + filepath
  30. test_out = subprocess.getoutput(cmd)
  31. if not test_out.startswith("Segmentation fault"):
  32. print("test {:40} ........ [PASSED]".format(filepath))
  33. succ_cnt += 1
  34. else:
  35. print("test {:40} ........ [FAILED]".format(filepath))
  36. print(test_out)
  37. print('\n')
  38. fail_cnt += 1
  39. test_end = time.time()
  40. print("\n##################### MALFORMED TEST ########################")
  41. print("run {} test cases in {}ms, {} passed, {} failed"
  42. .format(succ_cnt + fail_cnt, test_end - test_start, succ_cnt, fail_cnt))