Skip to content

Commit

Permalink
Fixes and comments for test input driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltanvb committed Mar 18, 2024
1 parent 7e6a1ba commit bed6bd1
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 34 deletions.
3 changes: 3 additions & 0 deletions cores/libretro-net-retropad/net_retropad_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,9 @@ void NETRETROPAD_CORE_PREFIX(retro_run)(void)
NETRETROPAD_CORE_PREFIX(log_cb)(RETRO_LOG_INFO,
"[Remote RetroPad]: Test sequence finished at frame %d, result: %d/%d inputs detected\n",
current_frame, pass_count, last_test_step);
NETRETROPAD_CORE_PREFIX(log_cb)(RETRO_LOG_INFO,
"[Remote RetroPad]: Validated state: %08x combo: %08x\n",
input_state_validated, combo_state_validated);
}
}

Expand Down
84 changes: 56 additions & 28 deletions input/drivers_joypad/test_joypad.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/

/* Possible improvement list:
* Add vid/pid to autoconf profile step
* Add vid/pid to autoconf profile step, if autoconf matching needs testing
* Multiple device autoconf profiles, with different analog/digital setup, analog buttons, extra buttons, unconfigured buttons...
* Unimplemented functions (get_button, rumble)
*/

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -41,6 +43,14 @@
#define MAX_AXIS 10
#endif

#define JOYPAD_TEST_COMMAND_ADD_CONTROLLER 1
#define JOYPAD_TEST_COMMAND_BUTTON_PRESS_FIRST 16
#define JOYPAD_TEST_COMMAND_BUTTON_PRESS_LAST 31
#define JOYPAD_TEST_COMMAND_BUTTON_RELEASE_FIRST 32
#define JOYPAD_TEST_COMMAND_BUTTON_RELEASE_LAST 47
#define JOYPAD_TEST_COMMAND_BUTTON_AXIS_FIRST 1000
#define JOYPAD_TEST_COMMAND_BUTTON_AXIS_LAST JOYPAD_TEST_COMMAND_BUTTON_AXIS_FIRST+MAX_AXIS*DEFAULT_MAX_PADS

typedef struct
{
char* name;
Expand Down Expand Up @@ -81,11 +91,11 @@ typedef struct
unsigned action;
unsigned param_num;
char *param_str;
} ITifJSONContext;
} JTifJSONContext;

static bool ITifJSONObjectEndHandler(void* context)
static bool JTifJSONObjectEndHandler(void* context)
{
ITifJSONContext *pCtx = (ITifJSONContext*)context;
JTifJSONContext *pCtx = (JTifJSONContext*)context;

/* Too long input is handled elsewhere, it should not lead to parse error */
if (current_test_step >= MAX_TEST_STEPS)
Expand Down Expand Up @@ -114,9 +124,9 @@ static bool ITifJSONObjectEndHandler(void* context)
return true;
}

static bool ITifJSONObjectMemberHandler(void* context, const char *pValue, size_t length)
static bool JTifJSONObjectMemberHandler(void* context, const char *pValue, size_t length)
{
ITifJSONContext *pCtx = (ITifJSONContext*)context;
JTifJSONContext *pCtx = (JTifJSONContext*)context;

/* something went wrong */
if (pCtx->current_entry_str_val)
Expand All @@ -138,9 +148,9 @@ static bool ITifJSONObjectMemberHandler(void* context, const char *pValue, size_
return true;
}

static bool ITifJSONNumberHandler(void* context, const char *pValue, size_t length)
static bool JTifJSONNumberHandler(void* context, const char *pValue, size_t length)
{
ITifJSONContext *pCtx = (ITifJSONContext*)context;
JTifJSONContext *pCtx = (JTifJSONContext*)context;

if (pCtx->current_entry_uint_val && length && !string_is_empty(pValue))
*pCtx->current_entry_uint_val = string_to_unsigned(pValue);
Expand All @@ -151,9 +161,9 @@ static bool ITifJSONNumberHandler(void* context, const char *pValue, size_t leng
return true;
}

static bool ITifJSONStringHandler(void* context, const char *pValue, size_t length)
static bool JTifJSONStringHandler(void* context, const char *pValue, size_t length)
{
ITifJSONContext *pCtx = (ITifJSONContext*)context;
JTifJSONContext *pCtx = (JTifJSONContext*)context;

if (pCtx->current_entry_str_val && length && !string_is_empty(pValue))
{
Expand All @@ -174,7 +184,7 @@ static bool ITifJSONStringHandler(void* context, const char *pValue, size_t leng
static bool input_test_file_read(const char* file_path)
{
bool success = false;
ITifJSONContext context = {0};
JTifJSONContext context = {0};
RFILE *file = NULL;
rjson_t* parser;

Expand Down Expand Up @@ -212,10 +222,10 @@ static bool input_test_file_read(const char* file_path)

/* Read file */
if (rjson_parse(parser, &context,
ITifJSONObjectMemberHandler,
ITifJSONStringHandler,
ITifJSONNumberHandler,
NULL, ITifJSONObjectEndHandler, NULL, NULL, /* object/array handlers */
JTifJSONObjectMemberHandler,
JTifJSONStringHandler,
JTifJSONNumberHandler,
NULL, JTifJSONObjectEndHandler, NULL, NULL, /* object/array handlers */
NULL, NULL) /* unused boolean/null handlers */
!= RJSON_DONE)
{
Expand Down Expand Up @@ -305,7 +315,7 @@ static void *test_joypad_init(void *data)
{
if (input_test_steps[i].frame > 0)
continue;
if (input_test_steps[i].action == 1)
if (input_test_steps[i].action == JOYPAD_TEST_COMMAND_ADD_CONTROLLER)
{
test_joypads[input_test_steps[i].param_num].name = input_test_steps[i].param_str;
test_joypad_autodetect_add(input_test_steps[i].param_num);
Expand Down Expand Up @@ -389,39 +399,57 @@ static void test_joypad_poll(void)
{
if (!input_test_steps[i].handled && curr_frame > input_test_steps[i].frame)
{
if (input_test_steps[i].action == 1)
if (input_test_steps[i].action == JOYPAD_TEST_COMMAND_ADD_CONTROLLER)
{
test_joypads[input_test_steps[i].param_num].name = input_test_steps[i].param_str;
test_joypad_autodetect_add(input_test_steps[i].param_num);
input_test_steps[i].handled = true;
}
else if(input_test_steps[i].action >= 16 && input_test_steps[i].action <= 31)
else if( input_test_steps[i].action >= JOYPAD_TEST_COMMAND_BUTTON_PRESS_FIRST &&
input_test_steps[i].action <= JOYPAD_TEST_COMMAND_BUTTON_PRESS_LAST)
{
unsigned targetpad = input_test_steps[i].action - 16;
unsigned targetpad = input_test_steps[i].action - JOYPAD_TEST_COMMAND_BUTTON_PRESS_FIRST;
test_joypads[targetpad].button_state |= input_test_steps[i].param_num;
input_test_steps[i].handled = true;
RARCH_DBG("[Test input driver]: Pressing device %d buttons %x, new state %x.\n",targetpad,input_test_steps[i].param_num,test_joypads[targetpad].button_state);
RARCH_DBG(
"[Test input driver]: Pressing device %d buttons %x, new state %x.\n",
targetpad,input_test_steps[i].param_num,test_joypads[targetpad].button_state);
}
else if(input_test_steps[i].action >= 32 && input_test_steps[i].action <= 47)
else if( input_test_steps[i].action >= JOYPAD_TEST_COMMAND_BUTTON_RELEASE_FIRST &&
input_test_steps[i].action <= JOYPAD_TEST_COMMAND_BUTTON_RELEASE_LAST)
{
unsigned targetpad = input_test_steps[i].action - 32;
unsigned targetpad = input_test_steps[i].action - JOYPAD_TEST_COMMAND_BUTTON_RELEASE_FIRST;
test_joypads[targetpad].button_state &= ~input_test_steps[i].param_num;
input_test_steps[i].handled = true;
RARCH_DBG("[Test input driver]: Releasing device %d buttons %x, new state %x.\n",targetpad,input_test_steps[i].param_num,test_joypads[targetpad].button_state);
RARCH_DBG(
"[Test input driver]: Releasing device %d buttons %x, new state %x.\n",
targetpad,input_test_steps[i].param_num,test_joypads[targetpad].button_state);
}
else if(input_test_steps[i].action >= 1000 && input_test_steps[i].action <= 1000+MAX_AXIS*DEFAULT_MAX_PADS)
else if( input_test_steps[i].action >= JOYPAD_TEST_COMMAND_BUTTON_AXIS_FIRST &&
input_test_steps[i].action <= JOYPAD_TEST_COMMAND_BUTTON_AXIS_LAST)
{
unsigned targetpad = (input_test_steps[i].action - 1000)/MAX_AXIS;
unsigned targetaxis = input_test_steps[i].action - 1000 - (targetpad*MAX_AXIS);
unsigned targetpad =
(input_test_steps[i].action - JOYPAD_TEST_COMMAND_BUTTON_AXIS_FIRST) / MAX_AXIS;
unsigned targetaxis =
input_test_steps[i].action - JOYPAD_TEST_COMMAND_BUTTON_AXIS_FIRST - (targetpad*MAX_AXIS);
if (targetpad < DEFAULT_MAX_PADS && targetaxis < MAX_AXIS)
test_joypads[targetpad].axis_state[targetaxis] = (int16_t) input_test_steps[i].param_num;
else
RARCH_WARN(
"[Test input driver]: Decoded axis outside target range: action %d pad %d axis %d.\n",
input_test_steps[i].action, targetpad, targetaxis);

input_test_steps[i].handled = true;
RARCH_DBG("[Test input driver]: Setting axis device %d axis %d value %d.\n",targetpad, targetaxis, (int16_t)input_test_steps[i].param_num);
RARCH_DBG(
"[Test input driver]: Setting axis device %d axis %d value %d.\n",
targetpad, targetaxis, (int16_t)input_test_steps[i].param_num);
}
else
{
input_test_steps[i].handled = true;
RARCH_WARN("[Test input driver]: Unrecognized action %d in step %d, skipping\n",input_test_steps[i].action,i);
RARCH_WARN(
"[Test input driver]: Unrecognized action %d in step %d, skipping\n",
input_test_steps[i].action,i);
}

}
Expand Down
5 changes: 5 additions & 0 deletions tests-other/all_binds_empty.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Config file to be used with --appendconfig
# Sets input related settings to default (or nul, in case of bindings)
# so that tests can rely on a clean startup state.
# Escape button is deliberately retained, to be able to end / abort tests.

input_exit_emulator = "escape"
input_max_users = "10"

Expand Down
10 changes: 5 additions & 5 deletions tests-other/netretropad_all_inputs.ratst
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[
{
"expected_button": 8,
"message": "Press A"
"message": "Press A (face button right)"
},
{
"expected_button": 0,
"message": "Press B"
"message": "Press B (face button bottom)"
},
{
"expected_button": 9,
"message": "Press X"
"message": "Press X (face button top)"
},
{
"expected_button": 1,
"message": "Press Y"
"message": "Press Y (face button left)"
},
{
"expected_button": 2,
Expand Down Expand Up @@ -127,4 +127,4 @@
"expected_button": 23,
"message": "Move right analog stick right fully"
}
]
]
11 changes: 10 additions & 1 deletion tests-other/testinput.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Test configuration file to be used with --appendconfig.
# Sets up joypad driver, test input file for the joypad driver,
# logging and autoconfig dir, and prevents saving.
# Usage: retroarch --appendconfig tests-other/testinput.cfg\|tests_other/all_binds_empty.cfg
# Usage with retropad test counterpart: retroarch --appendconfig tests_other/testinput.cfg\|tests_other/all_binds_empty.cfg -L netretropad tests_other/netretropad_all_inputs.ratst

input_joypad_driver = "test"
test_input_file_joypad = "tests-other/test_input_joypad.ratst"
joypad_autoconfig_dir = "tests-other/autoconf"
config_save_on_exit = "false"
frontend_log_level = "0"
libretro_log_level = "0"
log_verbosity = "true"
config_save_on_exit = "false"

0 comments on commit bed6bd1

Please sign in to comment.