Move more tests to libretro.py

This commit is contained in:
Jesse Talavera 2024-03-21 15:01:51 -04:00
parent 51774a16da
commit 7293141d2f
6 changed files with 154 additions and 106 deletions

View File

@ -1,118 +1,58 @@
### Preventing Unneeded Loads
add_retroarch_test(
NAME "Core doesn't try to load native BIOS if using FreeBIOS (NDS)"
CONTENT "${NDS_ROM}"
MAX_FRAMES 6
CORE_OPTION "melonds_console_mode=ds"
CORE_OPTION "melonds_sysfile_mode=builtin"
PASS_REGULAR_EXPRESSION "Not loading native ARM BIOS files"
add_python_test(
NAME "Core doesn't try to load native BIOS if using FreeBIOS (NDS)"
TEST_MODULE firmware.native_bios_not_loaded_with_freebios
CONTENT "${NDS_ROM}"
CORE_OPTION "melonds_console_mode=ds"
CORE_OPTION "melonds_sysfile_mode=builtin"
)
### Ensuring firmware is not overwritten
# See https://github.com/JesseTG/melonds-ds/issues/59
add_retroarch_test(
NAME "Native firmware is not overwritten by contents of wfcsettings.bin"
MAX_FRAMES 6
CORE_OPTION "melonds_console_mode=ds"
CORE_OPTION "melonds_firmware_nds_path=melonDS DS/${NDS_FIRMWARE_NAME}"
CORE_OPTION "melonds_sysfile_mode=native"
CORE_OPTION "melonds_boot_mode=native"
ARM7_BIOS
ARM9_BIOS
NDS_FIRMWARE
REQUIRE_FILE_SIZE_UNCHANGED "system/melonDS DS/${NDS_FIRMWARE_NAME}"
add_python_test(
NAME "Native firmware is not overwritten by contents of wfcsettings.bin"
TEST_MODULE firmware.nds_firmware_not_overwritten
CORE_OPTION "melonds_console_mode=ds"
CORE_OPTION "melonds_firmware_nds_path=melonDS DS/${NDS_FIRMWARE_NAME}"
CORE_OPTION "melonds_sysfile_mode=native"
CORE_OPTION "melonds_boot_mode=native"
NDS_SYSFILES
)
add_retroarch_test(
NAME "Core saves wi-fi settings to wfcsettings.bin when using built-in firmware"
CONTENT "${NDS_ROM}"
MAX_FRAMES 6
CORE_OPTION "melonds_console_mode=ds"
CORE_OPTION "melonds_firmware_nds_path=/builtin"
ARM7_BIOS
ARM9_BIOS
REQUIRE_FILE_CREATED "system/melonDS DS/wfcsettings.bin"
add_python_test(
NAME "Core saves wi-fi settings to wfcsettings.bin when using built-in firmware"
TEST_MODULE firmware.core_saves_wfcsettings
CONTENT "${NDS_ROM}"
CORE_OPTION "melonds_console_mode=ds"
CORE_OPTION "melonds_firmware_nds_path=/builtin"
CORE_OPTION "melonds_sysfile_mode=builtin"
)
### Overwriting Firmware
add_emutest_test(
NAME "NDS firmware is not overwritten when switching from DS to DSi mode"
CONTENT "${NDS_ROM}"
TEST_SCRIPT "firmware-not-overwritten.lua"
ARM7_BIOS
ARM9_BIOS
ARM7_DSI_BIOS
ARM9_DSI_BIOS
NDS_FIRMWARE
DSI_FIRMWARE
DSI_NAND
CORE_OPTION melonds_firmware_dsi_path="melonDS DS/${DSI_FIRMWARE_NAME}"
CORE_OPTION melonds_firmware_nds_path="melonDS DS/${NDS_FIRMWARE_NAME}"
CORE_OPTION melonds_dsi_nand_path="melonDS DS/${DSI_NAND_NAME}"
CORE_OPTION melonds_console_mode="ds"
CORE_OPTION melonds_boot_directly="false"
CORE_OPTION melonds_sysfile_mode="native"
CORE_OPTION melonds_show_cursor="disabled"
add_python_test(
NAME "Firmware images aren't overwritten when switching from DS to DSi mode"
TEST_MODULE firmware.firmware_not_overwritten_when_switching_console_mode
CONTENT "${NDS_ROM}"
NDS_SYSFILES
DSI_SYSFILES
CORE_OPTION "melonds_firmware_dsi_path=melonDS DS/${DSI_FIRMWARE_NAME}"
CORE_OPTION "melonds_firmware_nds_path=melonDS DS/${NDS_FIRMWARE_NAME}"
CORE_OPTION "melonds_dsi_nand_path=melonDS DS/${DSI_NAND_NAME}"
CORE_OPTION "melonds_console_mode=ds"
CORE_OPTION "melonds_boot_directly=false"
CORE_OPTION "melonds_sysfile_mode=native"
)
add_emutest_test(
NAME "NDS firmware is not overwritten when switching from DSi to NDS mode"
CONTENT "${NDS_ROM}"
TEST_SCRIPT "firmware-not-overwritten.lua"
ARM7_BIOS
ARM9_BIOS
ARM7_DSI_BIOS
ARM9_DSI_BIOS
NDS_FIRMWARE
DSI_FIRMWARE
DSI_NAND
CORE_OPTION melonds_firmware_dsi_path="melonDS DS/${DSI_FIRMWARE_NAME}"
CORE_OPTION melonds_firmware_nds_path="melonDS DS/${NDS_FIRMWARE_NAME}"
CORE_OPTION melonds_dsi_nand_path="melonDS DS/${DSI_NAND_NAME}"
CORE_OPTION melonds_console_mode="dsi"
CORE_OPTION melonds_boot_directly="false"
CORE_OPTION melonds_sysfile_mode="native"
CORE_OPTION melonds_show_cursor="disabled"
add_python_test(
NAME "Firmware images aren't overwritten when switching from DSi to DS mode"
TEST_MODULE firmware.firmware_not_overwritten_when_switching_console_mode
CONTENT "${NDS_ROM}"
NDS_SYSFILES
DSI_SYSFILES
CORE_OPTION "melonds_firmware_dsi_path=melonDS DS/${DSI_FIRMWARE_NAME}"
CORE_OPTION "melonds_firmware_nds_path=melonDS DS/${NDS_FIRMWARE_NAME}"
CORE_OPTION "melonds_dsi_nand_path=melonDS DS/${DSI_NAND_NAME}"
CORE_OPTION "melonds_console_mode=dsi"
CORE_OPTION "melonds_boot_directly=false"
CORE_OPTION "melonds_sysfile_mode=native"
)
add_emutest_test(
NAME "DSi firmware is not overwritten when switching from NDS to DSi mode"
CONTENT "${NDS_ROM}"
TEST_SCRIPT "firmware-not-overwritten.lua"
ARM7_BIOS
ARM9_BIOS
ARM7_DSI_BIOS
ARM9_DSI_BIOS
NDS_FIRMWARE
DSI_FIRMWARE
DSI_NAND
CORE_OPTION melonds_firmware_dsi_path="melonDS DS/${DSI_FIRMWARE_NAME}"
CORE_OPTION melonds_firmware_nds_path="melonDS DS/${NDS_FIRMWARE_NAME}"
CORE_OPTION melonds_dsi_nand_path="melonDS DS/${DSI_NAND_NAME}"
CORE_OPTION melonds_console_mode="dsi"
CORE_OPTION melonds_boot_directly="false"
CORE_OPTION melonds_sysfile_mode="native"
CORE_OPTION melonds_show_cursor="disabled"
)
add_emutest_test(
NAME "DSi firmware is not overwritten when switching from DSi to NDS mode"
CONTENT "${NDS_ROM}"
TEST_SCRIPT "firmware-not-overwritten.lua"
ARM7_BIOS
ARM9_BIOS
ARM7_DSI_BIOS
ARM9_DSI_BIOS
NDS_FIRMWARE
DSI_FIRMWARE
DSI_NAND
CORE_OPTION melonds_firmware_dsi_path="melonDS DS/${DSI_FIRMWARE_NAME}"
CORE_OPTION melonds_firmware_nds_path="melonDS DS/${NDS_FIRMWARE_NAME}"
CORE_OPTION melonds_dsi_nand_path="melonDS DS/${DSI_NAND_NAME}"
CORE_OPTION melonds_console_mode="dsi"
CORE_OPTION melonds_boot_directly="false"
CORE_OPTION melonds_sysfile_mode="native"
CORE_OPTION melonds_show_cursor="disabled"
)

View File

View File

@ -0,0 +1,14 @@
import os
from libretro import Session
import prelude
assert not os.access(prelude.wfcsettings_path, os.F_OK), f"{prelude.wfcsettings_path} should not exist yet"
session: Session
with prelude.session() as session:
for i in range(300):
session.core.run()
assert os.access(prelude.wfcsettings_path, os.F_OK), f"{prelude.wfcsettings_path} should exist by now"

View File

@ -0,0 +1,55 @@
import os
from libretro import Session
import prelude
nds_firmware_path = os.environ["NDS_FIRMWARE"]
nds_firmware_basename = os.path.basename(nds_firmware_path)
dsi_firmware_path = os.environ["DSI_FIRMWARE"]
dsi_firmware_basename = os.path.basename(dsi_firmware_path)
with open(nds_firmware_path, "rb") as firmware_file:
nds_firmware = firmware_file.read()
with open(dsi_firmware_path, "rb") as firmware_file:
dsi_firmware = firmware_file.read()
assert nds_firmware != dsi_firmware, "DS and DSi firmware are the same"
session: Session
with prelude.session() as session:
for i in range(30):
session.core.run()
match prelude.options[b'melonds_console_mode']:
case 'ds' | b'ds':
print("Switching to DSi mode")
session.options.variables['melonds_console_mode'] = b'dsi'
case 'dsi' | b'dsi':
print("Switching to DS mode")
session.options.variables['melonds_console_mode'] = b'ds'
case _ as mode:
raise ValueError(f"Unknown console mode {mode}")
session.core.reset()
for i in range(30):
session.core.run()
nds_firmware_path_local = os.path.join(prelude.core_system_dir, nds_firmware_basename)
dsi_firmware_path_local = os.path.join(prelude.core_system_dir, dsi_firmware_basename)
with open(nds_firmware_path_local, "rb") as nds_firmware_file_local:
nds_firmware_after = nds_firmware_file_local.read()
with open(dsi_firmware_path_local, "rb") as dsi_firmware_file_local:
dsi_firmware_after = dsi_firmware_file_local.read()
assert len(nds_firmware_after) == len(nds_firmware), \
f"DS firmware size changed from {len(nds_firmware)} to {len(nds_firmware_after)}"
assert len(dsi_firmware_after) == len(dsi_firmware), \
f"DSi firmware size changed from {len(dsi_firmware)} to {len(dsi_firmware_after)}"
assert nds_firmware_after != dsi_firmware_after, "Firmware was overwritten after switching console mode"

View File

@ -0,0 +1,17 @@
from libretro import Session
from libretro.api.vfs import StandardFileSystemInterface, HistoryFileSystemInterface, VfsOperation, VfsOperationType
import prelude
vfs = HistoryFileSystemInterface(StandardFileSystemInterface())
session: Session
with prelude.session(vfs=vfs) as session:
for i in range(300):
session.core.run()
op: VfsOperation
for op in filter(lambda f: f.operation == VfsOperationType.OPEN, vfs.history):
path = op.args[0]
assert isinstance(path, bytes), f"Expected path to be bytes, found {type(path).__name__} instead"
assert not path.endswith(b'bios7.bin'), f"{path} should not have been opened"
assert not path.endswith(b'bios9.bin'), f"{path} should not have been opened"

View File

@ -0,0 +1,22 @@
import os
from libretro import Session
import prelude
nds_firmware_path = os.environ["NDS_FIRMWARE"]
nds_firmware_basename = os.path.basename(nds_firmware_path)
test_nds_firmware_path = os.path.join(prelude.core_system_dir, nds_firmware_basename)
original_nds_firmware_size = os.stat(nds_firmware_path).st_size
assert original_nds_firmware_size > 0, f"{nds_firmware_path} is empty"
session: Session
with prelude.session() as session:
for i in range(300):
session.core.run()
test_nds_firmware_size = os.stat(test_nds_firmware_path).st_size
assert original_nds_firmware_size == test_nds_firmware_size, \
f"Expected firmware to be {original_nds_firmware_size} bytes after saving, found {test_nds_firmware_size} bytes"