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_SUITE OFF CACHE BOOL "Build test 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_PYTHON OFF CACHE BOOL "Build Python bindings")
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)
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)
set(BUILD_SUITE OFF)
endif()
@ -1213,6 +1220,7 @@ elseif(BUILD_STATIC)
cpack_add_component(lib${BINARY_NAME} GROUP dev)
endif()
cpack_add_component(${BINARY_NAME}-dev GROUP dev)
cpack_add_component(${BINARY_NAME}-headless GROUP dev)
if(3DS)
cpack_add_component(${BINARY_NAME}-3ds GROUP base)
@ -1318,6 +1326,7 @@ if(NOT QUIET AND NOT LIBMGBA_ONLY)
message(STATUS "Frontends:")
message(STATUS " Qt: ${BUILD_QT}")
message(STATUS " SDL (${SDL_VERSION}): ${BUILD_SDL}")
message(STATUS " Headless: ${BUILD_HEADLESS}")
message(STATUS " Python bindings: ${BUILD_PYTHON}")
message(STATUS " Examples: ${BUILD_EXAMPLE}")
message(STATUS "Test tools:")
@ -1325,7 +1334,6 @@ if(NOT QUIET AND NOT LIBMGBA_ONLY)
message(STATUS " Test harness: ${BUILD_TEST}")
message(STATUS " Test suite: ${BUILD_SUITE}")
message(STATUS " Video test suite: ${BUILD_CINEMA}")
message(STATUS " ROM tester: ${BUILD_ROM_TEST}")
message(STATUS "Cores:")
message(STATUS " Libretro core: ${BUILD_LIBRETRO}")
message(STATUS "Libraries:")

View File

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

View File

@ -46,10 +46,3 @@ if(BUILD_CINEMA)
add_test(cinema ${BINARY_NAME}-cinema -v)
install(TARGETS ${BINARY_NAME}-cinema DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${BINARY_NAME}-test)
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()