-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Expand file tree
/
Copy pathtest_coremark.py
More file actions
59 lines (48 loc) · 2.21 KB
/
Copy pathtest_coremark.py
File metadata and controls
59 lines (48 loc) · 2.21 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
import json
import logging
import os
def test_coremark(dut, request):
LOGGER = logging.getLogger(__name__)
# Match "Runs: %d"
res = dut.expect(r"Runs: (\d+)", timeout=60)
runs = int(res.group(0).decode("utf-8").split(" ")[1])
LOGGER.info("Number of runs: {}".format(runs))
assert runs > 0, "Invalid number of runs"
# Match "Cores: %d"
res = dut.expect(r"Cores: (\d+)", timeout=60)
cores = int(res.group(0).decode("utf-8").split(" ")[1])
LOGGER.info("Number of cores: {}".format(cores))
assert cores > 0, "Invalid number of cores"
total_score = 0
for i in range(runs):
# Match "Run %d"
res = dut.expect(r"Run (\d+)", timeout=120)
run = int(res.group(0).decode("utf-8").split(" ")[1])
LOGGER.info("Run {}".format(run))
assert run == i, "Invalid run number"
score = 0
# Match "CoreMark 1.0 : %d"
res = dut.expect(r"CoreMark 1.0 : (\d+)\.(\d+)", timeout=120)
score = float(res.group(0).decode("utf-8").split(" ")[3])
LOGGER.info("CoreMark score: {}".format(score))
assert score > 0 and score < 10000, "Impossible CoreMark score"
total_score += score
avg_score = round(total_score / runs, 2)
LOGGER.info("Average CoreMark score: {}".format(avg_score))
assert avg_score > 0 and avg_score < 10000, "Impossible CoreMark score"
# Create JSON with results and write it to file
# Always create a JSON with this format (so it can be merged later on):
# { TEST_NAME_STR: TEST_RESULTS_DICT }
results = {"coremark": {"runs": runs, "cores": cores, "avg_score": avg_score}}
current_folder = os.path.dirname(request.path)
os.makedirs(os.path.join(current_folder, dut.app.target), exist_ok=True)
file_index = 0
report_file = os.path.join(current_folder, dut.app.target, "result_coremark" + str(file_index) + ".json")
while os.path.exists(report_file):
report_file = report_file.replace(str(file_index) + ".json", str(file_index + 1) + ".json")
file_index += 1
with open(report_file, "w+") as f:
try:
f.write(json.dumps(results))
except Exception as e:
LOGGER.warning("Failed to write results to file: {}".format(e))