Skip to content

Commit

Permalink
fix tests, add proc test
Browse files Browse the repository at this point in the history
Signed-off-by: Elazar Gershuni <[email protected]>
  • Loading branch information
elazarg committed Oct 28, 2024
1 parent eda584c commit e2c4ede
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 35 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ __pycache__
*.log
*.out
*.qcow2
**/cache
**/cache
venv*
**/dumps
59 changes: 31 additions & 28 deletions checkpoint/persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import hashlib
import socket
import struct
from checkpoint.criu_binding import set_criu, criu_dump


FUEL = "FUEL"
STEP = "STEP"
Expand Down Expand Up @@ -243,34 +243,37 @@ def sigint() -> None:
os.kill(PID, signal.SIGINT)


SET_CRIU = False
CRIU_FOLDER = pathlib.Path("criu_images")
CRIU_DUMPS = CRIU_FOLDER / "dumps"
if os.name == "posix":

coredump_iterations = 0
coredump_steps = 0
from checkpoint.criu_binding import set_criu, criu_dump

SET_CRIU = False
CRIU_FOLDER = pathlib.Path("criu_images")
CRIU_DUMPS = CRIU_FOLDER / "dumps"

def self_coredump() -> None:
global coredump_iterations, coredump_steps
if not coredump_iterations:
CRIU_FOLDER.mkdir(exist_ok=True)
shutil.rmtree(CRIU_DUMPS, ignore_errors=True)
CRIU_DUMPS.mkdir(exist_ok=False)
set_criu(CRIU_FOLDER)
coredump_iterations += 1
coredump_iterations = 0
coredump_steps = 0

if coredump_iterations % STEP_VALUE in [0, 1]:
criu_dump()
image_file = CRIU_FOLDER / "pages-1.img"
if not image_file.exists():
raise RuntimeError(
"CRIU image was not created. Make sure to run the CRIU service:\n"
"sudo criu service --shell-job --address /tmp/criu_service.socket"
)
target_image = CRIU_DUMPS / f"{coredump_steps:05d}.a.img"
os.rename(CRIU_FOLDER / "pages-1.img", target_image)
if coredump_steps > 0:
source_image = CRIU_DUMPS / f"{coredump_steps-1:05d}.b.img"
source_image.hardlink_to(target_image)
coredump_steps += 1
def self_coredump() -> None:
global coredump_iterations, coredump_steps
if not coredump_iterations:
CRIU_FOLDER.mkdir(exist_ok=True)
shutil.rmtree(CRIU_DUMPS, ignore_errors=True)
CRIU_DUMPS.mkdir(exist_ok=False)
set_criu(CRIU_FOLDER)
coredump_iterations += 1

if coredump_iterations % STEP_VALUE in [0, 1]:
criu_dump()
image_file = CRIU_FOLDER / "pages-1.img"
if not image_file.exists():
raise RuntimeError(
"CRIU image was not created. Make sure to run the CRIU service:\n"
"sudo criu service --shell-job --address /tmp/criu_service.socket"
)
target_image = CRIU_DUMPS / f"{coredump_steps:05d}.a.img"
os.rename(CRIU_FOLDER / "pages-1.img", target_image)
if coredump_steps > 0:
source_image = CRIU_DUMPS / f"{coredump_steps-1:05d}.b.img"
source_image.hardlink_to(target_image)
coredump_steps += 1
27 changes: 21 additions & 6 deletions tests/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def naive_transform(filename: pathlib.Path, expected_outfile: pathlib.Path) -> N
compare_transformed_files(actual, expected_outfile)


@pytest.mark.parametrize(
"experiment_name", ["k_means", "omp", "pivoter", "trivial"]
)
@pytest.mark.parametrize("experiment_name", ["k_means", "omp", "pivoter", "trivial"])
def test_naive_transformation(experiment_name: str) -> None:
exp = pathlib.Path("experiment") / experiment_name
naive_transform(
Expand All @@ -45,9 +43,7 @@ def tcp_transform(
compare_transformed_files(actual, expected_outfile)


@pytest.mark.parametrize(
"experiment_name", ["k_means", "omp", "pivoter", "trivial"]
)
@pytest.mark.parametrize("experiment_name", ["k_means", "omp", "pivoter", "trivial"])
def test_tcp_transformation(experiment_name: str) -> None:
exp = pathlib.Path("experiment") / experiment_name
filename = exp / "main.py"
Expand All @@ -60,6 +56,25 @@ def test_tcp_transformation(experiment_name: str) -> None:
)


def proc_transform(
filename: pathlib.Path, function_name: str, expected_outfile: pathlib.Path
) -> None:
actual = ast_transform.coredump(filename, function_name)
compare_transformed_files(actual, expected_outfile)


@pytest.mark.parametrize("experiment_name", ["k_means", "omp", "pivoter", "trivial"])
def test_proc_transformation(experiment_name: str) -> None:
exp = pathlib.Path("experiment") / experiment_name
filename = exp / "main.py"
expected_outfile = exp / "proc.py"
proc_transform(
function_name="run",
filename=filename,
expected_outfile=expected_outfile,
)


def analyze_and_transform(
experiment_name: str, function_name: str, simplify: bool
) -> None:
Expand Down

0 comments on commit e2c4ede

Please sign in to comment.