forked from vadyushkins/kotgll
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsingle_test.py
More file actions
66 lines (56 loc) · 1.61 KB
/
single_test.py
File metadata and controls
66 lines (56 loc) · 1.61 KB
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
import os
import subprocess
import sys
gradlew = "./gradlew"
task = ":test-shared:test"
test_name = sys.argv[1] # example "solver.correctnessTests.AmbiguousAStar3GrammarTest.AmbiguousAStar3GrammarTreeCorrectnessTest"
test_case_name = sys.argv[2] # example "small_test"
def run_test_for_mem(test_name):
def get_cmd(mem):
return [
gradlew,
task,
f"-DtestMaxHeapSize={mem}m",
"--tests", test_name,
f"-Dspecial_case = {test_case_name}",
f"-Dcount_for_case=1"
]
cache = {}
def execute(mem):
if mem in cache:
return cache[mem]
cmd = get_cmd(mem)
process = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
return_code = process.returncode
cache[mem] = return_code
print(return_code)
return return_code
l = 1
r = 64
max_mem = 4*1024
while r <= max_mem:
return_code = execute(r)
if return_code != 0:
l = r
r *= 2
else:
break
print(f"calculate r = {r}")
if r == 2*max_mem:
return r
while l < r - 1:
m = (l + r) // 2
print(m)
return_code = execute(m)
print(f"for {m} mem got code {return_code}")
if return_code != 0:
l = m
else:
r = m
return r
print(test_name)
mem = run_test_for_mem(test_name)
print(f"Got for test = {test_name}: {mem}mb")
with open(f"{test_name.replace('.', '_')}_res.txt", "w") as output:
output.write(f"test,mem\n")
output.write(f"{test_name},{mem}\n")