Skip to content

Commit

Permalink
Write tests to ensure that wfcsettings.bin doesn't overwrite anything…
Browse files Browse the repository at this point in the history
… it shouldn't
  • Loading branch information
JesseTG committed Sep 8, 2023
1 parent 93011c0 commit 8334f73
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
38 changes: 35 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(Python3 COMPONENTS Interpreter)
find_package(Python3 3.8 REQUIRED COMPONENTS Interpreter)

if (NOT RETROARCH)
find_program(RETROARCH retroarch)
Expand Down Expand Up @@ -47,7 +47,7 @@ include(CMakePrintHelpers)

function(add_retroarch_test)
set(options WILL_FAIL ARM7_BIOS ARM9_BIOS ARM7_DSI_BIOS ARM9_DSI_BIOS NDS_FIRMWARE DSI_FIRMWARE DSI_NAND)
set(oneValueArgs NAME MAX_FRAMES CONTENT)
set(oneValueArgs NAME MAX_FRAMES CONTENT REQUIRE_FILE_SIZE_UNCHANGED REQUIRE_FILE_CREATED)
set(multiValueArgs CORE_OPTION PASS_REGULAR_EXPRESSION FAIL_REGULAR_EXPRESSION SKIP_REGULAR_EXPRESSION)
cmake_parse_arguments(PARSE_ARGV 0 RETRO "${options}" "${oneValueArgs}" "${multiValueArgs}")

Expand All @@ -69,6 +69,14 @@ function(add_retroarch_test)
list(APPEND REQUIRED_FILES "${RETRO_CONTENT}")
endif()

if (RETRO_REQUIRE_FILE_SIZE_UNCHANGED)
list(APPEND ENVIRONMENT "REQUIRE_FILE_SIZE_UNCHANGED=${RETRO_REQUIRE_FILE_SIZE_UNCHANGED}")
endif()

if (RETRO_REQUIRE_FILE_CREATED)
list(APPEND ENVIRONMENT "REQUIRE_FILE_CREATED=${RETRO_REQUIRE_FILE_CREATED}")
endif()

list(APPEND ENVIRONMENT "RETROARCH=${RETROARCH}")
list(APPEND ENVIRONMENT ${RETRO_CORE_OPTION}) # Not an omission, this is already a list

Expand Down Expand Up @@ -464,11 +472,35 @@ add_retroarch_test(
WILL_FAIL
)

### Using wfcsettings.bin

# 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/firmware.bin"
ARM7_BIOS
ARM9_BIOS
NDS_FIRMWARE
REQUIRE_FILE_SIZE_UNCHANGED "system/melonDS DS/firmware.bin"
)

add_retroarch_test(
NAME "Core saves wi-fi settings to wfcsettings.bin when using built-in firmware"
CONTENT "${CMAKE_BINARY_DIR}/mkds.nds"
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"
)

# TODO: Write the following test capabilities:
# - Copying a system file to a particular location
# - Select a GBA ROM
# - Select a GBA save file
# - Select a different test script

# TODO: Write the following tests:

Expand Down
29 changes: 28 additions & 1 deletion test/python/retroarch.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,31 @@ def retroarch():


if __name__ == "__main__":
sys.exit(retroarch())
require_file_size_unchanged = os.environ.get("REQUIRE_FILE_SIZE_UNCHANGED", None)
required_file_size: int | None = None
if require_file_size_unchanged is not None:
# If there's a file whose size we must ensure didn't change...
require_file_size_unchanged = os.path.join(tempdir, require_file_size_unchanged)
stat = os.stat(require_file_size_unchanged)
assert stat is not None
required_file_size = stat.st_size

require_file_created = os.environ.get("REQUIRE_FILE_CREATED", None)
if require_file_created is not None:
# If there's a file that we must ensure is newly-created...
require_file_created = os.path.join(tempdir, require_file_created)
assert not os.access(require_file_created, os.F_OK)

returnCode = retroarch()

if require_file_size_unchanged is not None:
# If there's a file whose size we must ensure didn't change...
stat = os.stat(require_file_size_unchanged)
assert stat is not None
assert stat.st_size == required_file_size

if require_file_created is not None:
# If there's a file that we must ensure is newly-created...
assert os.access(require_file_created, os.F_OK)

sys.exit(returnCode)

0 comments on commit 8334f73

Please sign in to comment.