run.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/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. import argparse
  8. from typing import List, Dict, Tuple
  9. import json
  10. WORK_DIR = os.getcwd()
  11. WAMR_DIR = os.path.join(WORK_DIR, "../../..")
  12. IWASM_CMD = os.path.join(
  13. WORK_DIR, "../../../product-mini/platforms/linux/build/iwasm")
  14. WAMRC_CMD = os.path.join(WORK_DIR, "../../../wamr-compiler/build/wamrc")
  15. SUBREQUIREMENT_DESCRIPTIONS = {
  16. 1: ("633", "Modify existing opcodes to conform to the semantics of the GC proposal when needed."),
  17. 2: ("634", "Supporting new GC opcodes(semantics of GC MVP proposal spec)."),
  18. 3: ("635", "Supporting new GC opcode(semantics of Binaryen GC spec)."),
  19. }
  20. def test_subrequirement(id: int) -> Dict[Tuple[str, str], bool]:
  21. print(f"\n============> test gc aot requirement: {id}")
  22. test_cases = {}
  23. result = {}
  24. with open('test_cases.json') as config_file:
  25. config = json.load(config_file)
  26. for req in config["sub-requirements"]:
  27. if req['req_id'] == id:
  28. test_cases = req['cases']
  29. break
  30. for case in test_cases:
  31. print(case)
  32. print(f"{case['name']}.aot")
  33. exit_status = os.system(
  34. f"python runtest.py --aot --wast2wasm spec/interpreter/wasm --interpreter {IWASM_CMD} --aot-compiler {WAMRC_CMD} --gc wasm-apps/{case['name']}.wast"
  35. )
  36. if exit_status == 0:
  37. result[case['name'], case['description']] = True
  38. else:
  39. result[case['name'], case['description']] = False
  40. return result
  41. def run(
  42. output_dir: str, subrequirement_ids: List[int]
  43. ) -> Dict[int, Dict[Tuple[str, str], bool]]:
  44. # key: value -> subrequirement id: dict[tuple(test_case_name, test_case_description), is_success]
  45. result_dict: Dict[int, Dict[Tuple[str, str], bool]] = {}
  46. # Default run all subrequirement
  47. if not subrequirement_ids:
  48. subrequirement_ids = [1, 2, 3]
  49. for subrequirement_id in subrequirement_ids:
  50. if subrequirement_id not in SUBREQUIREMENT_DESCRIPTIONS.keys():
  51. print(
  52. f"Subrequirement id invalid! It should be a value in {[_ for _ in SUBREQUIREMENT_DESCRIPTIONS.keys()]}"
  53. )
  54. continue
  55. result_dict[subrequirement_id] = test_subrequirement(subrequirement_id)
  56. return result_dict
  57. if __name__ == "__main__":
  58. print("============> test GC AOT")
  59. # Create the parser
  60. parser = argparse.ArgumentParser(
  61. description="A script to process sub-requirement ids, run corresponding test cases, and compile wamrc, iwasm if requested."
  62. )
  63. # The argparse module handles -h and --help by default, no needs to add it
  64. # Add an output option `-o` as a flag that, when specified, sets the variable to True
  65. parser.add_argument(
  66. "-o",
  67. "--output",
  68. type=str,
  69. required=False,
  70. help="Specify the output file name. If provided, the script will write the results to <file name>.csv",
  71. )
  72. # Add positional arguments for integers
  73. parser.add_argument(
  74. "integers",
  75. metavar="N",
  76. type=int,
  77. nargs="*",
  78. help="an integer for the sub-requirement ids",
  79. )
  80. # Parse arguments
  81. args = parser.parse_args()
  82. run(args.output, args.integers)