Skip to content

Commit

Permalink
Remove any possibility to run tests in parallel.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Aug 26, 2024
1 parent 7c4c3ea commit a3264e5
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 112 deletions.
2 changes: 2 additions & 0 deletions suite/auto-sync/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ vendor/llvm_root
src/auto-sync/config.json
src/autosync/cpptranslator/Tests/Differ/test_saved_patches.json
src/autosync.egg-info
src/autosync/Tests/MCUpdaterTests/ARCH/Output
src/autosync/Tests/MCUpdaterTests/Disassembler/ARCH/Output
src/autosync/lit_config/test_dir_*
src/autosync/lit_config/.lit_test_times.txt
src/autosync/Tests/MCUpdaterTests/test_output

This file was deleted.

This file was deleted.

This file was deleted.

214 changes: 106 additions & 108 deletions suite/auto-sync/src/autosync/Tests/test_mcupdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sys
import unittest
from pathlib import Path
from threading import Lock

from autosync.Helper import get_path, test_only_overwrite_path_var
from autosync.MCUpdater import MCUpdater
Expand All @@ -21,117 +20,112 @@ def setUpClass(cls):
format="%(levelname)-5s - %(message)s",
force=True,
)
cls.mutex = Lock()

def test_unified_test_cases(self):
with self.mutex:
out_dir = Path(
get_path("{MCUPDATER_TEST_OUT_DIR}")
.joinpath("merged")
.joinpath("unified")
)
if not out_dir.exists():
out_dir.mkdir(parents=True)
for file in out_dir.iterdir():
logging.debug(f"Delete old file: {file}")
os.remove(file)
test_only_overwrite_path_var(
"{MCUPDATER_OUT_DIR}",
out_dir,
)
self.updater = MCUpdater(
"ARCH", get_path("{MCUPDATER_TEST_DIR}"), [], [], True
)
self.updater.gen_all()
self.assertTrue(
self.compare_files(out_dir, ["test_a.txt.yaml", "test_b.txt.yaml"])
)
def test_test_case_gen(self):
"""
To enforce sequential execution of the tests, we execute them in here.
And don't make them a separated test.
"""
self.assertTrue(self.unified_test_cases(), "Failed: unified_test_cases")
self.assertTrue(self.separated_test_cases(), "Failed: separated_test_cases")
self.assertTrue(
self.multi_mode_unified_test_cases(),
"Failed: multi_mode_unified_test_cases",
)
self.assertTrue(
self.multi_mode_separated_test_cases(),
"Failed: multi_mode_separated_test_cases",
)

def unified_test_cases(self):
out_dir = Path(
get_path("{MCUPDATER_TEST_OUT_DIR}").joinpath("merged").joinpath("unified")
)
if not out_dir.exists():
out_dir.mkdir(parents=True)
for file in out_dir.iterdir():
logging.debug(f"Delete old file: {file}")
os.remove(file)
test_only_overwrite_path_var(
"{MCUPDATER_OUT_DIR}",
out_dir,
)
self.updater = MCUpdater("ARCH", get_path("{MCUPDATER_TEST_DIR}"), [], [], True)
self.updater.gen_all()
return self.compare_files(out_dir, ["test_a.txt.yaml", "test_b.txt.yaml"])

def test_separated_test_cases(self):
with self.mutex:
out_dir = Path(
get_path("{MCUPDATER_TEST_OUT_DIR}")
.joinpath("merged")
.joinpath("separated")
)
if not out_dir.exists():
out_dir.mkdir(parents=True)
for file in out_dir.iterdir():
logging.debug(f"Delete old file: {file}")
os.remove(file)
test_only_overwrite_path_var(
"{MCUPDATER_OUT_DIR}",
out_dir,
)
self.updater = MCUpdater(
"ARCH", get_path("{MCUPDATER_TEST_DIR}"), [], [], False
)
self.updater.gen_all()
self.assertTrue(
self.compare_files(out_dir, ["test_a.txt.yaml", "test_b.txt.yaml"])
)
def separated_test_cases(self):
out_dir = Path(
get_path("{MCUPDATER_TEST_OUT_DIR}")
.joinpath("merged")
.joinpath("separated")
)
if not out_dir.exists():
out_dir.mkdir(parents=True)
for file in out_dir.iterdir():
logging.debug(f"Delete old file: {file}")
os.remove(file)
test_only_overwrite_path_var(
"{MCUPDATER_OUT_DIR}",
out_dir,
)
self.updater = MCUpdater(
"ARCH", get_path("{MCUPDATER_TEST_DIR}"), [], [], False
)
self.updater.gen_all()
return self.compare_files(out_dir, ["test_a.txt.yaml", "test_b.txt.yaml"])

def test_multi_mode_unified_test_cases(self):
with self.mutex:
out_dir = Path(
get_path("{MCUPDATER_TEST_OUT_DIR}")
.joinpath("multi")
.joinpath("unified")
)
if not out_dir.exists():
out_dir.mkdir(parents=True)
for file in out_dir.iterdir():
logging.debug(f"Delete old file: {file}")
os.remove(file)
test_only_overwrite_path_var(
"{MCUPDATER_OUT_DIR}",
out_dir,
)
self.updater = MCUpdater(
"ARCH", get_path("{MCUPDATER_TEST_DIR}"), [], [], True, multi_mode=True
)
self.updater.gen_all()
self.assertTrue(
self.compare_files(
out_dir,
[
"test_a_aarch64_v8a__fp_armv8.txt.yaml",
"test_a_arm64_v8.2a.txt.yaml",
"test_b_arm64.txt.yaml",
],
)
)
def multi_mode_unified_test_cases(self):
out_dir = Path(
get_path("{MCUPDATER_TEST_OUT_DIR}").joinpath("multi").joinpath("unified")
)
if not out_dir.exists():
out_dir.mkdir(parents=True)
for file in out_dir.iterdir():
logging.debug(f"Delete old file: {file}")
os.remove(file)
test_only_overwrite_path_var(
"{MCUPDATER_OUT_DIR}",
out_dir,
)
self.updater = MCUpdater(
"ARCH", get_path("{MCUPDATER_TEST_DIR}"), [], [], True, multi_mode=True
)
self.updater.gen_all()
return self.compare_files(
out_dir,
[
"test_a_aarch64_v8a__fp_armv8.txt.yaml",
"test_a_arm64_v8.2a.txt.yaml",
"test_b_arm64.txt.yaml",
],
)

def test_multi_mode_separated_test_cases(self):
with self.mutex:
out_dir = Path(
get_path("{MCUPDATER_TEST_OUT_DIR}")
.joinpath("multi")
.joinpath("separated")
)
if not out_dir.exists():
out_dir.mkdir(parents=True)
for file in out_dir.iterdir():
logging.debug(f"Delete old file: {file}")
os.remove(file)
test_only_overwrite_path_var(
"{MCUPDATER_OUT_DIR}",
out_dir,
)
self.updater = MCUpdater(
"ARCH", get_path("{MCUPDATER_TEST_DIR}"), [], [], False, multi_mode=True
)
self.updater.gen_all()
self.assertTrue(
self.compare_files(
out_dir,
[
"test_a_aarch64_v8a__fp_armv8.txt.yaml",
"test_a_arm64_v8.2a.txt.yaml",
"test_b_arm64.txt.yaml",
],
)
)
def multi_mode_separated_test_cases(self):
out_dir = Path(
get_path("{MCUPDATER_TEST_OUT_DIR}").joinpath("multi").joinpath("separated")
)
if not out_dir.exists():
out_dir.mkdir(parents=True)
for file in out_dir.iterdir():
logging.debug(f"Delete old file: {file}")
os.remove(file)
test_only_overwrite_path_var(
"{MCUPDATER_OUT_DIR}",
out_dir,
)
self.updater = MCUpdater(
"ARCH", get_path("{MCUPDATER_TEST_DIR}"), [], [], False, multi_mode=True
)
self.updater.gen_all()
return self.compare_files(
out_dir,
[
"test_a_aarch64_v8a__fp_armv8.txt.yaml",
"test_a_arm64_v8.2a.txt.yaml",
"test_b_arm64.txt.yaml",
],
)

def compare_files(self, out_dir: Path, filenames: list[str]) -> bool:
if not out_dir.is_dir():
Expand All @@ -153,16 +147,20 @@ def compare_files(self, out_dir: Path, filenames: list[str]) -> bool:
logging.error(f"{efile} does not exist")
return False
with open(efile) as f:
logging.debug(f"Read {efile}")
expected = f.read()

afile = out_dir.joinpath(file)
if not afile.exists():
logging.error(f"{afile} does not exist")
return False
with open(afile) as f:
logging.debug(f"Read {afile}")
actual = f.read()
if expected != actual:
logging.error("Files mismatch")
print(f"Expected: {efile}")
print(f"Actual: {afile}\n")
print(f"Expected:\n\n{expected}\n")
print(f"Actual:\n\n{actual}\n")
return False
Expand Down

0 comments on commit a3264e5

Please sign in to comment.