Skip to content

Commit 37ff9dd

Browse files
committed
Add memory test
1 parent fa986b4 commit 37ff9dd

4 files changed

Lines changed: 155 additions & 3 deletions

File tree

all_test.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import os
2+
import subprocess
3+
import sys
4+
5+
gradlew = "./gradlew"
6+
task = ":test-shared:test"
7+
8+
test_name = "" # example "solver.correctnessTests.AmbiguousAStar3GrammarTest.AmbiguousAStar3GrammarTreeCorrectnessTest"
9+
test_case_name = "" # example "small_test"
10+
def run_test_for_mem(test_name):
11+
def get_cmd(mem):
12+
return [
13+
gradlew,
14+
task,
15+
f"-DtestMaxHeapSize={mem}m",
16+
"--tests", test_name,
17+
f"-Dspecial_case = {test_case_name}",
18+
f"-Dcount_for_case=1"
19+
]
20+
21+
cache = {}
22+
23+
def execute(mem):
24+
if mem in cache:
25+
return cache[mem]
26+
27+
cmd = get_cmd(mem)
28+
process = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
29+
return_code = process.returncode
30+
cache[mem] = return_code
31+
return return_code
32+
33+
l = 1
34+
r = 64
35+
max_mem = 4*1024
36+
while r <= max_mem:
37+
return_code = execute(r)
38+
if return_code != 0:
39+
l = r
40+
r *= 2
41+
else:
42+
break
43+
if r == 2*max_mem:
44+
return r
45+
46+
while l < r - 1:
47+
m = (l + r) // 2
48+
return_code = execute(m)
49+
50+
if return_code != 0:
51+
l = m
52+
else:
53+
r = m
54+
55+
return r
56+
57+
58+
with open("tests_list.conf", "r") as input:
59+
with open(f"res.txt", "w") as output:
60+
output.write(f"test,mem\n")
61+
for line in input:
62+
config = line.split()
63+
test_name = config[0]
64+
test_case_name = config[1]
65+
print(test_name)
66+
print(test_case_name)
67+
mem = run_test_for_mem(test_name)
68+
print(f"Got for test = {test_name}: {mem}mb")
69+
70+
output.write(f"{test_name},{mem}\n")

single_test.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import os
2+
import subprocess
3+
import sys
4+
5+
gradlew = "./gradlew"
6+
task = ":test-shared:test"
7+
8+
test_name = sys.argv[1] # example "solver.correctnessTests.AmbiguousAStar3GrammarTest.AmbiguousAStar3GrammarTreeCorrectnessTest"
9+
test_case_name = sys.argv[2] # example "small_test"
10+
def run_test_for_mem(test_name):
11+
def get_cmd(mem):
12+
return [
13+
gradlew,
14+
task,
15+
f"-DtestMaxHeapSize={mem}m",
16+
"--tests", test_name,
17+
f"-Dspecial_case = {test_case_name}",
18+
f"-Dcount_for_case=1"
19+
]
20+
21+
cache = {}
22+
23+
def execute(mem):
24+
if mem in cache:
25+
return cache[mem]
26+
27+
cmd = get_cmd(mem)
28+
process = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
29+
return_code = process.returncode
30+
cache[mem] = return_code
31+
print(return_code)
32+
return return_code
33+
34+
l = 1
35+
r = 64
36+
max_mem = 4*1024
37+
while r <= max_mem:
38+
return_code = execute(r)
39+
if return_code != 0:
40+
l = r
41+
r *= 2
42+
else:
43+
break
44+
print(f"calculate r = {r}")
45+
if r == 2*max_mem:
46+
return r
47+
48+
while l < r - 1:
49+
m = (l + r) // 2
50+
print(m)
51+
return_code = execute(m)
52+
print(f"for {m} mem got code {return_code}")
53+
54+
if return_code != 0:
55+
l = m
56+
else:
57+
r = m
58+
59+
return r
60+
61+
print(test_name)
62+
mem = run_test_for_mem(test_name)
63+
print(f"Got for test = {test_name}: {mem}mb")
64+
with open(f"{test_name.replace('.', '_')}_res.txt", "w") as output:
65+
output.write(f"test,mem\n")
66+
output.write(f"{test_name},{mem}\n")

test-shared/build.gradle.kts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ dependencies {
2121
tasks.test {
2222
useJUnitPlatform()
2323
val heapSize = (System.getProperty("testMaxHeapSize") ?: "100m") // ограничение памяти для JVM тестов
24+
val special_case = System.getProperty("special_case") ?: "nothing"
25+
val count_for_case = System.getProperty("count_for_case") ?: "50"
2426
maxHeapSize = heapSize
27+
2528
jvmArgs(
26-
"-XX:+PrintGCDetails",
27-
"-Xlog:gc*:file=gc.log:time,uptime,level,tags"
29+
// "-XX:+PrintGCDetails",
30+
// "-Xlog:gc*:file=gc.log:time,uptime,level,tags",
31+
"-Dspecial_case=$special_case",
32+
"-Dcount_for_case=$count_for_case"
2833
)
2934
}
3035
kotlin {

test-shared/src/test/kotlin/solver/benchmarks/AbstractBenchmarkTest.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,17 @@ abstract class AbstractBenchmarkTest {
7878
}
7979
testCasesFolder.createDirectory()
8080
result_folder.createDirectory()
81+
val special_case = System.getProperty("special_case")
82+
83+
8184
for (folder in testCasesFolder.listFiles()) {
85+
if((!special_case.isNullOrEmpty() && special_case != "nothing") && folder.name != special_case) {
86+
87+
println(special_case.isNullOrEmpty())
88+
continue;
89+
}
8290
if (folder.isDirectory) {
91+
println(special_case)
8392
println(folder.name)
8493
println(File(Path(result_folder.path).resolve(folder.name).toUri() ))
8594
val bechmark_result_folder = File(Path(result_folder.path).resolve(folder.name).toUri() )
@@ -107,8 +116,10 @@ abstract class AbstractBenchmarkTest {
107116
println("Work time: $testCasesFolder")
108117
val used = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024)
109118
println("Used memory: " + used + " MB")
119+
val max_test_count = System.getProperty("count_for_case").toInt()
120+
println("Used memorsssssy: " + max_test_count + " MB")
110121
MemoryMonitor.start()
111-
while (x < 1000) {
122+
while (x < max_test_count) {
112123
val start = System.nanoTime()
113124
val actualResult = createTree(input, grammar)
114125
val workTime = System.nanoTime() - start

0 commit comments

Comments
 (0)