Skip to content

Commit e1f9c0b

Browse files
committed
add setting for tests
1 parent 37ff9dd commit e1f9c0b

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

all_test.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ def get_cmd(mem):
1414
task,
1515
f"-DtestMaxHeapSize={mem}m",
1616
"--tests", test_name,
17-
f"-Dspecial_case = {test_case_name}",
18-
f"-Dcount_for_case=1"
17+
f"-Dspecial_case={test_case_name}",
18+
f"-Dcount_for_case=1",
19+
f"-Dwrite_case_time=0"
1920
]
2021

2122
cache = {}
@@ -25,8 +26,11 @@ def execute(mem):
2526
return cache[mem]
2627

2728
cmd = get_cmd(mem)
28-
process = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
29-
return_code = process.returncode
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
3034
cache[mem] = return_code
3135
return return_code
3236

@@ -35,6 +39,7 @@ def execute(mem):
3539
max_mem = 4*1024
3640
while r <= max_mem:
3741
return_code = execute(r)
42+
print(r)
3843
if return_code != 0:
3944
l = r
4045
r *= 2
@@ -45,6 +50,7 @@ def execute(mem):
4550

4651
while l < r - 1:
4752
m = (l + r) // 2
53+
print(m)
4854
return_code = execute(m)
4955

5056
if return_code != 0:
@@ -57,14 +63,23 @@ def execute(mem):
5763

5864
with open("tests_list.conf", "r") as input:
5965
with open(f"res.txt", "w") as output:
60-
output.write(f"test,mem\n")
66+
output.write(f"test,case,mem\n")
6167
for line in input:
6268
config = line.split()
6369
test_name = config[0]
6470
test_case_name = config[1]
6571
print(test_name)
6672
print(test_case_name)
6773
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
6884
print(f"Got for test = {test_name}: {mem}mb")
69-
70-
output.write(f"{test_name},{mem}\n")
85+
output.write(f"{test_name},{test_case_name},{mem}\n")

test-shared/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ tasks.test {
2323
val heapSize = (System.getProperty("testMaxHeapSize") ?: "100m") // ограничение памяти для JVM тестов
2424
val special_case = System.getProperty("special_case") ?: "nothing"
2525
val count_for_case = System.getProperty("count_for_case") ?: "50"
26+
val write_case_time = System.getProperty("write_case_time") ?: "1"
2627
maxHeapSize = heapSize
2728

2829
jvmArgs(
2930
// "-XX:+PrintGCDetails",
3031
// "-Xlog:gc*:file=gc.log:time,uptime,level,tags",
3132
"-Dspecial_case=$special_case",
32-
"-Dcount_for_case=$count_for_case"
33+
"-Dcount_for_case=$count_for_case",
34+
"-Dwrite_case_time=$write_case_time"
3335
)
3436
}
3537
kotlin {

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ abstract class AbstractBenchmarkTest {
8484
for (folder in testCasesFolder.listFiles()) {
8585
if((!special_case.isNullOrEmpty() && special_case != "nothing") && folder.name != special_case) {
8686

87-
println(special_case.isNullOrEmpty())
87+
8888
continue;
8989
}
9090
if (folder.isDirectory) {
@@ -105,9 +105,12 @@ abstract class AbstractBenchmarkTest {
105105
val time = LocalDateTime.now()
106106
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
107107
val formattedDateTime = time.format(formatter)
108-
val logsFile = File(result_folder.toPath().toString(), formattedDateTime+"work_times" +".logs")
109-
val resultsLog = File(result_folder.toPath().toString(), formattedDateTime+"results" +".logs")
110-
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+
}
111114
var x = 0
112115
var logs = ""
113116
val timeMeasurements = mutableListOf<Long>()
@@ -117,7 +120,6 @@ abstract class AbstractBenchmarkTest {
117120
val used = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024)
118121
println("Used memory: " + used + " MB")
119122
val max_test_count = System.getProperty("count_for_case").toInt()
120-
println("Used memorsssssy: " + max_test_count + " MB")
121123
MemoryMonitor.start()
122124
while (x < max_test_count) {
123125
val start = System.nanoTime()
@@ -143,12 +145,18 @@ abstract class AbstractBenchmarkTest {
143145
println("===========================")
144146
// останавливаем и получаем пик
145147
println("Peak memory usage: $peak MB")
146-
logsFile.writeText(logs)
148+
if(System.getProperty("write_case_time") == "1") {
149+
logsFile?.writeText(logs)
150+
}
147151
logs = "\n=== PERFORMANCE RESULTS === \n Total iterations: ${timeMeasurements.size} \n Average time: ${"%.3f".format(averageTime / 1_000_000)} ms" +
148152
"\n Min time: ${minTime / 1_000_000} ms" +
149153
"\nMax time: ${maxTime / 1_000_000} ms" +
150-
"Total time: ${totalTime / 1_000_000_000.0} seconds"
151-
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+
}
152160

153161
}
154162

0 commit comments

Comments
 (0)