|
7 | 7 | import atexit |
8 | 8 | import math |
9 | 9 | import os |
| 10 | +import pathlib |
10 | 11 | import re |
11 | 12 | import shutil |
12 | 13 | import struct |
@@ -81,9 +82,8 @@ def log(data, end='\n'): |
81 | 82 | print(data, end=end) |
82 | 83 | sys.stdout.flush() |
83 | 84 |
|
84 | | -def create_tmp_file(suffix: str) -> str: |
85 | | - with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as tmp_file: |
86 | | - return tmp_file.name |
| 85 | +def create_tmp_file(prefix: str, suffix: str) -> str: |
| 86 | + return tempfile.NamedTemporaryFile(prefix=prefix, suffix=suffix, delete=False).name |
87 | 87 |
|
88 | 88 | # TODO: do we need to support '\n' too |
89 | 89 | import platform |
@@ -1241,10 +1241,10 @@ def run_wasm_with_repl(wasm_tempfile, aot_tempfile, opts, r): |
1241 | 1241 | def create_tmpfiles(wast_name): |
1242 | 1242 | tempfiles = [] |
1243 | 1243 |
|
1244 | | - tempfiles.append(create_tmp_file(".wast")) |
1245 | | - tempfiles.append(create_tmp_file(".wasm")) |
| 1244 | + tempfiles.append(create_tmp_file(wast_name, ".wast")) |
| 1245 | + tempfiles.append(create_tmp_file(wast_name, ".wasm")) |
1246 | 1246 | if test_aot: |
1247 | | - tempfiles.append(create_tmp_file(".aot")) |
| 1247 | + tempfiles.append(create_tmp_file(wast_name, ".aot")) |
1248 | 1248 |
|
1249 | 1249 | # add these temp file to temporal repo, will be deleted when finishing the test |
1250 | 1250 | temp_file_repo.extend(tempfiles) |
@@ -1314,10 +1314,15 @@ def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile, |
1314 | 1314 | else: |
1315 | 1315 | SKIP_TESTS = C_SKIP_TESTS |
1316 | 1316 |
|
1317 | | - wast_tempfile = create_tmp_file(".wast") |
1318 | | - wasm_tempfile = create_tmp_file(".wasm") |
| 1317 | + case_file = pathlib.Path(opts.test_file.name) |
| 1318 | + assert(case_file.exists()), f"Test file {case_file} doesn't exist" |
| 1319 | + |
| 1320 | + case_name = case_file.stem + "_" |
| 1321 | + wast_tempfile = create_tmp_file(case_name, ".wast") |
| 1322 | + wasm_tempfile = create_tmp_file(case_name, ".wasm") |
| 1323 | + |
1319 | 1324 | if test_aot: |
1320 | | - aot_tempfile = create_tmp_file(".aot") |
| 1325 | + aot_tempfile = create_tmp_file(case_name, ".aot") |
1321 | 1326 | # could be potientially compiled to aot |
1322 | 1327 | # with the future following call test_assert_xxx, |
1323 | 1328 | # add them to temp_file_repo now even if no actual following file, |
@@ -1498,35 +1503,35 @@ def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile, |
1498 | 1503 | elif re.match("^\(register\\b.*", form): |
1499 | 1504 | # get module's new name from the register cmd |
1500 | 1505 | name_new =re.split('\"',re.search('\".*\"',form).group(0))[1] |
1501 | | - if name_new: |
1502 | | - if not name_new in temp_module_table: |
1503 | | - print(f"can not find module name {name_new} from the register, use {wasm_tempfile} instead") |
1504 | | - |
1505 | | - just_generated = temp_module_table.get(name_new, wasm_tempfile) |
1506 | | - if not os.path.exists(just_generated): |
1507 | | - raise Exception("can not find file %s" % just_generated) |
1508 | | - |
1509 | | - print("f{just_generated} is copied to {new_module}") |
1510 | | - |
1511 | | - # copy the just generated module into a file with specific name |
1512 | | - new_module = os.path.join(tempfile.gettempdir(), name_new + ".wasm") |
1513 | | - shutil.copyfile(just_generated, new_module) |
1514 | | - |
1515 | | - # add new_module copied from the old into temp_file_repo[] |
1516 | | - temp_file_repo.append(new_module) |
1517 | | - |
1518 | | - if test_aot: |
1519 | | - new_module_aot = os.path.join(tempfile.gettempdir(), name_new + ".aot") |
1520 | | - r = compile_wasm_to_aot(new_module, new_module_aot, True, opts, r) |
1521 | | - try: |
1522 | | - assert_prompt(r, ['Compile success'], opts.start_timeout, True) |
1523 | | - except: |
1524 | | - raise Exception(f"compile wasm to aot failed {r.buf}") |
1525 | | - # add aot module into temp_file_repo[] |
1526 | | - temp_file_repo.append(new_module_aot) |
1527 | | - else: |
| 1506 | + if not name_new: |
1528 | 1507 | # there is no name defined in register cmd |
1529 | | - raise Exception("can not find module name from the register") |
| 1508 | + raise Exception(f"Not following register cmd pattern {form}") |
| 1509 | + |
| 1510 | + # assumption |
| 1511 | + # - There exists a module in the form of (module $name). |
| 1512 | + # - The nearest module in the form of (module), without $name, is the candidate for registration. |
| 1513 | + if not name_new in temp_module_table: |
| 1514 | + print(f"Module {name_new} is not found in temp_module_table. use the nearest module") |
| 1515 | + |
| 1516 | + for_registration = temp_module_table.get(name_new, wasm_tempfile) |
| 1517 | + assert os.path.exists(for_registration), f"module {for_registration} is not found" |
| 1518 | + |
| 1519 | + new_module = os.path.join(tempfile.gettempdir(), name_new + ".wasm") |
| 1520 | + # for_registration(tmpfile) --copy-> name_new.wasm |
| 1521 | + shutil.copyfile(for_registration, new_module) |
| 1522 | + |
| 1523 | + # add new_module copied from the old into temp_file_repo[] |
| 1524 | + temp_file_repo.append(new_module) |
| 1525 | + |
| 1526 | + if test_aot: |
| 1527 | + new_module_aot = os.path.join(tempfile.gettempdir(), name_new + ".aot") |
| 1528 | + r = compile_wasm_to_aot(new_module, new_module_aot, True, opts, r) |
| 1529 | + try: |
| 1530 | + assert_prompt(r, ['Compile success'], opts.start_timeout, True) |
| 1531 | + except: |
| 1532 | + raise Exception("compile wasm to aot failed") |
| 1533 | + # add aot module into temp_file_repo[] |
| 1534 | + temp_file_repo.append(new_module_aot) |
1530 | 1535 | else: |
1531 | 1536 | raise Exception("unrecognized form '%s...'" % form[0:40]) |
1532 | 1537 | except Exception as e: |
|
0 commit comments