Implement or update some tests

This commit is contained in:
Jesse Talavera 2024-03-06 21:24:10 -05:00
parent 5b0ed4a8d8
commit 9f432f7b00
16 changed files with 142 additions and 34 deletions

View File

@ -30,6 +30,8 @@ add_library(melondsds_libretro MODULE
core/core.cpp
core/core.hpp
core/tasks.cpp
core/test.cpp
core/test.hpp
environment.cpp
environment.hpp
exceptions.cpp

View File

@ -0,0 +1,31 @@
/*
Copyright 2024 Jesse Talavera
melonDS DS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS DS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS DS. If not, see http://www.gnu.org/licenses/.
*/
#include "test.hpp"
#include <string/stdstring.h>
extern "C" int libretropy_add_integers(int a, int b) {
return a + b;
}
retro_proc_address_t MelonDsDs::GetProcAddress(const char* sym) noexcept {
if (string_is_equal(sym, "libretropy_add_integers"))
return reinterpret_cast<retro_proc_address_t>(libretropy_add_integers);
return nullptr;
}

View File

@ -0,0 +1,25 @@
/*
Copyright 2024 Jesse Talavera
melonDS DS is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
melonDS DS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with melonDS DS. If not, see http://www.gnu.org/licenses/.
*/
#pragma once
#include <libretro.h>
namespace MelonDsDs
{
// test functions for the test suite
retro_proc_address_t GetProcAddress(const char* sym) noexcept;
}

View File

@ -37,6 +37,7 @@
#include "info.hpp"
#include "libretro.hpp"
#include "config/config.hpp"
#include "core/test.hpp"
#include "tracy.hpp"
#include "version.hpp"

View File

@ -334,15 +334,3 @@ void Platform::WriteFirmware(const Firmware& firmware, u32 writeoffset, u32 writ
MelonDsDs::Core.WriteFirmware(firmware, writeoffset, writelen);
}
extern "C" int libretropy_add_integers(int a, int b) {
return a + b;
}
retro_proc_address_t MelonDsDs::GetProcAddress(const char* sym) noexcept {
if (sym == "libretropy_add_integers")
return reinterpret_cast<retro_proc_address_t>(libretropy_add_integers);
return nullptr;
}

View File

@ -39,7 +39,6 @@ namespace MelonDsDs {
void HardwareContextReset() noexcept;
void HardwareContextDestroyed() noexcept;
bool UpdateOptionVisibility() noexcept;
retro_proc_address_t GetProcAddress(const char* sym) noexcept;
}
#endif //MELONDS_DS_LIBRETRO_HPP

View File

@ -138,12 +138,14 @@ add_python_test(
add_python_test(
NAME "Core sets pixel format to XRGB8888"
TEST_MODULE ""
TEST_MODULE basics.core_sets_pixel_format
CONTENT "${NDS_ROM}"
)
add_python_test(
NAME "Core sets input descriptors"
TEST_MODULE ""
TEST_MODULE basics.core_defines_input_descriptors
NDS_SYSFILES
)
add_python_test(
@ -163,21 +165,19 @@ add_python_test(
add_python_test(
NAME "Core registers support for no-content mode"
TEST_MODULE "basics.core_registers_no_content_support"
TEST_MODULE basics.core_registers_no_content_support
CONTENT "${NDS_ROM}"
)
add_python_test(
NAME "Core loads and unloads without content"
TEST_MODULE "basics.core_loads_unloads_without_content"
TEST_MODULE basics.core_loads_unloads_without_content
)
add_python_test(
NAME "Core logs output"
TEST_MODULE "basics.core_logs_output"
ARM7_BIOS
ARM9_BIOS
NDS_FIRMWARE
TEST_MODULE basics.core_logs_output
NDS_SYSFILES
)
add_python_test(
@ -187,13 +187,14 @@ add_python_test(
add_python_test(
NAME "Core sets retro_get_proc_address_interface"
TEST_MODULE "basics.core_get_proc_address"
CONTENT "${NDS_ROM}"
TEST_MODULE basics.core_get_proc_address
NDS_SYSFILES
)
add_python_test(
NAME "Core defines subsystems"
TEST_MODULE ""
TEST_MODULE basics.core_defines_subsystems
NDS_SYSFILES
)
add_python_test(
@ -203,7 +204,8 @@ add_python_test(
add_python_test(
NAME "Core defines controller info"
TEST_MODULE ""
TEST_MODULE basics.core_defines_controller_info
NDS_SYSFILES
)
add_python_test(
@ -213,7 +215,8 @@ add_python_test(
add_python_test(
NAME "Core registers support for achievements"
TEST_MODULE ""
TEST_MODULE basics.core_registers_achievement_support
NDS_SYSFILES
)
add_python_test(
@ -253,7 +256,8 @@ add_python_test(
add_python_test(
NAME "Core sets content info overrides"
TEST_MODULE ""
TEST_MODULE basics.core_defines_content_info_overrides
NDS_SYSFILES
)
add_python_test(

View File

@ -0,0 +1,10 @@
from libretro import default_session
import prelude
with default_session(prelude.core_path) as session:
overrides = session.content_info_overrides
assert overrides is not None
assert len(overrides) > 0
assert all(o.extensions for o in overrides)

View File

@ -0,0 +1,9 @@
from libretro import default_session
import prelude
with default_session(prelude.core_path) as session:
info = session.controller_info
assert info is not None
assert info.num_types > 0

View File

@ -0,0 +1,11 @@
from ctypes import *
from libretro import default_session, retro_get_proc_address_t
import prelude
with default_session(prelude.core_path) as session:
descriptors = session.input_descriptors
assert descriptors is not None
assert len(descriptors) > 0
assert all(d.description for d in descriptors)

View File

@ -0,0 +1,10 @@
from libretro import default_session
import prelude
with default_session(prelude.core_path) as session:
subsystems = session.subsystems
assert subsystems is not None
assert len(subsystems) > 0
assert all(s.desc for s in subsystems)

View File

@ -1,17 +1,19 @@
from ctypes import *
from sys import argv
from libretro import default_session, retro_get_proc_address_t
with default_session(argv[1]) as env:
proc_address_callback = env.proc_address_callback
import prelude
with default_session(prelude.core_path) as session:
proc_address_callback = session.proc_address_callback
assert proc_address_callback is not None
get_proc_address: retro_get_proc_address_t = proc_address_callback.get_proc_address
assert get_proc_address is not None
add_integers = get_proc_address("libretropy_add_integers")
add_integers = get_proc_address(b"libretropy_add_integers")
assert add_integers is not None
add_integers_callable = cast(add_integers, CFUNCTYPE(c_int, c_int, c_int))
assert add_integers_callable is not None
assert add_integers_callable(1, 2) == 3

View File

@ -1,11 +1,10 @@
from sys import argv
from typing import cast
from libretro import default_session
from libretro.callback.log import StandardLogger
import prelude
with default_session(argv[1], system_dir=prelude.core_system_dir) as session:
with default_session(prelude.core_path, system_dir=prelude.core_system_dir) as session:
log: StandardLogger = cast(StandardLogger, session.log)
assert log is not None
assert log.records is not None

View File

@ -0,0 +1,6 @@
from libretro import default_session
import prelude
with default_session(prelude.core_path, prelude.content_path) as env:
assert env.support_achievements is True

View File

@ -0,0 +1,8 @@
from sys import argv
from libretro import default_session
from libretro.defs import PixelFormat
import prelude
with default_session(prelude.core_path) as session:
assert session.video.pixel_format == PixelFormat.XRGB8888

View File

@ -1,5 +1,6 @@
import os
import shutil
import sys
import tempfile
if not __debug__:
@ -30,3 +31,5 @@ for _f in SYSTEM_FILES:
shutil.copyfile(os.environ[_f], targetpath)
options_string = os.getenv("RETRO_CORE_OPTIONS")
core_path = sys.argv[1]
content_path = sys.argv[2] if len(sys.argv) > 2 else None