mirror of
https://github.com/LTTLabsOSS/markbench-tests.git
synced 2026-04-24 03:01:09 -04:00
Merge branch 'main' into AB/pharaoh_artifact
This commit is contained in:
151
F1_23/f1_23.py
151
F1_23/f1_23.py
@@ -2,6 +2,7 @@
|
||||
import logging
|
||||
from argparse import ArgumentParser
|
||||
import os.path
|
||||
import re
|
||||
import time
|
||||
import sys
|
||||
import pydirectinput as user
|
||||
@@ -9,9 +10,9 @@ from f1_23_utils import get_resolution
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], ".."))
|
||||
|
||||
from harness_utils.steam import exec_steam_run_command, get_app_install_location
|
||||
from harness_utils.steam import exec_steam_run_command, get_app_install_location, get_build_id
|
||||
from harness_utils.keras_service import KerasService
|
||||
from harness_utils.misc import remove_files
|
||||
from harness_utils.misc import remove_files, press_n_times
|
||||
from harness_utils.process import terminate_processes
|
||||
from harness_utils.output import (
|
||||
format_resolution,
|
||||
@@ -21,6 +22,7 @@ from harness_utils.output import (
|
||||
DEFAULT_LOGGING_FORMAT,
|
||||
DEFAULT_DATE_FORMAT,
|
||||
)
|
||||
from harness_utils.artifacts import ArtifactManager, ArtifactType
|
||||
|
||||
SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
|
||||
LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run")
|
||||
@@ -28,12 +30,31 @@ PROCESS_NAME = "F1_23"
|
||||
STEAM_GAME_ID = 2108330
|
||||
VIDEO_PATH = os.path.join(get_app_install_location(STEAM_GAME_ID), "videos")
|
||||
|
||||
username = os.getlogin()
|
||||
CONFIG_PATH = f"C:\\Users\\{username}\\Documents\\My Games\\F1 23\\hardwaresettings"
|
||||
CONFIG_FILENAME = "hardware_settings_config.xml"
|
||||
CONFIG = f"{CONFIG_PATH}\\{CONFIG_FILENAME}"
|
||||
BENCHMARK_RESULTS_PATH = f"C:\\Users\\{username}\\Documents\\My Games\\F1 23\\benchmark"
|
||||
|
||||
intro_videos = [
|
||||
os.path.join(VIDEO_PATH, "attract.bk2"),
|
||||
os.path.join(VIDEO_PATH, "cm_f1_sting.bk2")
|
||||
]
|
||||
|
||||
|
||||
def find_latest_result_file(base_path):
|
||||
"""Look for files in the benchmark results path that match the pattern in the regular expression"""
|
||||
pattern = r"benchmark_.*\.xml"
|
||||
list_of_files = []
|
||||
|
||||
for filename in os.listdir(base_path):
|
||||
if re.search(pattern, filename, re.IGNORECASE):
|
||||
list_of_files.append(base_path + '\\' +filename)
|
||||
|
||||
latest_file = max(list_of_files, key=os.path.getmtime)
|
||||
|
||||
return latest_file
|
||||
|
||||
def find_settings() -> any:
|
||||
"""Look for and enter settings"""
|
||||
if not kerasService.look_for_word("settings", attempts=5, interval=3):
|
||||
@@ -49,49 +70,11 @@ def find_graphics() -> any:
|
||||
logging.info("Didn't find graphics!")
|
||||
sys.exit(1)
|
||||
user.press("right")
|
||||
time.sleep(0.5)
|
||||
time.sleep(0.2)
|
||||
user.press("enter")
|
||||
time.sleep(1.5)
|
||||
|
||||
|
||||
def find_benchmark() -> any:
|
||||
"""Look for and enter benchmark options"""
|
||||
if not kerasService.look_for_word("benchmark", attempts=5, interval=3):
|
||||
logging.info("Didn't find benchmark!")
|
||||
sys.exit(1)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("enter")
|
||||
time.sleep(1.5)
|
||||
|
||||
|
||||
def find_weather() -> any:
|
||||
"""Navigate to start benchmark"""
|
||||
if not kerasService.look_for_word("weather", attempts=5, interval=3):
|
||||
logging.info("Didn't find weather!")
|
||||
sys.exit(1)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("enter")
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
def navigate_startup():
|
||||
"""press space through the warnings and navigate startup menus"""
|
||||
result = kerasService.wait_for_word("product", timeout=40)
|
||||
@@ -124,8 +107,17 @@ def navigate_startup():
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
def navigate_menu():
|
||||
"""Simulate inputs to navigate to benchmark option."""
|
||||
def run_benchmark():
|
||||
"""Runs the actual benchmark."""
|
||||
remove_files(intro_videos)
|
||||
exec_steam_run_command(STEAM_GAME_ID)
|
||||
am = ArtifactManager(LOG_DIRECTORY)
|
||||
|
||||
setup_start_time = time.time()
|
||||
time.sleep(2)
|
||||
navigate_startup()
|
||||
|
||||
# Navigate menus and take screenshots using the artifact manager
|
||||
result = kerasService.wait_for_word("theatre", interval=3, timeout=60)
|
||||
if not result:
|
||||
logging.info("Didn't land on the main menu!")
|
||||
@@ -133,36 +125,55 @@ def navigate_menu():
|
||||
|
||||
logging.info("Saw the options! we are good to go!")
|
||||
time.sleep(1)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
user.press("down")
|
||||
time.sleep(0.5)
|
||||
|
||||
press_n_times("down", 7, 0.2)
|
||||
user.press("enter")
|
||||
time.sleep(2)
|
||||
|
||||
find_settings()
|
||||
find_graphics()
|
||||
find_benchmark()
|
||||
find_weather() # Run benchmark!
|
||||
|
||||
def run_benchmark():
|
||||
"""Runs the actual benchmark."""
|
||||
remove_files(intro_videos)
|
||||
exec_steam_run_command(STEAM_GAME_ID)
|
||||
setup_start_time = time.time()
|
||||
# Navigate to video settings
|
||||
press_n_times("down", 3, 0.2)
|
||||
user.press("enter")
|
||||
time.sleep(0.2)
|
||||
|
||||
result = kerasService.wait_for_word("vsync", interval=3, timeout=60)
|
||||
if not result:
|
||||
logging.info("Didn't find the keyword 'vsync'. Did the program navigate to the video mode menu correctly?")
|
||||
sys.exit(1)
|
||||
am.take_screenshot("video.png", ArtifactType.CONFIG_IMAGE, "screenshot of video settings menu")
|
||||
user.press("esc")
|
||||
time.sleep(0.2)
|
||||
|
||||
result = kerasService.wait_for_word("steering", interval=3, timeout=60)
|
||||
if not result:
|
||||
logging.info("Didn't find the keyword 'steering'. Did the program exit the video mode menu correctly?")
|
||||
sys.exit(1)
|
||||
|
||||
# Navigate through graphics settings and take screenshots of all settings contained within
|
||||
am.take_screenshot("graphics_1.png", ArtifactType.CONFIG_IMAGE, "first screenshot of graphics settings")
|
||||
press_n_times("down", 30, 0.2)
|
||||
|
||||
result = kerasService.wait_for_word("chromatic", interval=3, timeout=60)
|
||||
if not result:
|
||||
logging.info("Didn't find the keyword 'chromatic'. Did we navigate the menu correctly?")
|
||||
sys.exit(1)
|
||||
|
||||
am.take_screenshot("graphics_2.png", ArtifactType.CONFIG_IMAGE, "second screenshot of graphics settings")
|
||||
press_n_times("up", 29, 0.2)
|
||||
user.press("enter")
|
||||
time.sleep(0.2)
|
||||
|
||||
# Navigate benchmark menu
|
||||
if not kerasService.look_for_word("weather", attempts=5, interval=3):
|
||||
logging.info("Didn't find weather!")
|
||||
sys.exit(1)
|
||||
|
||||
am.take_screenshot("benchmark.png", ArtifactType.CONFIG_IMAGE, "screenshot of benchmark settings")
|
||||
|
||||
press_n_times("down", 6, 0.2)
|
||||
user.press("enter")
|
||||
time.sleep(2)
|
||||
navigate_startup()
|
||||
navigate_menu()
|
||||
|
||||
elapsed_setup_time = round(time.time() - setup_start_time, 2)
|
||||
logging.info("Setup took %f seconds", elapsed_setup_time)
|
||||
@@ -193,8 +204,11 @@ def run_benchmark():
|
||||
logging.info("Results screen was not found!" +
|
||||
"Did harness not wait long enough? Or test was too long?")
|
||||
sys.exit(1)
|
||||
|
||||
logging.info("Results screen was found! Finishing benchmark.")
|
||||
results_file = find_latest_result_file(BENCHMARK_RESULTS_PATH)
|
||||
am.take_screenshot("result.png", ArtifactType.RESULTS_IMAGE, "screenshot of results")
|
||||
am.copy_file(CONFIG, ArtifactType.CONFIG_TEXT, "config file")
|
||||
am.copy_file(results_file, ArtifactType.RESULTS_TEXT, "benchmark results xml file")
|
||||
|
||||
if test_end_time is None:
|
||||
logging.info("Loading screen end time not found. Using results screen fallback time.")
|
||||
@@ -240,6 +254,7 @@ try:
|
||||
"resolution": format_resolution(width, height),
|
||||
"start_time": seconds_to_milliseconds(start_time),
|
||||
"end_time": seconds_to_milliseconds(end_time),
|
||||
"version": get_build_id(STEAM_GAME_ID)
|
||||
}
|
||||
|
||||
write_report_json(LOG_DIRECTORY, "report.json", report)
|
||||
|
||||
@@ -3,9 +3,17 @@ import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
import time
|
||||
import pydirectinput as user
|
||||
|
||||
import requests
|
||||
|
||||
def press_n_times(key: str, n: int, pause: float):
|
||||
"""A helper function press the same button multiple times"""
|
||||
for _ in range(n):
|
||||
user.press(key)
|
||||
time.sleep(pause)
|
||||
|
||||
def remove_files(paths: list[str]) -> None:
|
||||
"""Removes files specified by provided list of file paths.
|
||||
Does nothing for a path that does not exist.
|
||||
|
||||
Reference in New Issue
Block a user