Skip to content

Commit 165a0c2

Browse files
committed
Merge branch 'create_new_memory_test_and_scripts_for_test' into new_main
2 parents b91de46 + 25f0e50 commit 165a0c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+187
-20667
lines changed

all_test.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
f"-Dwrite_case_time=0"
20+
]
21+
22+
cache = {}
23+
24+
def execute(mem):
25+
if mem in cache:
26+
return cache[mem]
27+
28+
cmd = get_cmd(mem)
29+
try:
30+
process = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,timeout=60)
31+
return_code = process.returncode
32+
except:
33+
return_code = 1
34+
cache[mem] = return_code
35+
return return_code
36+
37+
l = 1
38+
r = 64
39+
max_mem = 4*1024
40+
while r <= max_mem:
41+
return_code = execute(r)
42+
print(r)
43+
if return_code != 0:
44+
l = r
45+
r *= 2
46+
else:
47+
break
48+
if r == 2*max_mem:
49+
return r
50+
51+
while l < r - 1:
52+
m = (l + r) // 2
53+
print(m)
54+
return_code = execute(m)
55+
56+
if return_code != 0:
57+
l = m
58+
else:
59+
r = m
60+
61+
return r
62+
63+
64+
with open("tests_list.conf", "r") as input:
65+
with open(f"res.txt", "w") as output:
66+
output.write(f"test,case,mem\n")
67+
for line in input:
68+
config = line.split()
69+
test_name = config[0]
70+
test_case_name = config[1]
71+
print(test_name)
72+
print(test_case_name)
73+
mem = run_test_for_mem(test_name)
74+
cmd = [
75+
gradlew,
76+
task,
77+
f"-DtestMaxHeapSize=15m",
78+
"--tests", test_name,
79+
f"-Dspecial_case={test_case_name}",
80+
f"-Dcount_for_case=1"
81+
]
82+
process = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
83+
return_code = process.returncode
84+
print(f"Got for test = {test_name}: {mem}mb")
85+
output.write(f"{test_name},{test_case_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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ 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"
26+
val write_case_time = System.getProperty("write_case_time") ?: "1"
2427
maxHeapSize = heapSize
28+
2529
jvmArgs(
26-
"-XX:+PrintGCDetails",
27-
"-Xlog:gc*:file=gc.log:time,uptime,level,tags"
30+
// "-XX:+PrintGCDetails",
31+
// "-Xlog:gc*:file=gc.log:time,uptime,level,tags",
32+
"-Dspecial_case=$special_case",
33+
"-Dcount_for_case=$count_for_case",
34+
"-Dwrite_case_time=$write_case_time"
2835
)
2936
}
3037
kotlin {

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

Lines changed: 27 additions & 8 deletions
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+
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() )
@@ -96,9 +105,12 @@ abstract class AbstractBenchmarkTest {
96105
val time = LocalDateTime.now()
97106
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
98107
val formattedDateTime = time.format(formatter)
99-
val logsFile = File(result_folder.toPath().toString(), formattedDateTime+"work_times" +".logs")
100-
val resultsLog = File(result_folder.toPath().toString(), formattedDateTime+"results" +".logs")
101-
val actualResult = createTree(input, grammar)
108+
var logsFile: File? = null
109+
var resultsLog: File? = null
110+
if(System.getProperty("write_case_time") == "1") {
111+
logsFile = File(result_folder.toPath().toString(), formattedDateTime + "work_times" + ".logs")
112+
resultsLog = File(result_folder.toPath().toString(), formattedDateTime + "results" + ".logs")
113+
}
102114
var x = 0
103115
var logs = ""
104116
val timeMeasurements = mutableListOf<Long>()
@@ -107,8 +119,9 @@ abstract class AbstractBenchmarkTest {
107119
println("Work time: $testCasesFolder")
108120
val used = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024)
109121
println("Used memory: " + used + " MB")
122+
val max_test_count = System.getProperty("count_for_case").toInt()
110123
MemoryMonitor.start()
111-
while (x < 1000) {
124+
while (x < max_test_count) {
112125
val start = System.nanoTime()
113126
val actualResult = createTree(input, grammar)
114127
val workTime = System.nanoTime() - start
@@ -130,14 +143,20 @@ abstract class AbstractBenchmarkTest {
130143
println("Max time: ${maxTime / 1_000_000} ms")
131144
println("Total time: ${totalTime / 1_000_000_000.0} seconds")
132145
println("===========================")
133-
// останавливаем и получаем пик
146+
134147
println("Peak memory usage: $peak MB")
135-
logsFile.writeText(logs)
148+
if(System.getProperty("write_case_time") == "1") {
149+
logsFile?.writeText(logs)
150+
}
136151
logs = "\n=== PERFORMANCE RESULTS === \n Total iterations: ${timeMeasurements.size} \n Average time: ${"%.3f".format(averageTime / 1_000_000)} ms" +
137152
"\n Min time: ${minTime / 1_000_000} ms" +
138153
"\nMax time: ${maxTime / 1_000_000} ms" +
139-
"Total time: ${totalTime / 1_000_000_000.0} seconds"
140-
resultsLog.writeText(logs)
154+
"\nTotal time: ${totalTime / 1_000_000_000.0} seconds"+
155+
"\nPeak memory usage: $peak MB"
156+
157+
if(System.getProperty("write_case_time") == "1") {
158+
resultsLog?.writeText(logs)
159+
}
141160

142161
}
143162

test-shared/src/test/resources/benchmarks/BipartitleGrammar/1/input.dot

Lines changed: 0 additions & 4 deletions
This file was deleted.

test-shared/src/test/resources/benchmarks/BipartitleGrammar/10/input.dot

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)