1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-25 17:09:44 +00:00

feat(core): adjust the coverage file output for multicore tests

When the tests are run using multiple cores, there will

be one .coverage file for each core. So that the one file

is not being overwritten many times, using unique

filename for each core.

[no changelog]
This commit is contained in:
grdddj 2023-03-08 12:44:51 +01:00 committed by Jiří Musil
parent 41e07769e2
commit 07797158db

View File

@ -50,7 +50,14 @@ class _Prof:
def write_data(self): def write_data(self):
print("Total traces executed: ", __prof__.trace_count) print("Total traces executed: ", __prof__.trace_count)
with open(".coverage", "w") as f: # In case of multithreaded tests, we might be called multiple times.
# Making sure the threads do not overwrite each other's data.
worker_id = getenv("PYTEST_XDIST_WORKER")
if worker_id:
file_name = f".coverage.{worker_id}"
else:
file_name = ".coverage"
with open(file_name, "w") as f:
# wtf so private much beautiful wow # wtf so private much beautiful wow
f.write("!coverage.py: This is a private format, don't read it directly!") f.write("!coverage.py: This is a private format, don't read it directly!")
# poormans json # poormans json
@ -67,10 +74,13 @@ class AllocCounter:
if self.last_line is None: if self.last_line is None:
return return
entry = self.data.setdefault(self.last_line, { entry = self.data.setdefault(
"total_allocs": 0, self.last_line,
"calls": 0, {
}) "total_allocs": 0,
"calls": 0,
},
)
entry["total_allocs"] += allocs entry["total_allocs"] += allocs
entry["calls"] += 1 entry["calls"] += 1