Add tests for mouse configuration

This change adds a test suite for validating mouse configuration. This
only tests the logic for mouse thread enable/disable and mouse speed
calculations.
reverse-scroll
nirenjan 2022-04-28 01:54:09 -07:00
parent 3168061c99
commit 8f9ab9cefd
6 changed files with 162 additions and 15 deletions

View File

@ -100,7 +100,25 @@ EXTRA_DIST += \
daemon/test_daemon_comm.py \
daemon/tests/comm/config_args.tc
TESTS += daemon/test_daemon_comm.py
check_PROGRAMS += x52d-mouse-test
x52d_mouse_test_SOURCES = \
daemon/x52d_mouse_test.c \
daemon/x52d_mouse.c
x52d_mouse_test_CFLAGS = \
-DLOCALEDIR='"$(localedir)"' \
-I $(top_srcdir) \
-I $(top_srcdir)/libx52 \
-I $(top_srcdir)/libx52io \
-I $(top_srcdir)/lib/pinelog \
$(WARN_CFLAGS)
x52d_mouse_test_LDFLAGS = @CMOCKA_LIBS@ $(WARN_LDFLAGS)
x52d_mouse_test_LDADD = \
lib/pinelog/libpinelog.la
TESTS += \
daemon/test_daemon_comm.py \
x52d-mouse-test
if HAVE_SYSTEMD
if !IS_MAKE_DISTCHECK

View File

@ -22,7 +22,6 @@
#define MOUSE_DELAY_MIN 10000
#define MAX_MOUSE_MULT 5
volatile bool mouse_enabled = false;
volatile int mouse_delay = DEFAULT_MOUSE_DELAY;
volatile int mouse_mult = MOUSE_MULT_FACTOR;

View File

@ -12,7 +12,6 @@
#include <stdbool.h>
#include "libx52io.h"
extern volatile bool mouse_enabled;
extern volatile int mouse_delay;
extern volatile int mouse_mult;

View File

@ -0,0 +1,131 @@
/*
* Saitek X52 Pro MFD & LED driver - Mouse driver test harness
*
* Copyright (C) 2022 Nirenjan Krishnan (nirenjan@nirenjan.org)
*
* SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
*/
#include "config.h"
#include <stdio.h>
#include <stdbool.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#define PINELOG_MODULE X52D_MOD_MOUSE
#include "pinelog.h"
#include "x52d_config.h"
#include "x52d_const.h"
#include "x52d_mouse.h"
#if defined HAVE_EVDEV
/* Stub for evdev */
void x52d_mouse_evdev_thread_control(bool enabled)
{
function_called();
check_expected(enabled);
}
#endif
static void test_mouse_thread_enabled(void **state)
{
#if defined HAVE_EVDEV
expect_function_calls(x52d_mouse_evdev_thread_control, 1);
expect_value(x52d_mouse_evdev_thread_control, enabled, true);
#endif
x52d_cfg_set_Mouse_Enabled(true);
}
static void test_mouse_thread_disabled(void **state)
{
#if defined HAVE_EVDEV
expect_function_calls(x52d_mouse_evdev_thread_control, 1);
expect_value(x52d_mouse_evdev_thread_control, enabled, false);
#endif
x52d_cfg_set_Mouse_Enabled(false);
}
static void test_mouse_speed_negative(void **state)
{
int orig_mouse_delay = mouse_delay;
int orig_mouse_mult = mouse_mult;
x52d_cfg_set_Mouse_Speed(-1);
assert_int_equal(mouse_delay, orig_mouse_delay);
assert_int_equal(mouse_mult, orig_mouse_mult);
}
/* The following tests are dependent on the values in x52d_mouse.c */
static void test_mouse_speed_0(void **state)
{
x52d_cfg_set_Mouse_Speed(0);
assert_int_equal(mouse_delay, 70000);
assert_int_equal(mouse_mult, 4);
}
static void test_mouse_speed_mid_base(void **state)
{
x52d_cfg_set_Mouse_Speed(6);
assert_int_equal(mouse_delay, 40000);
assert_int_equal(mouse_mult, 4);
}
static void test_mouse_speed_max_base(void **state)
{
x52d_cfg_set_Mouse_Speed(12);
assert_int_equal(mouse_delay, 10000);
assert_int_equal(mouse_mult, 4);
}
static void test_mouse_speed_min_hyper(void **state)
{
x52d_cfg_set_Mouse_Speed(13);
assert_int_equal(mouse_delay, 10000);
assert_int_equal(mouse_mult, 5);
}
static void test_mouse_speed_mid_hyper(void **state)
{
x52d_cfg_set_Mouse_Speed(22);
assert_int_equal(mouse_delay, 10000);
assert_int_equal(mouse_mult, 14);
}
static void test_mouse_speed_max_hyper(void **state)
{
x52d_cfg_set_Mouse_Speed(32);
assert_int_equal(mouse_delay, 10000);
assert_int_equal(mouse_mult, 24);
}
static void test_mouse_speed_above_max(void **state)
{
int orig_mouse_delay = mouse_delay;
int orig_mouse_mult = mouse_mult;
x52d_cfg_set_Mouse_Speed(33);
assert_int_equal(mouse_delay, orig_mouse_delay);
assert_int_equal(mouse_mult, orig_mouse_mult);
}
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_mouse_thread_enabled),
cmocka_unit_test(test_mouse_thread_disabled),
cmocka_unit_test(test_mouse_speed_negative),
cmocka_unit_test(test_mouse_speed_0),
cmocka_unit_test(test_mouse_speed_mid_base),
cmocka_unit_test(test_mouse_speed_max_base),
cmocka_unit_test(test_mouse_speed_min_hyper),
cmocka_unit_test(test_mouse_speed_mid_hyper),
cmocka_unit_test(test_mouse_speed_max_hyper),
cmocka_unit_test(test_mouse_speed_above_max),
};
int main(void)
{
cmocka_set_message_output(CM_OUTPUT_TAP);
cmocka_run_group_tests(tests, NULL, NULL);
}

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: libx52 0.2.3\n"
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
"POT-Creation-Date: 2022-02-11 13:23-0800\n"
"POT-Creation-Date: 2022-04-28 01:49-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -142,11 +142,11 @@ msgstr ""
msgid "Unknown LED state %d"
msgstr ""
#: libx52/x52_stringify.c:47 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:32
#: libx52/x52_stringify.c:47 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:31
msgid "off"
msgstr ""
#: libx52/x52_stringify.c:48 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:32
#: libx52/x52_stringify.c:48 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:31
msgid "on"
msgstr ""
@ -810,17 +810,17 @@ msgstr ""
msgid "Shutting down X52 I/O driver thread"
msgstr ""
#: daemon/x52d_mouse.c:31
#: daemon/x52d_mouse.c:30
#, c-format
msgid "Setting mouse enable to %s"
msgstr ""
#: daemon/x52d_mouse.c:47
#: daemon/x52d_mouse.c:46
#, c-format
msgid "Ignoring mouse speed %d outside supported range (0-%d)"
msgstr ""
#: daemon/x52d_mouse.c:59
#: daemon/x52d_mouse.c:58
#, c-format
msgid "Setting mouse speed to %d (delay %d ms, multiplier %f)"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: libx52 0.2.3\n"
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
"POT-Creation-Date: 2022-02-11 13:23-0800\n"
"POT-Creation-Date: 2022-04-28 01:49-0700\n"
"PO-Revision-Date: 2021-11-04 15:35-0700\n"
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
"Language-Team: Dummy Language for testing i18n\n"
@ -142,11 +142,11 @@ msgstr "YYay-MMay-DDay"
msgid "Unknown LED state %d"
msgstr "Unknownay EDLay atestay %d"
#: libx52/x52_stringify.c:47 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:32
#: libx52/x52_stringify.c:47 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:31
msgid "off"
msgstr "offay"
#: libx52/x52_stringify.c:48 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:32
#: libx52/x52_stringify.c:48 daemon/x52d_clock.c:29 daemon/x52d_mouse.c:31
msgid "on"
msgstr "onay"
@ -862,17 +862,17 @@ msgstr "Erroray %d initializingay I/O iverdray eadthray: %s"
msgid "Shutting down X52 I/O driver thread"
msgstr "Uttingshay ownday X52 I/O iverdray eadthray"
#: daemon/x52d_mouse.c:31
#: daemon/x52d_mouse.c:30
#, c-format
msgid "Setting mouse enable to %s"
msgstr "Ettingsay ousemay enableay otay %s"
#: daemon/x52d_mouse.c:47
#: daemon/x52d_mouse.c:46
#, c-format
msgid "Ignoring mouse speed %d outside supported range (0-%d)"
msgstr "Ignoringay ousemay eedspay %d outsideay upportedsay angeray (0-%d)"
#: daemon/x52d_mouse.c:59
#: daemon/x52d_mouse.c:58
#, c-format
msgid "Setting mouse speed to %d (delay %d ms, multiplier %f)"
msgstr "Ettingsay ousemay eedspay otay %d (elayday %d ms, ultipliermay %f)"