Files
markbench-tests/3dmark/utils.py
2023-12-15 10:37:51 -08:00

36 lines
1.3 KiB
Python

"""3dmark test utils"""
from pathlib import Path
import psutil
import xml.etree.ElementTree as ET
def is_process_running(process_name):
"""check if given process is running"""
for process in psutil.process_iter(['pid', 'name']):
if process.info['name'] == process_name:
return process
return None
def get_score(element_name, xml_path):
"""fetch the score from the xml report"""
tree = ET.parse(xml_path)
root = tree.getroot()
found_elements = root.findall(f".//{element_name}")
if len(found_elements) == 0:
raise ValueError("Could not find a score in the XML report")
return found_elements[0].text
if __name__ == "__main__":
script_dir = Path(__file__).resolve().parent
firestrike_example = script_dir / "sample_reports" / "firestrike_result.xml"
portroyal_example = script_dir / "sample_reports" / "portroyal_result.xml"
solarbay_example = script_dir / "sample_reports" / "solarbay_result.xml"
timespy_example = script_dir / "sample_reports" / "timespy_result.xml"
scores = []
scores.append(get_score("FireStrike", firestrike_example))
scores.append(get_score("PortRoyal", portroyal_example))
scores.append(get_score("SolarBay", solarbay_example))
scores.append(get_score("TimeSpy", timespy_example))
print(scores)