Headless: Rename mgba-rom-test to mgba-headless

This commit is contained in:
Vicki Pfau 2025-01-02 01:58:41 -08:00
parent 69ead6e3c9
commit d9aa7d5103
3 changed files with 53 additions and 52 deletions

View File

@ -72,7 +72,7 @@ if(NOT LIBMGBA_ONLY)
set(BUILD_TEST OFF CACHE BOOL "Build testing harness") set(BUILD_TEST OFF CACHE BOOL "Build testing harness")
set(BUILD_SUITE OFF CACHE BOOL "Build test suite") set(BUILD_SUITE OFF CACHE BOOL "Build test suite")
set(BUILD_CINEMA OFF CACHE BOOL "Build video tests suite") set(BUILD_CINEMA OFF CACHE BOOL "Build video tests suite")
set(BUILD_ROM_TEST OFF CACHE BOOL "Build ROM test tool") set(BUILD_HEADLESS OFF CACHE BOOL "Build headless tool")
set(BUILD_EXAMPLE OFF CACHE BOOL "Build example frontends") set(BUILD_EXAMPLE OFF CACHE BOOL "Build example frontends")
set(BUILD_PYTHON OFF CACHE BOOL "Build Python bindings") set(BUILD_PYTHON OFF CACHE BOOL "Build Python bindings")
set(BUILD_STATIC OFF CACHE BOOL "Build a static library") set(BUILD_STATIC OFF CACHE BOOL "Build a static library")
@ -1037,6 +1037,13 @@ if(BUILD_QT)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/qt ${CMAKE_CURRENT_BINARY_DIR}/qt) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/qt ${CMAKE_CURRENT_BINARY_DIR}/qt)
endif() endif()
if(BUILD_HEADLESS)
add_executable(${BINARY_NAME}-headless ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/headless-main.c)
target_link_libraries(${BINARY_NAME}-headless ${BINARY_NAME})
target_compile_definitions(${BINARY_NAME}-headless PRIVATE "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
install(TARGETS ${BINARY_NAME}-headless DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-headless)
endif()
if(NOT USE_CMOCKA) if(NOT USE_CMOCKA)
set(BUILD_SUITE OFF) set(BUILD_SUITE OFF)
endif() endif()
@ -1213,6 +1220,7 @@ elseif(BUILD_STATIC)
cpack_add_component(lib${BINARY_NAME} GROUP dev) cpack_add_component(lib${BINARY_NAME} GROUP dev)
endif() endif()
cpack_add_component(${BINARY_NAME}-dev GROUP dev) cpack_add_component(${BINARY_NAME}-dev GROUP dev)
cpack_add_component(${BINARY_NAME}-headless GROUP dev)
if(3DS) if(3DS)
cpack_add_component(${BINARY_NAME}-3ds GROUP base) cpack_add_component(${BINARY_NAME}-3ds GROUP base)
@ -1318,6 +1326,7 @@ if(NOT QUIET AND NOT LIBMGBA_ONLY)
message(STATUS "Frontends:") message(STATUS "Frontends:")
message(STATUS " Qt: ${BUILD_QT}") message(STATUS " Qt: ${BUILD_QT}")
message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}") message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
message(STATUS " Headless: ${BUILD_HEADLESS}")
message(STATUS " Python bindings: ${BUILD_PYTHON}") message(STATUS " Python bindings: ${BUILD_PYTHON}")
message(STATUS " Examples: ${BUILD_EXAMPLE}") message(STATUS " Examples: ${BUILD_EXAMPLE}")
message(STATUS "Test tools:") message(STATUS "Test tools:")
@ -1325,7 +1334,6 @@ if(NOT QUIET AND NOT LIBMGBA_ONLY)
message(STATUS " Test harness: ${BUILD_TEST}") message(STATUS " Test harness: ${BUILD_TEST}")
message(STATUS " Test suite: ${BUILD_SUITE}") message(STATUS " Test suite: ${BUILD_SUITE}")
message(STATUS " Video test suite: ${BUILD_CINEMA}") message(STATUS " Video test suite: ${BUILD_CINEMA}")
message(STATUS " ROM tester: ${BUILD_ROM_TEST}")
message(STATUS "Cores:") message(STATUS "Cores:")
message(STATUS " Libretro core: ${BUILD_LIBRETRO}") message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
message(STATUS "Libraries:") message(STATUS "Libraries:")

View File

@ -29,8 +29,8 @@
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#define ROM_TEST_OPTIONS "S:R:" #define HEADLESS_OPTIONS "S:R:"
static const char* const romTestUsage = static const char* const headlessUsage =
"Additional options:\n" "Additional options:\n"
" -S SWI Run until specified SWI call before exiting\n" " -S SWI Run until specified SWI call before exiting\n"
" -R REGISTER General purpose register to return as exit code\n" " -R REGISTER General purpose register to return as exit code\n"
@ -39,18 +39,18 @@ static const char* const romTestUsage =
#endif #endif
; ;
struct RomTestOpts { struct HeadlessOpts {
int exitSwiImmediate; int exitSwiImmediate;
char* returnCodeRegister; char* returnCodeRegister;
struct StringList scripts; struct StringList scripts;
}; };
static void _romTestShutdown(int signal); static void _headlessShutdown(int signal);
static bool _parseRomTestOpts(struct mSubParser* parser, int option, const char* arg); static bool _parseHeadlessOpts(struct mSubParser* parser, int option, const char* arg);
static bool _parseLongRomTestOpts(struct mSubParser* parser, const char* option, const char* arg); static bool _parseLongHeadlessOpts(struct mSubParser* parser, const char* option, const char* arg);
static bool _parseSwi(const char* regStr, int* oSwi); static bool _parseSwi(const char* regStr, int* oSwi);
static bool _romTestCheckResiger(void); static bool _headlessCheckResiger(void);
static struct mCore* core; static struct mCore* core;
@ -58,10 +58,10 @@ static bool _dispatchExiting = false;
static int _exitCode = 0; static int _exitCode = 0;
static struct mStandardLogger _logger; static struct mStandardLogger _logger;
static void _romTestCallback(void* context); static void _headlessCallback(void* context);
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
static void _romTestSwi16(struct ARMCore* cpu, int immediate); static void _headlessSwi16(struct ARMCore* cpu, int immediate);
static void _romTestSwi32(struct ARMCore* cpu, int immediate); static void _headlessSwi32(struct ARMCore* cpu, int immediate);
static int _exitSwiImmediate; static int _exitSwiImmediate;
static char* _returnCodeRegister; static char* _returnCodeRegister;
@ -71,18 +71,18 @@ void (*_armSwi32)(struct ARMCore* cpu, int immediate);
#endif #endif
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
signal(SIGINT, _romTestShutdown); signal(SIGINT, _headlessShutdown);
bool cleanExit = false; bool cleanExit = false;
int uncleanExit = 1; int uncleanExit = 1;
struct RomTestOpts romTestOpts = { 3, NULL }; struct HeadlessOpts headlessOpts = { 3, NULL };
StringListInit(&romTestOpts.scripts, 0); StringListInit(&headlessOpts.scripts, 0);
struct mSubParser subparser = { struct mSubParser subparser = {
.usage = romTestUsage, .usage = headlessUsage,
.parse = _parseRomTestOpts, .parse = _parseHeadlessOpts,
.parseLong = _parseLongRomTestOpts, .parseLong = _parseLongHeadlessOpts,
.extraOptions = ROM_TEST_OPTIONS, .extraOptions = HEADLESS_OPTIONS,
.longOptions = (struct mOption[]) { .longOptions = (struct mOption[]) {
{ {
.name = "script", .name = "script",
@ -90,7 +90,7 @@ int main(int argc, char * argv[]) {
}, },
{0} {0}
}, },
.opts = &romTestOpts .opts = &headlessOpts
}; };
struct mArguments args; struct mArguments args;
@ -113,7 +113,7 @@ int main(int argc, char * argv[]) {
goto argsExit; goto argsExit;
} }
core->init(core); core->init(core);
mCoreInitConfig(core, "romTest"); mCoreInitConfig(core, "headless");
mArgumentsApply(&args, NULL, 0, &core->config); mArgumentsApply(&args, NULL, 0, &core->config);
mCoreConfigSetDefaultValue(&core->config, "idleOptimization", "remove"); mCoreConfigSetDefaultValue(&core->config, "idleOptimization", "remove");
@ -126,8 +126,8 @@ int main(int argc, char * argv[]) {
struct mCoreCallbacks callbacks = {0}; struct mCoreCallbacks callbacks = {0};
_returnCodeRegister = romTestOpts.returnCodeRegister; _returnCodeRegister = headlessOpts.returnCodeRegister;
if (!_romTestCheckResiger()) { if (!_headlessCheckResiger()) {
goto loadError; goto loadError;
} }
@ -135,24 +135,24 @@ int main(int argc, char * argv[]) {
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
case mPLATFORM_GBA: case mPLATFORM_GBA:
((struct GBA*) core->board)->hardCrash = false; ((struct GBA*) core->board)->hardCrash = false;
_exitSwiImmediate = romTestOpts.exitSwiImmediate; _exitSwiImmediate = headlessOpts.exitSwiImmediate;
if (_exitSwiImmediate == 3) { if (_exitSwiImmediate == 3) {
// Hook into SWI 3 (shutdown) // Hook into SWI 3 (shutdown)
callbacks.shutdown = _romTestCallback; callbacks.shutdown = _headlessCallback;
core->addCoreCallbacks(core, &callbacks); core->addCoreCallbacks(core, &callbacks);
} else { } else {
// Custom SWI hooks // Custom SWI hooks
_armSwi16 = ((struct GBA*) core->board)->cpu->irqh.swi16; _armSwi16 = ((struct GBA*) core->board)->cpu->irqh.swi16;
((struct GBA*) core->board)->cpu->irqh.swi16 = _romTestSwi16; ((struct GBA*) core->board)->cpu->irqh.swi16 = _headlessSwi16;
_armSwi32 = ((struct GBA*) core->board)->cpu->irqh.swi32; _armSwi32 = ((struct GBA*) core->board)->cpu->irqh.swi32;
((struct GBA*) core->board)->cpu->irqh.swi32 = _romTestSwi32; ((struct GBA*) core->board)->cpu->irqh.swi32 = _headlessSwi32;
} }
break; break;
#endif #endif
#ifdef M_CORE_GB #ifdef M_CORE_GB
case mPLATFORM_GB: case mPLATFORM_GB:
callbacks.shutdown = _romTestCallback; callbacks.shutdown = _headlessCallback;
core->addCoreCallbacks(core, &callbacks); core->addCoreCallbacks(core, &callbacks);
break; break;
#endif #endif
@ -193,7 +193,7 @@ int main(int argc, char * argv[]) {
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
struct mScriptContext scriptContext; struct mScriptContext scriptContext;
if (StringListSize(&romTestOpts.scripts)) { if (StringListSize(&headlessOpts.scripts)) {
mScriptContextInit(&scriptContext); mScriptContextInit(&scriptContext);
mScriptContextAttachStdlib(&scriptContext); mScriptContextAttachStdlib(&scriptContext);
mScriptContextAttachImage(&scriptContext); mScriptContextAttachImage(&scriptContext);
@ -207,9 +207,9 @@ int main(int argc, char * argv[]) {
mScriptContextAttachCore(&scriptContext, core); mScriptContextAttachCore(&scriptContext, core);
size_t i; size_t i;
for (i = 0; i < StringListSize(&romTestOpts.scripts); ++i) { for (i = 0; i < StringListSize(&headlessOpts.scripts); ++i) {
if (!mScriptContextLoadFile(&scriptContext, *StringListGetPointer(&romTestOpts.scripts, i))) { if (!mScriptContextLoadFile(&scriptContext, *StringListGetPointer(&headlessOpts.scripts, i))) {
mLOG(STATUS, ERROR, "Failed to load script \"%s\"", *StringListGetPointer(&romTestOpts.scripts, i)); mLOG(STATUS, ERROR, "Failed to load script \"%s\"", *StringListGetPointer(&headlessOpts.scripts, i));
goto scriptsError; goto scriptsError;
} }
} }
@ -232,7 +232,7 @@ scriptsError:
core->unloadROM(core); core->unloadROM(core);
#ifdef ENABLE_SCRIPTING #ifdef ENABLE_SCRIPTING
if (StringListSize(&romTestOpts.scripts)) { if (StringListSize(&headlessOpts.scripts)) {
mScriptContextDeinit(&scriptContext); mScriptContextDeinit(&scriptContext);
} }
#endif #endif
@ -254,21 +254,21 @@ loadError:
argsExit: argsExit:
size_t i; size_t i;
for (i = 0; i < StringListSize(&romTestOpts.scripts); ++i) { for (i = 0; i < StringListSize(&headlessOpts.scripts); ++i) {
free(*StringListGetPointer(&romTestOpts.scripts, i)); free(*StringListGetPointer(&headlessOpts.scripts, i));
} }
StringListDeinit(&romTestOpts.scripts); StringListDeinit(&headlessOpts.scripts);
mArgumentsDeinit(&args); mArgumentsDeinit(&args);
return cleanExit ? _exitCode : uncleanExit; return cleanExit ? _exitCode : uncleanExit;
} }
static void _romTestShutdown(int signal) { static void _headlessShutdown(int signal) {
UNUSED(signal); UNUSED(signal);
_dispatchExiting = true; _dispatchExiting = true;
} }
static bool _romTestCheckResiger(void) { static bool _headlessCheckResiger(void) {
if (!_returnCodeRegister) { if (!_returnCodeRegister) {
return true; return true;
} }
@ -314,7 +314,7 @@ static bool _romTestCheckResiger(void) {
return true; return true;
} }
static void _romTestCallback(void* context) { static void _headlessCallback(void* context) {
UNUSED(context); UNUSED(context);
if (_returnCodeRegister) { if (_returnCodeRegister) {
core->readRegister(core, _returnCodeRegister, &_exitCode); core->readRegister(core, _returnCodeRegister, &_exitCode);
@ -323,7 +323,7 @@ static void _romTestCallback(void* context) {
} }
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
static void _romTestSwi16(struct ARMCore* cpu, int immediate) { static void _headlessSwi16(struct ARMCore* cpu, int immediate) {
if (immediate == _exitSwiImmediate) { if (immediate == _exitSwiImmediate) {
if (_returnCodeRegister) { if (_returnCodeRegister) {
core->readRegister(core, _returnCodeRegister, &_exitCode); core->readRegister(core, _returnCodeRegister, &_exitCode);
@ -334,7 +334,7 @@ static void _romTestSwi16(struct ARMCore* cpu, int immediate) {
_armSwi16(cpu, immediate); _armSwi16(cpu, immediate);
} }
static void _romTestSwi32(struct ARMCore* cpu, int immediate) { static void _headlessSwi32(struct ARMCore* cpu, int immediate) {
if (immediate == _exitSwiImmediate) { if (immediate == _exitSwiImmediate) {
if (_returnCodeRegister) { if (_returnCodeRegister) {
core->readRegister(core, _returnCodeRegister, &_exitCode); core->readRegister(core, _returnCodeRegister, &_exitCode);
@ -346,8 +346,8 @@ static void _romTestSwi32(struct ARMCore* cpu, int immediate) {
} }
#endif #endif
static bool _parseRomTestOpts(struct mSubParser* parser, int option, const char* arg) { static bool _parseHeadlessOpts(struct mSubParser* parser, int option, const char* arg) {
struct RomTestOpts* opts = parser->opts; struct HeadlessOpts* opts = parser->opts;
errno = 0; errno = 0;
switch (option) { switch (option) {
case 'S': case 'S':
@ -360,8 +360,8 @@ static bool _parseRomTestOpts(struct mSubParser* parser, int option, const char*
} }
} }
static bool _parseLongRomTestOpts(struct mSubParser* parser, const char* option, const char* arg) { static bool _parseLongHeadlessOpts(struct mSubParser* parser, const char* option, const char* arg) {
struct RomTestOpts* opts = parser->opts; struct HeadlessOpts* opts = parser->opts;
if (strcmp(option, "script") == 0) { if (strcmp(option, "script") == 0) {
*StringListAppend(&opts->scripts) = strdup(arg); *StringListAppend(&opts->scripts) = strdup(arg);
return true; return true;

View File

@ -46,10 +46,3 @@ if(BUILD_CINEMA)
add_test(cinema ${BINARY_NAME}-cinema -v) add_test(cinema ${BINARY_NAME}-cinema -v)
install(TARGETS ${BINARY_NAME}-cinema DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-test) install(TARGETS ${BINARY_NAME}-cinema DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-test)
endif() endif()
if(BUILD_ROM_TEST)
add_executable(${BINARY_NAME}-rom-test ${CMAKE_CURRENT_SOURCE_DIR}/rom-test-main.c)
target_link_libraries(${BINARY_NAME}-rom-test ${BINARY_NAME})
target_compile_definitions(${BINARY_NAME}-rom-test PRIVATE "${OS_DEFINES};${FEATURE_DEFINES};${FUNCTION_DEFINES}")
install(TARGETS ${BINARY_NAME}-rom-test DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-test)
endif()