test_c_embed_api_thoroughly.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 CLI_ARGS_GENREATOR(running_modes_supported: list[str]) -> list[str]:
  9. res = []
  10. list_2d = [["--default-running-mode={} --module-running-mode={}".format(i, j)
  11. for i in running_modes_supported] for j in running_modes_supported]
  12. for list_1d in list_2d:
  13. res.extend(list_1d)
  14. return res
  15. def main():
  16. RUNNING_MODES: list[str] = [
  17. "interp",
  18. "fast-jit",
  19. "llvm-jit",
  20. "multi-tier-jit",
  21. ]
  22. COMPILE_FLAGS: list[str] = [
  23. "-DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=0",
  24. "-DWAMR_BUILD_FAST_JIT=1",
  25. "-DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1",
  26. "-DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1",
  27. "-DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0",
  28. ]
  29. # Python 3.7+: Dictionary iteration order is guaranteed to be in order of insertion.
  30. # just to be safe, using orderreddict
  31. # key: value -> compile mode, {"compile_flag": CMake compile flag, "iwasm_cli_args": array of CLI args tested}
  32. test_options = OrderedDict({
  33. "INTERP": {"compile_flag": COMPILE_FLAGS[0], "cli_args": CLI_ARGS_GENREATOR(RUNNING_MODES[:1])},
  34. "FAST_JIT": {"compile_flag": COMPILE_FLAGS[1], "cli_args": CLI_ARGS_GENREATOR(RUNNING_MODES[:2])},
  35. "LLVM_JIT": {"compile_flag": COMPILE_FLAGS[2],
  36. "cli_args": CLI_ARGS_GENREATOR([RUNNING_MODES[0], RUNNING_MODES[2]])},
  37. "MULTI_TIER_JIT": {"compile_flag": COMPILE_FLAGS[3], "cli_args": CLI_ARGS_GENREATOR(RUNNING_MODES)},
  38. "EAGER_JIT_WITH_BOTH_JIT": {"compile_flag": COMPILE_FLAGS[4],
  39. "cli_args": CLI_ARGS_GENREATOR(RUNNING_MODES[:3])}
  40. })
  41. build_cmd = "./build_c_embed.sh \"{build_flag}\""
  42. run_cmd = "cd c-embed/build && ./c_embed_test {cli_args}"
  43. for compile_mode in test_options.keys():
  44. build_flag: str = test_options[compile_mode]["compile_flag"]
  45. cli_args_li: list = test_options[compile_mode]["cli_args"]
  46. # compile
  47. print("\r\n\r\nCompile C program embed WAMR in {} mode".format(compile_mode))
  48. ret = os.system(build_cmd.format(build_flag=build_flag))
  49. if ret:
  50. print("Compile failed")
  51. # iter over cli args combination
  52. for cli_args in cli_args_li:
  53. print(run_cmd.format(cli_args=cli_args))
  54. ret = os.system(run_cmd.format(cli_args=cli_args))
  55. if ret:
  56. break
  57. else: # if inner for loop finish normally
  58. continue
  59. # if break from inner for loop
  60. print("Run failed")
  61. break
  62. if __name__ == '__main__':
  63. main()