Audit Harness utils - second pass (#38)

* add changes to steam utils to harnesses

* replace steam path

* cleanup duplicated functions for removing video files

* Add util func to remove files
This commit is contained in:
Derek Hirotsu
2023-09-21 09:25:31 -07:00
committed by GitHub
parent e02728a281
commit 0c6ee870de
20 changed files with 111 additions and 270 deletions

View File

@@ -3,17 +3,15 @@ import logging
import sys
import os.path
import time
from subprocess import Popen
import pydirectinput as user
from f1_22_utils import get_args
from f1_22_utils import get_resolution, remove_intro_videos
from f1_22_utils import get_resolution
sys.path.insert(1, os.path.join(sys.path[0], ".."))
#pylint: disable=wrong-import-position
from harness_utils.keras_service import KerasService
from harness_utils.steam import DEFAULT_EXECUTABLE_PATH as STEAM_PATH
from harness_utils.steam import exec_steam_run_command, get_steamapps_common_path
from harness_utils.output import (
format_resolution,
seconds_to_milliseconds,
@@ -22,14 +20,14 @@ from harness_utils.output import (
DEFAULT_LOGGING_FORMAT,
DEFAULT_DATE_FORMAT,
)
from harness_utils.misc import remove_files
from harness_utils.process import terminate_processes
#pylint: enable=wrong-import-position
SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run")
STEAM_GAME_ID = 1692250
VIDEO_PATH = r"C:\Program Files (x86)\Steam\steamapps\common\F1 22\videos"
VIDEO_PATH = os.path.join(get_steamapps_common_path(), "videos")
skippable = [
os.path.join(VIDEO_PATH, "attract.bk2"),
@@ -46,14 +44,6 @@ def wait_for_word(word: str, attempts: int = 5, delay_seconds: int = 1) -> bool:
time.sleep(delay_seconds)
return False
def start_game():
"""Starts the game via steam command."""
steam_run_arg = "steam://rungameid/" + str(STEAM_GAME_ID)
logging.info("%s %s", STEAM_PATH, steam_run_arg)
return Popen([STEAM_PATH, steam_run_arg])
def navigate_overlay():
"""Simulate inputs to navigate ingame overlay."""
# if steam ingame overlay is disabled it will be a an okay to press
@@ -127,8 +117,8 @@ def navigate_menu():
def run_benchmark():
"""Runs the actual benchmark."""
setup_start_time = time.time()
remove_intro_videos(skippable)
start_game()
remove_files(skippable)
exec_steam_run_command(STEAM_GAME_ID)
time.sleep(20)
@@ -219,7 +209,6 @@ try:
write_report_json(LOG_DIRECTORY, "report.json", report)
#pylint: disable=broad-exception-caught
except Exception as e:
logging.error("Something went wrong running the benchmark!")
logging.exception(e)

View File

@@ -40,13 +40,3 @@ def get_args() -> any:
required=True,
)
return parser.parse_args()
def remove_intro_videos(file_paths: list[str]) -> None:
"""Remove video files from paths to speed up game startup."""
for video in file_paths:
try:
os.remove(video)
except FileNotFoundError:
# If file not found, it has likely already been deleted before.
pass

View File

@@ -3,17 +3,16 @@ import logging
from argparse import ArgumentParser
import os.path
import time
from subprocess import Popen
import sys
import pydirectinput as user
from f1_23_utils import get_resolution, remove_intro_videos, skippable
from f1_23_utils import get_resolution
sys.path.insert(1, os.path.join(sys.path[0], ".."))
# pylint: disable=wrong-import-position
from harness_utils.steam import DEFAULT_EXECUTABLE_PATH as STEAM_PATH
from harness_utils.steam import exec_steam_run_command, get_app_install_location
from harness_utils.keras_service import KerasService
from harness_utils.misc import remove_files
from harness_utils.process import terminate_processes
from harness_utils.output import (
format_resolution,
@@ -23,13 +22,18 @@ from harness_utils.output import (
DEFAULT_LOGGING_FORMAT,
DEFAULT_DATE_FORMAT,
)
# pylint: enable=wrong-import-position
SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run")
STEAM_GAME_ID = 2108330
PROCESS_NAME = "F1_23"
STEAM_GAME_ID = 2108330
VIDEO_PATH = os.path.join(get_app_install_location(STEAM_GAME_ID), "videos")
skippable = [
os.path.join(VIDEO_PATH, "attract.bk2"),
os.path.join(VIDEO_PATH, "cm_f1_sting.bk2")
]
def is_word_on_screen(word: str, attempts: int = 5, delay_seconds: int = 1) -> bool:
@@ -42,13 +46,6 @@ def is_word_on_screen(word: str, attempts: int = 5, delay_seconds: int = 1) -> b
return False
def start_game():
"""Starts the game via steam command."""
steam_run_arg = "steam://rungameid/" + str(STEAM_GAME_ID)
logging.info("%s %s", STEAM_PATH, steam_run_arg)
return Popen([STEAM_PATH, steam_run_arg])
def official() -> any:
"""Look for product"""
return is_word_on_screen(word="product", attempts=20, delay_seconds=0.5)
@@ -216,8 +213,8 @@ def navigate_menu():
def run_benchmark():
"""Runs the actual benchmark."""
remove_intro_videos(skippable)
start_game()
remove_files(skippable)
exec_steam_run_command(STEAM_GAME_ID)
setup_start_time = time.time()
time.sleep(2)
navigate_startup()

View File

@@ -1,8 +1,7 @@
"""Utility functions supporting F1 23 test script."""
import os
import re
import winreg
import logging
def get_resolution() -> tuple[int]:
"""Gets resolution width and height from local xml file created by game."""
@@ -23,35 +22,3 @@ def get_resolution() -> tuple[int]:
if width_match is not None:
width = width_match.group(1)
return (width, height)
def remove_intro_videos(file_paths: list[str]) -> None:
"""Remove video files from paths to speed up game startup."""
for video in file_paths:
try:
os.remove(video)
logging.info("Removing video %s", video)
except FileNotFoundError:
# If file not found, it has likely already been deleted before.
logging.info("Video already removed %s", video)
def f1_23_directory() -> any:
"""Gets the directory from the Windows Registry"""
reg_path = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 2108330'
try:
registry_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, reg_path, 0,
winreg.KEY_READ)
value, _ = winreg.QueryValueEx(registry_key, "InstallLocation")
winreg.CloseKey(registry_key)
return value
except WindowsError:
return None
video_path = os.path.join(f1_23_directory(), "videos")
skippable = [
os.path.join(video_path, "attract.bk2"),
os.path.join(video_path, "cm_f1_sting.bk2")
]

View File

@@ -3,14 +3,14 @@ from argparse import ArgumentParser
import logging
import os
import time
from subprocess import Popen
import sys
import pydirectinput as user
from utils import read_resolution, remove_intros, skippable
from utils import read_resolution
sys.path.insert(1, os.path.join(sys.path[0], '..'))
#pylint: disable=wrong-import-position
from harness_utils.steam import get_run_game_id_command, DEFAULT_EXECUTABLE_PATH as STEAM_PATH
from harness_utils.steam import exec_steam_run_command, get_app_install_location
from harness_utils.misc import remove_files
from harness_utils.process import terminate_processes
from harness_utils.output import (
format_resolution,
@@ -23,22 +23,26 @@ from harness_utils.output import (
from harness_utils.keras_service import KerasService
#pylint: enable=wrong-import-position
STEAM_GAME_ID = 668580
SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run")
APPDATA = os.getenv("LOCALAPPDATA")
CONFIG_LOCATION = f"{APPDATA}\\AtomicHeart\\Saved\\Config\\WindowsNoEditor"
CONFIG_FILENAME = "GameUserSettings.ini"
PROCESS_NAME = "AtomicHeart"
STEAM_GAME_ID = 668580
VIDEO_PATH = os.path.join(
get_app_install_location(STEAM_GAME_ID), "AtomicHeart", "Content", "Movies")
skippable = [
os.path.join(VIDEO_PATH, "Launch_4k_60FPS_PS5.mp4"),
os.path.join(VIDEO_PATH, "Launch_4k_60FPS_XboxXS.mp4"),
os.path.join(VIDEO_PATH, "Launch_FHD_30FPS_PS4.mp4"),
os.path.join(VIDEO_PATH, "Launch_FHD_30FPS_XboxOne.mp4"),
os.path.join(VIDEO_PATH, "Launch_FHD_60FPS_PC_Steam.mp4")
]
user.FAILSAFE = False
def start_game():
"""Starts the game via steam command."""
steam_run_arg = get_run_game_id_command(STEAM_GAME_ID)
logging.info("%s %s", STEAM_PATH, steam_run_arg)
return Popen([STEAM_PATH, steam_run_arg])
def is_word_on_screen(word: str, attempts: int = 5, delay_seconds: int = 1) -> bool:
"""Looks for given word a specified number of times"""
@@ -77,8 +81,8 @@ def await_wicked() -> any:
def run_benchmark():
"""Starts the benchmark"""
remove_intros(skippable)
start_game()
remove_files(skippable)
exec_steam_run_command(STEAM_GAME_ID)
setup_start_time = time.time()
time.sleep(10)

View File

@@ -1,52 +1,12 @@
"""Atomic Heart utility functions"""
import os
import sys
import re
import winreg
import logging
import pydirectinput as user
sys.path.insert(1, os.path.join(sys.path[0], '..'))
APPDATA = os.getenv("LOCALAPPDATA")
CONFIG_LOCATION = f"{APPDATA}\\AtomicHeart\\Saved\\Config\\WindowsNoEditor"
CONFIG_FILENAME = "GameUserSettings.ini"
PROCESS_NAME = "AtomicHeart"
def get_install_location() -> any:
"""Gets install location based on registry"""
reg_path = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 668580'
try:
registry_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, reg_path, 0,
winreg.KEY_READ)
value, _ = winreg.QueryValueEx(registry_key, "InstallLocation")
winreg.CloseKey(registry_key)
return value
except WindowsError:
return None
video_path = os.path.join(get_install_location(), "AtomicHeart\\Content\\Movies")
skippable = [
os.path.join(video_path, "Launch_4k_60FPS_PS5.mp4"),
os.path.join(video_path, "Launch_4k_60FPS_XboxXS.mp4"),
os.path.join(video_path, "Launch_FHD_30FPS_PS4.mp4"),
os.path.join(video_path, "Launch_FHD_30FPS_XboxOne.mp4"),
os.path.join(video_path, "Launch_FHD_60FPS_PC_Steam.mp4")
]
user.FAILSAFE = False
def remove_intros(file_paths: list[str]) -> None:
"""Removes files from given paths"""
for video in file_paths:
try:
os.remove(video)
logging.info("Removing video %s", video)
except FileNotFoundError:
logging.info("Video already removed %s", video)
# If file not found, it has likely already been deleted before.
def read_resolution():
"""Gets resolution width and height values from local file"""

View File

@@ -2,7 +2,6 @@ import logging
import os
import time
from argparse import ArgumentParser
from subprocess import Popen
import pyautogui as gui
import pydirectinput as user
import sys
@@ -13,7 +12,7 @@ sys.path.insert(1, os.path.join(sys.path[0], '..'))
from harness_utils.output import *
from harness_utils.process import terminate_processes
from harness_utils.steam import get_run_game_id_command, DEFAULT_EXECUTABLE_PATH as STEAM_PATH
from harness_utils.steam import exec_steam_run_command, get_steam_folder_path
"""
Fortunately with Counter Strike we have access to the developer console which lets us
@@ -26,12 +25,6 @@ SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run")
def start_game():
steam_run_arg = get_run_game_id_command(STEAM_GAME_ID)
logging.info(STEAM_PATH + " " + steam_run_arg)
return Popen([STEAM_PATH, steam_run_arg])
def console_command(command):
for char in command:
gui.press(char)
@@ -40,7 +33,7 @@ def console_command(command):
def run_benchmark():
t1 = time.time()
start_game()
exec_steam_run_command(STEAM_GAME_ID)
time.sleep(40) # wait for game to load into main menu
# open developer console in main menu
@@ -78,7 +71,7 @@ logging.getLogger('').addHandler(console)
parser = ArgumentParser()
args = parser.parse_args() # This probably isn't working because there isn't steamid arg in manifest
config_path = f"{STEAM_PATH}\\userdata\\{args.steamid}\\{STEAM_GAME_ID}\\local\\cfg\\video.txt"
config_path = f"{get_steam_folder_path()}\\userdata\\{args.steamid}\\{STEAM_GAME_ID}\\local\\cfg\\video.txt"
try:
start_time, end_time = run_benchmark()

View File

@@ -1,7 +1,6 @@
"""Cyberpunk 2077 test script"""
import time
import logging
from subprocess import Popen
import sys
import os
from cyberpunk_utils import copy_no_intro_mod, get_args, read_current_resolution
@@ -15,7 +14,7 @@ from harness_utils.keras_service import KerasService
from harness_utils.output import (
setup_log_directory, write_report_json, DEFAULT_LOGGING_FORMAT, DEFAULT_DATE_FORMAT)
from harness_utils.process import terminate_processes
from harness_utils.steam import DEFAULT_EXECUTABLE_PATH as STEAM_PATH
from harness_utils.steam import exec_steam_game
#pylint: enable=wrong-import-position
STEAM_GAME_ID = 1091500
@@ -26,10 +25,7 @@ PROCESS_NAME = "cyberpunk2077.exe"
def start_game():
"""Launch the game with no launcher or start screen"""
cmd_array = [STEAM_PATH, "-applaunch",
str(STEAM_GAME_ID), "--launcher-skip", "-skipStartScreen"]
logging.info(" ".join(cmd_array))
return Popen(cmd_array)
return exec_steam_game(STEAM_GAME_ID, game_params=["--launcher-skip", "-skipStartScreen"])
def is_word_present(word: str, attempts: int = 5, delay_seconds: int = 1) -> bool:
@@ -90,6 +86,7 @@ def run_benchmark():
# Start game via Steam and enter fullscreen mode
setup_start_time = time.time()
start_game()
time.sleep(10)
settings_menu_screen = await_settings_menu()

View File

@@ -10,7 +10,7 @@ sys.path.insert(1, os.path.join(sys.path[0], '..'))
from harness_utils.output import *
from harness_utils.process import terminate_processes
from harness_utils.rtss import start_rtss_process, copy_rtss_profile
from harness_utils.steam import get_run_game_id_command, DEFAULT_EXECUTABLE_PATH as steam_path
from harness_utils.steam import exec_steam_run_command
STEAM_GAME_ID = 1551360
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
@@ -27,18 +27,12 @@ def start_rtss():
return start_rtss_process()
def start_game():
steam_run_arg = get_run_game_id_command(STEAM_GAME_ID)
logging.info(steam_path + " " + steam_run_arg)
return Popen([steam_path, steam_run_arg])
def run_benchmark():
start_rtss()
# Give RTSS time to start
time.sleep(10)
start_game()
exec_steam_run_command(STEAM_GAME_ID)
t1 = time.time()
# Wait for menu to load

View File

@@ -3,7 +3,6 @@ import os
import logging
import time
import sys
from subprocess import Popen
import pyautogui as gui
from hitman_3_utils import get_resolution, wait_for_image
@@ -19,7 +18,7 @@ from harness_utils.output import (
DEFAULT_DATE_FORMAT,
)
from harness_utils.process import terminate_processes
from harness_utils.steam import get_run_game_id_command, DEFAULT_EXECUTABLE_PATH as STEAM_PATH
from harness_utils.steam import exec_steam_run_command
#pylint: enable=wrong-import-position
STEAM_GAME_ID = 1659040
@@ -29,17 +28,10 @@ STEAM_EXECUTABLE = "steam.exe"
PROCESS_NAMES = ['HITMAN3.exe', 'Launcher.exe']
def start_game():
"""Starts the game process"""
steam_run_arg = get_run_game_id_command(STEAM_GAME_ID)
logging.info("%s %s", STEAM_PATH, steam_run_arg)
return Popen([STEAM_PATH, steam_run_arg])
def run_benchmark():
"""Starts the benchmark"""
setup_start_time = time.time()
start_game()
exec_steam_run_command(STEAM_GAME_ID)
options_image = os.path.dirname(os.path.realpath(__file__)) + "/images/hitman3_options.png"
options_loc = wait_for_image(options_image, 0.7, 1, 15)

View File

@@ -1,5 +1,4 @@
"""Shadow of the Tomb Raider test script"""
from subprocess import Popen
import os
import logging
import time
@@ -19,7 +18,7 @@ from harness_utils.output import (
DEFAULT_DATE_FORMAT,
)
from harness_utils.process import terminate_processes
from harness_utils.steam import get_run_game_id_command, DEFAULT_EXECUTABLE_PATH as steam_path
from harness_utils.steam import exec_steam_run_command
#pylint: enable=wrong-import-position
STEAM_GAME_ID = 750920
@@ -27,13 +26,6 @@ SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run")
def start_game():
"""Starts the game via steam command."""
steam_run_arg = get_run_game_id_command(STEAM_GAME_ID)
logging.info("%s %s", steam_path, steam_run_arg)
return Popen([steam_path, steam_run_arg])
def click_options(options):
"""
If the game is freshly installed the main menu has less options thus the options button
@@ -53,7 +45,7 @@ def click_options(options):
def run_benchmark():
"""Start game via Steam and enter fullscreen mode"""
setup_start_time = time.time()
start_game()
exec_steam_run_command(STEAM_GAME_ID)
try:
deprecated.cv2_utils.wait_and_click('load_menu_play', "play button", timeout=30)

View File

@@ -18,7 +18,7 @@ from harness_utils.output import (
DEFAULT_DATE_FORMAT,
)
from harness_utils.process import terminate_processes
from harness_utils.steam import get_run_game_id_command, DEFAULT_EXECUTABLE_PATH as steam_path
from harness_utils.steam import exec_steam_run_command
#pylint: enable=wrong-import-position
SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
@@ -37,9 +37,7 @@ def start_game() -> any:
logging.info("Could not find executable, trying a steam launch")
if game_process is None:
steam_run_arg = get_run_game_id_command(STEAM_GAME_ID)
logging.info("%s %s", steam_path, steam_run_arg)
game_process = Popen([steam_path, steam_run_arg])
game_process = exec_steam_run_command(STEAM_GAME_ID)
def run_benchmark():

View File

@@ -15,6 +15,12 @@ Contains class for instancing connection to a Keras Service and provides access
Functions related to logging and formatting output from test harnesses.
## Misc
`misc.py`
Misc utility functions
## Process
`process.py`

14
harness_utils/misc.py Normal file
View File

@@ -0,0 +1,14 @@
"""Misc utility functions"""
import logging
import os
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.
"""
for path in paths:
try:
os.remove(path)
logging.info("Removed file: %s", path)
except FileNotFoundError:
pass

View File

@@ -1,21 +1,9 @@
"""Utility functions related to using Steam for running games."""
import os
import logging
import winreg
from subprocess import Popen
from pathlib import Path
# TODO: Deprecate these. Replace DEFAULT_EXECUTABLE_PATH with the "exec" commands below
# Used in basically all the harnesses
DEFAULT_BASE_PATH = os.path.join(os.environ["ProgramFiles(x86)"], "Steam")
DEFAULT_EXECUTABLE_NAME = "Steam.exe"
DEFAULT_EXECUTABLE_PATH = os.path.join(
DEFAULT_BASE_PATH, DEFAULT_EXECUTABLE_NAME)
# TODO: Deprecate this. Currently used in Returnal harness.
DEFAULT_STEAMAPPS_COMMON_PATH = os.path.join(
DEFAULT_BASE_PATH, "steamapps", "common")
def get_run_game_id_command(game_id: int) -> str:
"""Returns the steam run game id command with the given game ID"""

View File

@@ -2,7 +2,6 @@
import logging
import os
import time
from subprocess import Popen
import sys
import pydirectinput as user
@@ -20,7 +19,7 @@ from harness_utils.output import (
DEFAULT_DATE_FORMAT,
)
from harness_utils.process import terminate_processes
from harness_utils.steam import get_run_game_id_command, DEFAULT_EXECUTABLE_PATH as STEAM_PATH
from harness_utils.steam import exec_steam_run_command
#pylint: enable=wrong-import-position
STEAM_GAME_ID = 1174180
@@ -28,24 +27,12 @@ PROCESS_NAME = "RDR2"
SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run")
config_path = os.path.join(
os.environ["HOMEPATH"], "Documents" ,"Rockstar Games",
"Red Dead Redemption 2", "Settings", "system.xml"
)
def start_game():
"""Starts the game via steam command"""
steam_run_arg = get_run_game_id_command(STEAM_GAME_ID)
logging.info("%s %s", STEAM_PATH, steam_run_arg)
return Popen([STEAM_PATH, steam_run_arg])
def run_benchmark():
"""Starts the benchmark"""
# Wait for game to load to main menu
setup_start_time = time.time()
start_game()
exec_steam_run_command(STEAM_GAME_ID)
time.sleep(65)
# Press Z to enter settings
@@ -98,7 +85,7 @@ logging.getLogger('').addHandler(console)
try:
start_time, end_time = run_benchmark()
width, height = get_resolution(config_path)
width, height = get_resolution()
report = {
"resolution": format_resolution(width, height),
"start_time": seconds_to_milliseconds(start_time),

View File

@@ -1,12 +1,11 @@
"""Returnal test script"""
import os
import logging
from subprocess import Popen
import sys
import time
import pydirectinput as user
from returnal_utils import get_resolution, remove_intro_videos, get_args
from returnal_utils import get_resolution, get_args
sys.path.insert(1, os.path.join(sys.path[0], '..'))
@@ -21,11 +20,11 @@ from harness_utils.output import (
DEFAULT_LOGGING_FORMAT,
DEFAULT_DATE_FORMAT,
)
from harness_utils.misc import remove_files
from harness_utils.process import terminate_processes
from harness_utils.steam import (
get_run_game_id_command,
DEFAULT_EXECUTABLE_PATH as STEAM_PATH,
DEFAULT_STEAMAPPS_COMMON_PATH
exec_steam_run_command,
get_steamapps_common_path,
)
# pylint: enable=wrong-import-position
@@ -38,8 +37,7 @@ LOCAL_USER_SETTINGS = os.path.join(
os.getenv('LOCALAPPDATA'), "Returnal", "Steam",
"Saved", "Config", "WindowsNoEditor", "GameUserSettings.ini"
)
VIDEO_PATH = os.path.join(
DEFAULT_STEAMAPPS_COMMON_PATH, "Returnal", "Returnal", "Content", "Movies")
VIDEO_PATH = os.path.join(get_steamapps_common_path(), "Returnal", "Returnal", "Content", "Movies")
user.FAILSAFE = False
@@ -52,14 +50,6 @@ skippable_videos = [
os.path.join(VIDEO_PATH, "Logos_Short_PC_UW32.mp4"),
]
def start_game() -> None:
"""Start game via steam command"""
steam_run_arg = get_run_game_id_command(STEAM_GAME_ID)
logging.info("%s %s", STEAM_PATH, steam_run_arg)
return Popen([STEAM_PATH, steam_run_arg])
def check_vram_alert(attempts: int) -> bool:
"""Look for VRAM alert in menu"""
logging.info("Checking for VRAM alert prompt")
@@ -120,10 +110,10 @@ def await_benchmark_menu(attempts: int) -> bool:
def run_benchmark() -> tuple[float]:
"""Run the benchmark"""
logging.info("Removing intro videos")
remove_intro_videos(skippable_videos)
remove_files(skippable_videos)
logging.info("Starting game")
start_game()
exec_steam_run_command(STEAM_GAME_ID)
setup_start_time = time.time()
time.sleep(10)

View File

@@ -2,7 +2,6 @@
import logging
import os
import time
from subprocess import Popen
import sys
import pydirectinput as user
import pyautogui as gui
@@ -22,9 +21,8 @@ from harness_utils.output import (
)
from harness_utils.process import terminate_processes
from harness_utils.steam import (
get_run_game_id_command,
get_registry_active_user,
DEFAULT_EXECUTABLE_PATH as STEAM_PATH
get_registry_active_user,
exec_steam_run_command,
)
#pylint: enable=wrong-import-position
@@ -36,13 +34,6 @@ PROCESS_NAME = "tlou"
user.FAILSAFE = False
def start_game():
"""Start game process via Steam"""
steam_run_arg = get_run_game_id_command(STEAM_GAME_ID)
logging.info("%s %s", STEAM_PATH, steam_run_arg)
return Popen([STEAM_PATH, steam_run_arg])
def await_start_screen(attempts: int) -> bool:
"""Wait for the start menu"""
for _ in range(attempts):
@@ -106,7 +97,7 @@ def await_fromy(attempts: int) -> bool:
def run_benchmark():
"""Starts the benchmark"""
start_game()
exec_steam_run_command(STEAM_GAME_ID)
setup_start_time = time.time()
time.sleep(10)

View File

@@ -4,10 +4,9 @@ import logging
import os
import time
import sys
import re
import winreg
import pyautogui as gui
import pydirectinput as user
from twwh3_utils import read_current_resolution
sys.path.insert(1, os.path.join(sys.path[0], '..'))
# pylint: disable=wrong-import-position
@@ -20,53 +19,21 @@ from harness_utils.output import (
DEFAULT_LOGGING_FORMAT,
DEFAULT_DATE_FORMAT
)
from harness_utils.steam import get_app_install_location
from harness_utils.keras_service import KerasService
# pylint: enable=wrong-import-position
SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
LOG_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, "run")
APPDATA = os.getenv("APPDATA")
CONFIG_LOCATION = f"{APPDATA}\\The Creative Assembly\\Warhammer3\\scripts"
CONFIG_FILENAME = "preferences.script.txt"
PROCESS_NAME = "Warhammer3.exe"
STEAM_GAME_ID = 1142710
user.FAILSAFE = False
def get_directory() -> any:
"""Gets directory from registry key"""
reg_path = r'Software\Microsoft\WIndows\CurrentVersion\Uninstall\Steam App 1142710'
try:
registry_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, reg_path, 0,
winreg.KEY_READ)
value, _ = winreg.QueryValueEx(registry_key, "InstallLocation")
winreg.CloseKey(registry_key)
return value
except WindowsError:
return None
def read_current_resolution():
"""Reads resolutions settings from local game file"""
height_pattern = re.compile(r"y_res (\d+);")
width_pattern = re.compile(r"x_res (\d+);")
cfg = f"{CONFIG_LOCATION}\\{CONFIG_FILENAME}"
height_value = 0
width_value = 0
with open(cfg, encoding="utf-8") as file:
lines = file.readlines()
for line in lines:
height_match = height_pattern.search(line)
width_match = width_pattern.search(line)
if height_match is not None:
height_value = height_match.group(1)
if width_match is not None:
width_value = width_match.group(1)
return (height_value, width_value)
def start_game():
"""Starts the game process"""
cmd_string = f"start /D \"{get_directory()}\" {PROCESS_NAME}"
cmd_string = f"start /D \"{get_app_install_location(STEAM_GAME_ID)}\" {PROCESS_NAME}"
logging.info(cmd_string)
return os.system(cmd_string)

View File

@@ -0,0 +1,25 @@
"""Utility functions for Total War: Warhammer III test script"""
import os
import re
APPDATA = os.getenv("APPDATA")
CONFIG_LOCATION = f"{APPDATA}\\The Creative Assembly\\Warhammer3\\scripts"
CONFIG_FILENAME = "preferences.script.txt"
def read_current_resolution():
"""Reads resolutions settings from local game file"""
height_pattern = re.compile(r"y_res (\d+);")
width_pattern = re.compile(r"x_res (\d+);")
cfg = f"{CONFIG_LOCATION}\\{CONFIG_FILENAME}"
height_value = 0
width_value = 0
with open(cfg, encoding="utf-8") as file:
lines = file.readlines()
for line in lines:
height_match = height_pattern.search(line)
width_match = width_pattern.search(line)
if height_match is not None:
height_value = height_match.group(1)
if width_match is not None:
width_value = width_match.group(1)
return (height_value, width_value)