From ccff012b1a470f4a4e7fdcf32d8fdb62336b0fd9 Mon Sep 17 00:00:00 2001 From: Jesse Talavera Date: Thu, 21 Mar 2024 17:06:18 -0400 Subject: [PATCH] Migrate more tests to libretro.py --- test/cmake/TestHomebrewSDCards.cmake | 70 +++++++++---------- test/lua/homebrew-sdcard-exists.lua | 13 ---- test/lua/homebrew-sdcard-sync-exists.lua | 14 ---- test/python/prelude.py | 2 + test/python/save/__init__.py | 0 test/python/save/homebrew_sd_card_exists.py | 15 ++++ .../save/homebrew_sd_card_sync_exists.py | 14 ++++ 7 files changed, 66 insertions(+), 62 deletions(-) delete mode 100644 test/lua/homebrew-sdcard-exists.lua delete mode 100644 test/lua/homebrew-sdcard-sync-exists.lua create mode 100644 test/python/save/__init__.py create mode 100644 test/python/save/homebrew_sd_card_exists.py create mode 100644 test/python/save/homebrew_sd_card_sync_exists.py diff --git a/test/cmake/TestHomebrewSDCards.cmake b/test/cmake/TestHomebrewSDCards.cmake index e41e2aa..b044514 100644 --- a/test/cmake/TestHomebrewSDCards.cmake +++ b/test/cmake/TestHomebrewSDCards.cmake @@ -1,68 +1,68 @@ -add_emutest_test( +add_python_test( NAME "Homebrew SD card image is not created if loading a retail ROM" CONTENT "${NDS_ROM}" - TEST_SCRIPT "homebrew-sdcard-exists.lua" - CORE_OPTION melonds_console_mode="ds" - CORE_OPTION melonds_homebrew_sdcard="enabled" - CORE_OPTION melonds_homebrew_sync_sdcard_to_host="disabled" + TEST_MODULE save.homebrew_sd_card_exists + CORE_OPTION "melonds_console_mode=ds" + CORE_OPTION "melonds_homebrew_sdcard=enabled" + CORE_OPTION "melonds_homebrew_sync_sdcard_to_host=disabled" WILL_FAIL ) -add_emutest_test( +add_python_test( NAME "Homebrew SD card image is not created if disabled and loading a retail ROM" CONTENT "${NDS_ROM}" - TEST_SCRIPT "homebrew-sdcard-exists.lua" - CORE_OPTION melonds_console_mode="ds" - CORE_OPTION melonds_homebrew_sdcard="disabled" - CORE_OPTION melonds_homebrew_sync_sdcard_to_host="disabled" + TEST_MODULE save.homebrew_sd_card_exists + CORE_OPTION "melonds_console_mode=ds" + CORE_OPTION "melonds_homebrew_sdcard=disabled" + CORE_OPTION "melonds_homebrew_sync_sdcard_to_host=disabled" WILL_FAIL ) -add_emutest_test( +add_python_test( NAME "Homebrew SD card image is created if enabled and loading a homebrew ROM" CONTENT "${GODMODE9I_ROM}" - TEST_SCRIPT "homebrew-sdcard-exists.lua" - CORE_OPTION melonds_console_mode="ds" - CORE_OPTION melonds_homebrew_sdcard="enabled" - CORE_OPTION melonds_homebrew_sync_sdcard_to_host="disabled" + TEST_MODULE save.homebrew_sd_card_exists + CORE_OPTION "melonds_console_mode=ds" + CORE_OPTION "melonds_homebrew_sdcard=enabled" + CORE_OPTION "melonds_homebrew_sync_sdcard_to_host=disabled" ) -add_emutest_test( +add_python_test( NAME "Homebrew SD card image is not created if disabled and loading a homebrew ROM" CONTENT "${GODMODE9I_ROM}" - TEST_SCRIPT "homebrew-sdcard-exists.lua" - CORE_OPTION melonds_console_mode="ds" - CORE_OPTION melonds_homebrew_sdcard="disabled" - CORE_OPTION melonds_homebrew_sync_sdcard_to_host="disabled" + TEST_MODULE save.homebrew_sd_card_exists + CORE_OPTION "melonds_console_mode=ds" + CORE_OPTION "melonds_homebrew_sdcard=disabled" + CORE_OPTION "melonds_homebrew_sync_sdcard_to_host=disabled" WILL_FAIL ) -add_emutest_test( +add_python_test( NAME "Homebrew SD card sync folder is not created if SD card is enabled and loading a retail ROM" CONTENT "${NDS_ROM}" - TEST_SCRIPT "homebrew-sdcard-sync-exists.lua" - CORE_OPTION melonds_console_mode="ds" - CORE_OPTION melonds_homebrew_sdcard="enabled" - CORE_OPTION melonds_homebrew_sync_sdcard_to_host="enabled" + TEST_MODULE save.homebrew_sd_card_sync_exists + CORE_OPTION "melonds_console_mode=ds" + CORE_OPTION "melonds_homebrew_sdcard=enabled" + CORE_OPTION "melonds_homebrew_sync_sdcard_to_host=enabled" WILL_FAIL ) -add_emutest_test( +add_python_test( NAME "Homebrew SD card sync folder is not created if SD card sync is disabled and loading a retail ROM" CONTENT "${NDS_ROM}" - TEST_SCRIPT "homebrew-sdcard-sync-exists.lua" - CORE_OPTION melonds_console_mode="ds" - CORE_OPTION melonds_homebrew_sdcard="enabled" - CORE_OPTION melonds_homebrew_sync_sdcard_to_host="disabled" + TEST_MODULE save.homebrew_sd_card_sync_exists + CORE_OPTION "melonds_console_mode=ds" + CORE_OPTION "melonds_homebrew_sdcard=enabled" + CORE_OPTION "melonds_homebrew_sync_sdcard_to_host=disabled" WILL_FAIL ) -add_emutest_test( +add_python_test( NAME "Homebrew SD card sync folder is not created if SD card sync is disabled and loading a homebrew ROM" CONTENT "${GODMODE9I_ROM}" - TEST_SCRIPT "homebrew-sdcard-sync-exists.lua" - CORE_OPTION melonds_console_mode="ds" - CORE_OPTION melonds_homebrew_sdcard="enabled" - CORE_OPTION melonds_homebrew_sync_sdcard_to_host="disabled" + TEST_MODULE save.homebrew_sd_card_sync_exists + CORE_OPTION "melonds_console_mode=ds" + CORE_OPTION "melonds_homebrew_sdcard=enabled" + CORE_OPTION "melonds_homebrew_sync_sdcard_to_host=disabled" WILL_FAIL ) \ No newline at end of file diff --git a/test/lua/homebrew-sdcard-exists.lua b/test/lua/homebrew-sdcard-exists.lua deleted file mode 100644 index c116a25..0000000 --- a/test/lua/homebrew-sdcard-exists.lua +++ /dev/null @@ -1,13 +0,0 @@ -local preamble = dofile(os.getenv("PREAMBLE")) - -set_options_string(preamble.options_string) - -load_core(corepath) -load_game(rompath) -run() - -local homebrew_sd_card, sdcard_err = io.open(preamble.core_save_dir .. "/dldi_sd_card.bin", "rb") -if homebrew_sd_card == nil or sdcard_err ~= nil then - print(get_logs()) - error("Failed to open homebrew SD card: " .. sdcard_err) -end diff --git a/test/lua/homebrew-sdcard-sync-exists.lua b/test/lua/homebrew-sdcard-sync-exists.lua deleted file mode 100644 index 52a31e3..0000000 --- a/test/lua/homebrew-sdcard-sync-exists.lua +++ /dev/null @@ -1,14 +0,0 @@ -local preamble = dofile(os.getenv("PREAMBLE")) - -set_options_string(preamble.options_string) - -load_core(corepath) -load_game(rompath) -run() - -local cmake = os.getenv("CMAKE") -local ok, reason, code = os.execute(string.format('"%s" -E chdir "%s" true', cmake, preamble.core_save_dir .. "/dldi_sd_card")) -if ok ~= true then - print(get_logs()) - error("Failed to open homebrew SD card sync directory") -end diff --git a/test/python/prelude.py b/test/python/prelude.py index 39a4436..01971de 100644 --- a/test/python/prelude.py +++ b/test/python/prelude.py @@ -17,6 +17,8 @@ savestate_directory = os.path.join(testdir.name, "states") core_system_dir = os.path.join(system_dir, "melonDS DS") core_save_dir = os.path.join(save_dir, "melonDS DS") wfcsettings_path = os.path.join(core_system_dir, "wfcsettings.bin") +dldi_sd_card_path = os.path.join(core_save_dir, "dldi_sd_card.bin") +dldi_sd_card_sync_path = os.path.join(core_save_dir, "dldi_sd_card") print("Test dir:", testdir.name) print("System dir:", system_dir) diff --git a/test/python/save/__init__.py b/test/python/save/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/python/save/homebrew_sd_card_exists.py b/test/python/save/homebrew_sd_card_exists.py new file mode 100644 index 0000000..ab87394 --- /dev/null +++ b/test/python/save/homebrew_sd_card_exists.py @@ -0,0 +1,15 @@ +import os +import stat + +from libretro import Session + +import prelude + +session: Session +with prelude.session() as session: + session.core.run() + + dldi_sdcard_stat = os.stat(prelude.dldi_sd_card_path) + + assert stat.S_ISREG(dldi_sdcard_stat.st_mode), "dldi_sd_card.bin should be a regular file" + assert dldi_sdcard_stat.st_size > 0, "dldi_sd_card.bin should exist and be non-empty" diff --git a/test/python/save/homebrew_sd_card_sync_exists.py b/test/python/save/homebrew_sd_card_sync_exists.py new file mode 100644 index 0000000..7367c5d --- /dev/null +++ b/test/python/save/homebrew_sd_card_sync_exists.py @@ -0,0 +1,14 @@ +import os +import stat + +from libretro import Session + +import prelude + +session: Session +with prelude.session() as session: + session.core.run() + + dldi_sdcard_stat = os.stat(prelude.dldi_sd_card_sync_path) + + assert stat.S_ISDIR(dldi_sdcard_stat.st_mode), "dldi_sd_card should be a directory"