test_iwasm_thoroughly.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!python3
  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. from collections import OrderedDict
  8. def main():
  9. IWASM_CMD = "../../../wamr/product-mini/platforms/linux/build/iwasm"
  10. IWASM_CLI_ARGS: list[str] = [
  11. "--heap-size=16384 --interp",
  12. "--heap-size=16384 --fast-jit",
  13. "--heap-size=16384 --llvm-jit",
  14. "--heap-size=16384 --multi-tier-jit",
  15. "--heap-size=16384 --llvm-jit --llvm-jit-size-level=1",
  16. "--heap-size=16384 --llvm-jit --llvm-jit-size-level=2 --llvm-jit-opt-level=1"
  17. ]
  18. COMPILE_FLAGS: list[str] = [
  19. "-DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0",
  20. "-DWAMR_BUILD_FAST_JIT=1",
  21. "-DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1",
  22. "-DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1",
  23. "-DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0",
  24. ]
  25. # Python 3.7+: Dictionary iteration order is guaranteed to be in order of insertion.
  26. # just to be safe, using OrderedDict
  27. # key: value -> compile mode, {"compile_flag": CMake compile flag, "iwasm_cli_args": array of CLI args tested}
  28. test_options = OrderedDict({
  29. "INTERP": {"compile_flag": COMPILE_FLAGS[0], "iwasm_cli_args": IWASM_CLI_ARGS[:1]},
  30. "FAST_JIT": {"compile_flag": COMPILE_FLAGS[1], "iwasm_cli_args": IWASM_CLI_ARGS[:2]},
  31. "LLVM_JIT": {"compile_flag": COMPILE_FLAGS[2], "iwasm_cli_args": [IWASM_CLI_ARGS[0], IWASM_CLI_ARGS[2]]},
  32. "MULTI_TIER_JIT": {"compile_flag": COMPILE_FLAGS[3], "iwasm_cli_args": IWASM_CLI_ARGS},
  33. "EAGER_JIT_WITH_BOTH_JIT": {"compile_flag": COMPILE_FLAGS[4],
  34. "iwasm_cli_args": IWASM_CLI_ARGS[:3] + IWASM_CLI_ARGS[4:]}
  35. })
  36. build_cmd = "./build_iwasm.sh \"{build_flag}\""
  37. wasm_file = "wasm-apps/mytest.wasm"
  38. run_cmd = "{IWASM_CMD} {cli_args} " + wasm_file
  39. for compile_mode in test_options.keys():
  40. build_flag: str = test_options[compile_mode]["compile_flag"]
  41. cli_args_li: list = test_options[compile_mode]["iwasm_cli_args"]
  42. # compile
  43. print("\r\n\r\nCompile iwasm in {} mode".format(compile_mode))
  44. ret = os.system(build_cmd.format(build_flag=build_flag))
  45. if ret:
  46. print("Compile failed")
  47. # iter over cli args combination
  48. for cli_args in cli_args_li:
  49. print(run_cmd.format(IWASM_CMD=IWASM_CMD, cli_args=cli_args))
  50. ret = os.system(run_cmd.format(
  51. IWASM_CMD=IWASM_CMD, cli_args=cli_args))
  52. if ret:
  53. break
  54. else: # if inner for loop finish normally
  55. continue
  56. # if break from inner for loop
  57. print("Run failed")
  58. break
  59. if __name__ == '__main__':
  60. main()