Merge branch 'sanei-usb-testing-mode' into 'master'

sanei: Support capture and replay of USB data for testing

See merge request sane-project/backends!55
merge-requests/92/head
Olaf Meeuwissen 2019-08-08 14:01:30 +00:00
commit 1be824f2c5
9 zmienionych plików z 1808 dodań i 25 usunięć

Wyświetl plik

@ -219,7 +219,7 @@ lib_LTLIBRARIES = libsane.la
sanelibdir = $(libdir)/sane
sanelib_LTLIBRARIES = $(BACKEND_LIBS_ENABLED) libsane-dll.la
COMMON_LIBS = ../lib/liblib.la
COMMON_LIBS = ../lib/liblib.la $(XML_LIBS)
# Each backend should define a convenience library that compiles
# all related files within backend directory. General guideline
@ -1110,8 +1110,10 @@ EXTRA_DIST += xerox_mfp.conf.in
libdll_preload_la_SOURCES = dll.c
libdll_preload_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=dll -DENABLE_PRELOAD
libdll_preload_la_LIBADD = ../sanei/sanei_usb.lo $(USB_LIBS) $(XML_LIBS)
libdll_la_SOURCES = dll.c
libdll_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=dll
libdll_la_LIBADD = ../sanei/sanei_usb.lo $(USB_LIBS) $(XML_LIBS)
BUILT_SOURCES = dll-preload.h
CLEANFILES += dll-preload.h
@ -1142,13 +1144,13 @@ EXTRA_DIST += dll.aliases
# what backends are preloaded. It should include what is needed by
# those backends that are actually preloaded.
if preloadable_backends_enabled
PRELOADABLE_BACKENDS_LIBS = ../sanei/sanei_config2.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_pv8630.lo ../sanei/sanei_pp.lo ../sanei/sanei_thread.lo ../sanei/sanei_lm983x.lo ../sanei/sanei_access.lo ../sanei/sanei_net.lo ../sanei/sanei_wire.lo ../sanei/sanei_codec_bin.lo ../sanei/sanei_pa4s2.lo ../sanei/sanei_ab306.lo ../sanei/sanei_pio.lo ../sanei/sanei_tcp.lo ../sanei/sanei_udp.lo ../sanei/sanei_magic.lo $(LIBV4L_LIBS) $(MATH_LIB) $(IEEE1284_LIBS) $(TIFF_LIBS) $(JPEG_LIBS) $(GPHOTO2_LIBS) $(SOCKET_LIBS) $(USB_LIBS) $(AVAHI_LIBS) $(SCSI_LIBS) $(PTHREAD_LIBS) $(RESMGR_LIBS)
PRELOADABLE_BACKENDS_LIBS = ../sanei/sanei_config2.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_pv8630.lo ../sanei/sanei_pp.lo ../sanei/sanei_thread.lo ../sanei/sanei_lm983x.lo ../sanei/sanei_access.lo ../sanei/sanei_net.lo ../sanei/sanei_wire.lo ../sanei/sanei_codec_bin.lo ../sanei/sanei_pa4s2.lo ../sanei/sanei_ab306.lo ../sanei/sanei_pio.lo ../sanei/sanei_tcp.lo ../sanei/sanei_udp.lo ../sanei/sanei_magic.lo $(LIBV4L_LIBS) $(MATH_LIB) $(IEEE1284_LIBS) $(TIFF_LIBS) $(JPEG_LIBS) $(GPHOTO2_LIBS) $(SOCKET_LIBS) $(USB_LIBS) $(AVAHI_LIBS) $(SCSI_LIBS) $(PTHREAD_LIBS) $(RESMGR_LIBS) $(XML_LIBS)
PRELOADABLE_BACKENDS_DEPS = ../sanei/sanei_config2.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_pv8630.lo ../sanei/sanei_pp.lo ../sanei/sanei_thread.lo ../sanei/sanei_lm983x.lo ../sanei/sanei_access.lo ../sanei/sanei_net.lo ../sanei/sanei_wire.lo ../sanei/sanei_codec_bin.lo ../sanei/sanei_pa4s2.lo ../sanei/sanei_ab306.lo ../sanei/sanei_pio.lo ../sanei/sanei_tcp.lo ../sanei/sanei_udp.lo ../sanei/sanei_magic.lo $(SANEI_SANEI_JPEG_LO)
endif
nodist_libsane_la_SOURCES = dll-s.c
libsane_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=dll
libsane_la_LDFLAGS = $(DIST_LIBS_LDFLAGS)
libsane_la_LIBADD = $(COMMON_LIBS) $(PRELOADABLE_BACKENDS_ENABLED) libdll_preload.la sane_strstatus.lo ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo $(PRELOADABLE_BACKENDS_LIBS) $(DL_LIBS)
libsane_la_LIBADD = $(COMMON_LIBS) $(PRELOADABLE_BACKENDS_ENABLED) libdll_preload.la sane_strstatus.lo ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo $(PRELOADABLE_BACKENDS_LIBS) $(DL_LIBS) $(XML_LIBS)
# WARNING: Automake is getting this wrong so have to do it ourselves.
libsane_la_DEPENDENCIES = $(COMMON_LIBS) $(PRELOADABLE_BACKENDS_ENABLED) libdll_preload.la sane_strstatus.lo ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo $(PRELOADABLE_BACKENDS_DEPS)

Wyświetl plik

@ -139,6 +139,8 @@ posix_dlsym (void *handle, const char *func)
#define DLL_CONFIG_FILE "dll.conf"
#define DLL_ALIASES_FILE "dll.aliases"
#include "../include/sane/sanei_usb.h"
enum SANE_Ops
{
OP_INIT = 0,
@ -1177,18 +1179,73 @@ sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle)
}
dev_name = strchr (full_name, ':');
int is_fakeusb = 0, is_fakeusbdev = 0, is_fakeusbout = 0;
if (dev_name)
{
be_name = strndup(full_name, dev_name - full_name);
++dev_name; /* skip colon */
is_fakeusb = strncmp(full_name, "fakeusb", dev_name - full_name) == 0 &&
dev_name - full_name == 7;
is_fakeusbdev = strncmp(full_name, "fakeusbdev", dev_name - full_name) == 0 &&
dev_name - full_name == 10;
is_fakeusbout = strncmp(full_name, "fakeusbout", dev_name - full_name) == 0 &&
dev_name - full_name == 10;
}
if (is_fakeusb || is_fakeusbdev)
{
++dev_name; // skip colon
status = sanei_usb_testing_enable_replay(dev_name, is_fakeusbdev);
if (status != SANE_STATUS_GOOD)
return status;
be_name = sanei_usb_testing_get_backend();
if (be_name == NULL)
{
DBG (0, "%s: unknown backend for testing\n", __func__);
return SANE_STATUS_ACCESS_DENIED;
}
}
else
{
/* if no colon interpret full_name as the backend name; an empty
backend device name will cause us to open the first device of
that backend. */
be_name = strdup(full_name);
dev_name = "";
char* fakeusbout_path = NULL;
if (is_fakeusbout)
{
++dev_name; // skip colon
const char* path_end = strchr(dev_name, ':');
if (path_end == NULL)
{
DBG (0, "%s: the device name does not contain path\n", __func__);
return SANE_STATUS_INVAL;
}
fakeusbout_path = strndup(dev_name, path_end - dev_name);
full_name = path_end + 1; // skip colon
dev_name = strchr(full_name, ':');
}
if (dev_name)
{
be_name = strndup(full_name, dev_name - full_name);
++dev_name; /* skip colon */
}
else
{
/* if no colon interpret full_name as the backend name; an empty
backend device name will cause us to open the first device of
that backend. */
be_name = strdup(full_name);
dev_name = "";
}
if (is_fakeusbout)
{
status = sanei_usb_testing_enable_record(fakeusbout_path, be_name);
free(fakeusbout_path);
if (status != SANE_STATUS_GOOD)
return status;
}
}
if (!be_name)

Wyświetl plik

@ -1972,6 +1972,8 @@ sanei_genesys_load_lut (unsigned char * lut,
void sanei_genesys_usleep(unsigned int useconds)
{
if (sanei_usb_is_replay_mode_enabled() == SANE_TRUE)
return;
usleep(useconds);
}

Wyświetl plik

@ -430,6 +430,24 @@ AS_IF([test xyes = "x$with_usb" && test xyes != "x$have_usb"],
])
AM_CONDITIONAL([have_usblib], [test x != "x$USB_LIBS"])
dnl ******************************************************************
dnl Check for USB record/replay support
dnl ******************************************************************
AC_ARG_WITH(usb_record_replay,
AS_HELP_STRING([--with-usb-record-replay],
[enable USB record and replay to XML files @<:@default=yes@:>@]))
if test "x$with_usb_record_replay" != "xno"; then
PKG_CHECK_MODULES([XML], [libxml-2.0], have_libxml=yes, have_libxml=no)
if test "x$have_libxml" = xyes; then
AC_DEFINE(WITH_USB_RECORD_REPLAY, 1, [define if USB record replay is enabled])
else
if test "x$with_usb_record_replay" = xyes; then
AC_MSG_ERROR([USB record and replay support was requested but libxml-2.0 was not found])
fi
fi
fi
dnl ************
dnl SCSI Support
dnl ************

Wyświetl plik

@ -180,6 +180,50 @@ struct sanei_usb_dev_descriptor
SANE_Byte max_packet_size;
};
/** Initialize sanei_usb for replay testing.
Initializes sanei_usb for testing by mocking whole USB stack. This function
must be called before sanei_usb_init().
The sanei_usb subsystem also implements a "development mode". It modifies
the XML data file with the actual commands of the test run and attemps to
proceed testing until a mismatching input command is found for which
input data is required.
A <known_commands_end/> node in the data XML file will cause sanei_usb not
to continue to the subsequent command in the XML file and instead it will
prepend all output commands before that node before an output command is
encountered.
@param path Path to the XML data file.
@param development_mode Enables development mode.
*/
extern SANE_Status sanei_usb_testing_enable_replay(SANE_String_Const path,
int development_mode);
/** Initialize sanei_usb for recording.
*
* Initializes sanei_usb for recording communication with the scanner. This
* function must be called before sanei_usb_init().
*
* @param path Path to the XML data file.
* @param be_name The name of the backend to enable recording for.
*/
extern SANE_Status sanei_usb_testing_enable_record(SANE_String_Const path,
SANE_String_Const be_name);
/** Returns backend name for testing.
*
* Returns backend name for the file registered in sanei_usb_testing_enable.
* The caller is responsible for freeing it.
*/
extern SANE_String sanei_usb_testing_get_backend();
/** Returns SANE_TRUE if replay testing mode is enabled, i.e. whether we are working with fake
* scan data.
*/
extern SANE_Bool sanei_usb_is_replay_mode_enabled();
/** Initialize sanei_usb.
*
* Call this before any other sanei_usb function.

Wyświetl plik

@ -5,7 +5,7 @@
## included LICENSE file for license information.
AM_CPPFLAGS += -I. -I$(srcdir) -I$(top_builddir)/include \
-I$(top_srcdir)/include $(USB_CFLAGS)
-I$(top_srcdir)/include $(USB_CFLAGS) $(XML_CFLAGS)
noinst_LTLIBRARIES = libsanei.la

Plik diff jest za duży Load Diff

Wyświetl plik

@ -10,12 +10,14 @@ EXTRA_DIST = data/boolean.conf data/empty.conf data/fixed.conf data/int.conf \
data/wrong-fixed.conf data/wrong-range.conf \
data/wrong-string-list.conf
TEST_LDADD = ../../sanei/libsanei.la ../../lib/liblib.la $(MATH_LIB) $(USB_LIBS) $(PTHREAD_LIBS)
TEST_LDADD = ../../sanei/libsanei.la ../../lib/liblib.la \
$(MATH_LIB) $(USB_LIBS) $(XML_LIBS) $(PTHREAD_LIBS)
check_PROGRAMS = sanei_usb_test test_wire sanei_check_test sanei_config_test sanei_constrain_test
TESTS = $(check_PROGRAMS)
AM_CPPFLAGS += -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include $(USB_CFLAGS)
AM_CPPFLAGS += -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include \
$(USB_CFLAGS) $(XML_CFLAGS)
sanei_constrain_test_SOURCES = sanei_constrain_test.c
sanei_constrain_test_LDADD = $(TEST_LDADD)

Wyświetl plik

@ -42,7 +42,7 @@ if have_usblib
sane_find_scanner_SOURCES += check-usb-chip.c
endif
sane_find_scanner_LDADD = ../sanei/libsanei.la ../lib/liblib.la \
$(USB_LIBS) $(IEEE1284_LIBS) $(SCSI_LIBS) \
$(USB_LIBS) $(IEEE1284_LIBS) $(SCSI_LIBS) $(XML_LIBS) \
../backend/sane_strstatus.lo
gamma4scanimage_SOURCES = gamma4scanimage.c