-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_generate.py
111 lines (87 loc) · 3.09 KB
/
test_generate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import pathlib
from typing import Any
import pytest
from pythia import analysis, ast_transform
def find_transaction(text: str) -> list[tuple[int, Any]]:
return [
(i, line.strip())
for i, line in enumerate(text.splitlines())
if "transaction.move" in line
]
def compare_transformed_files(actual: str, expected_outfile: pathlib.Path) -> None:
expected = expected_outfile.read_text(encoding="utf-8")
expected_transaction = find_transaction(expected)
actual_transaction = find_transaction(actual)
assert actual == expected
assert actual_transaction == expected_transaction
def naive_transform(filename: pathlib.Path, expected_outfile: pathlib.Path) -> None:
actual = ast_transform.transform(filename, dirty_map=None)
compare_transformed_files(actual, expected_outfile)
@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(
filename=exp / "main.py",
expected_outfile=exp / "naive.py",
)
def tcp_transform(
tag: str, filename: pathlib.Path, function_name: str, expected_outfile: pathlib.Path
) -> None:
actual = ast_transform.tcp_client(tag, filename, function_name)
compare_transformed_files(actual, expected_outfile)
@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"
expected_outfile = exp / "vm.py"
tcp_transform(
tag=experiment_name,
function_name="run",
filename=filename,
expected_outfile=expected_outfile,
)
def analyze_and_transform(
experiment_name: str, function_name: str, simplify: bool
) -> None:
exp = pathlib.Path("experiment") / experiment_name
filename = exp / "main.py"
expected_outfile = exp / "instrumented.py"
actual = analysis.analyze_and_transform(
filename=filename,
function_name=function_name,
print_invariants=False,
simplify=simplify,
)
compare_transformed_files(actual, expected_outfile)
@pytest.mark.parametrize("simplify", [True, False])
def test_analyze_omp(simplify: bool) -> None:
analyze_and_transform(
experiment_name="omp",
function_name="run",
simplify=simplify,
)
@pytest.mark.parametrize("simplify", [True, False])
def test_k_means(simplify: bool) -> None:
analyze_and_transform(
experiment_name="k_means",
function_name="run",
simplify=simplify,
)
@pytest.mark.parametrize("simplify", [True, False])
def test_pivoter(simplify: bool) -> None:
analyze_and_transform(
experiment_name="pivoter",
function_name="run",
simplify=simplify,
)
@pytest.mark.parametrize("simplify", [True, False])
def test_trivial(simplify: bool) -> None:
analyze_and_transform(
experiment_name="trivial",
function_name="run",
simplify=simplify,
)