sample_test_run.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (C) 2023 Intel Corporation. All rights reserved.
  4. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. #
  6. import argparse
  7. import shlex
  8. import subprocess
  9. import sys
  10. import time
  11. import traceback
  12. import glob
  13. WAMRC_CMD = "../../wamr-compiler/build/wamrc"
  14. def compile_wasm_files_to_aot(wasm_apps_dir):
  15. wasm_files = glob.glob(wasm_apps_dir + "/*.wasm")
  16. print("Compile wasm app into aot files")
  17. for wasm_file in wasm_files:
  18. aot_file = wasm_file[0 : len(wasm_file) - 5] + ".aot";
  19. cmd = [ WAMRC_CMD, "-o", aot_file, wasm_file ]
  20. subprocess.check_call(cmd)
  21. def start_server(cmd, cwd):
  22. app_server = subprocess.Popen(shlex.split(cmd), cwd=cwd)
  23. return app_server
  24. def run_cmd(cmd, cwd):
  25. qry_prc = subprocess.run(
  26. shlex.split(cmd), cwd=cwd, check=False, capture_output=True
  27. )
  28. if (qry_prc.returncode != 0):
  29. print("Run {} failed, return {}".format(cmd, qry_prc.returncode))
  30. return
  31. print("return code: {}, output:\n{}".format(qry_prc.returncode,
  32. qry_prc.stdout.decode()))
  33. def main():
  34. """
  35. GO!GO!!GO!!!
  36. """
  37. parser = argparse.ArgumentParser(description="run the sample and examine outputs")
  38. parser.add_argument("working_directory", type=str)
  39. parser.add_argument("--aot", action='store_true', help="Test with AOT")
  40. args = parser.parse_args()
  41. test_aot = False
  42. suffix = ".wasm"
  43. if not args.aot:
  44. print("Test with interpreter mode")
  45. else:
  46. print("Test with AOT mode")
  47. test_aot = True
  48. suffix = ".aot"
  49. wasm_apps_dir = args.working_directory
  50. compile_wasm_files_to_aot(wasm_apps_dir)
  51. ret = 1
  52. app_server = None
  53. try:
  54. print("\n================================")
  55. print("Test TCP server and client")
  56. cmd = "./iwasm --addr-pool=0.0.0.0/15 tcp_server" + suffix
  57. app_server = start_server(cmd, args.working_directory)
  58. # wait for a second
  59. time.sleep(1)
  60. cmd = "./iwasm --addr-pool=127.0.0.1/15 tcp_client" + suffix
  61. for i in range(5):
  62. run_cmd(cmd, args.working_directory)
  63. print("\n================================")
  64. print("Test UDP server and client")
  65. cmd = "./iwasm --addr-pool=0.0.0.0/15 udp_server" + suffix
  66. app_server = start_server(cmd, args.working_directory)
  67. # wait for a second
  68. time.sleep(1)
  69. cmd = "./iwasm --addr-pool=127.0.0.1/15 udp_client" + suffix
  70. for i in range(5):
  71. run_cmd(cmd, args.working_directory)
  72. print("\n=====================================================")
  73. print("Sleep 80 seconds to wait TCP server port actually close")
  74. time.sleep(80)
  75. print("\n================================")
  76. print("Test send and receive")
  77. cmd = "./iwasm --addr-pool=127.0.0.1/0 ./send_recv" + suffix
  78. run_cmd(cmd, args.working_directory)
  79. print("\n================================")
  80. print("Test socket options")
  81. cmd = "./iwasm socket_opts" + suffix
  82. run_cmd(cmd, args.working_directory)
  83. print("\n================================")
  84. print("Test timeout server and client")
  85. cmd = "./iwasm --addr-pool=0.0.0.0/15 timeout_server" + suffix
  86. app_server = start_server(cmd, args.working_directory)
  87. # wait for a second
  88. time.sleep(1)
  89. cmd = "./iwasm --addr-pool=127.0.0.1/15 timeout_client" + suffix
  90. run_cmd(cmd, args.working_directory)
  91. print("\n==========================================")
  92. print("Test multicast_client and multicast_server")
  93. cmd = "./iwasm --addr-pool=0.0.0.0/0,::/0 multicast_client.wasm 224.0.0.1"
  94. app_server = start_server(cmd, args.working_directory)
  95. # wait for a second
  96. time.sleep(1)
  97. cmd = "./multicast_server 224.0.0.1"
  98. run_cmd(cmd, args.working_directory)
  99. cmd = "./iwasm --addr-pool=0.0.0.0/0,::/0 multicast_client.wasm FF02:113D:6FDD:2C17:A643:FFE2:1BD1:3CD2"
  100. app_server = start_server(cmd, args.working_directory)
  101. # wait for a second
  102. time.sleep(1)
  103. cmd = "./multicast_server FF02:113D:6FDD:2C17:A643:FFE2:1BD1:3CD2"
  104. run_cmd(cmd, args.working_directory)
  105. print("\n================================")
  106. print("Test address resolving")
  107. cmd = "./iwasm --allow-resolve=*.com addr_resolve.wasm github.com"
  108. run_cmd(cmd, args.working_directory)
  109. # wait for a second
  110. time.sleep(1)
  111. print("--> All pass")
  112. ret = 0
  113. except AssertionError:
  114. traceback.print_exc()
  115. finally:
  116. app_server.kill()
  117. return ret
  118. if __name__ == "__main__":
  119. sys.exit(main())