tests: Ensure that we don't break ABI with expected TODv1 structures

We can check whether each relevant structure element has not changed and
that the supported enum and flag values didn't change value.
This commit is contained in:
Marco Trevisan (Treviño)
2021-04-13 22:09:09 +02:00
parent e5e999de2c
commit 58756ab62e
7 changed files with 611 additions and 0 deletions
+14
View File
@@ -242,11 +242,24 @@ if get_option('tod')
install: false
)
fp_todv1_enums = gnome.mkenums_simple('fp-todv1-enums',
source_dir: 'tod-drivers',
sources: [
'tod-drivers/base-fp-device.h',
'tod-drivers/base-fp-print.h',
'tod-drivers/base-fpi-device.h',
'tod-drivers/base-fpi-image-device.h',
'tod-drivers/base-fpi-usb.h',
],
install_header: false)
test_utils_tod = static_library('fprint-test-utils-tod',
sources: [
'test-utils.c',
'test-utils-tod.c',
fp_todv1_enums,
],
include_directories: 'tod-drivers',
dependencies: libfprint_private_dep,
install: false)
@@ -254,6 +267,7 @@ if get_option('tod')
'fp-context-tod',
'fp-device-tod',
'fpi-device',
'fp-todv1-types',
]
tod_dirs = {
+228
View File
@@ -0,0 +1,228 @@
/*
* FpDevice Unit tests
* Copyright (C) 2021 Marco Trevisan <marco.trevisan@canonical.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <libfprint/fprint.h>
#include "drivers_api.h"
#include "fp-todv1-enums.h"
#include "tod-drivers/base-fp-device.h"
#include "tod-drivers/base-fp-print.h"
#include "tod-drivers/base-fpi-device.h"
#include "tod-drivers/base-fpi-image-device.h"
#include "tod-drivers/base-fpi-usb.h"
static void
check_enum_compatibility (GType old_type, GType current_type)
{
g_autoptr(GEnumClass) old_class = g_type_class_ref (old_type);
g_autoptr(GEnumClass) current_class = g_type_class_ref (current_type);
int i;
g_debug ("Checking Enum %s", g_type_name (current_type));
for (i = 0; g_enum_get_value (old_class, i); ++i)
{
GEnumValue *old_value = g_enum_get_value (old_class, i);
GEnumValue *current_value = g_enum_get_value_by_nick (current_class,
old_value->value_nick);
g_debug (" .. %s", old_value->value_nick);
g_assert_nonnull (current_value);
g_assert_cmpuint (old_value->value, ==, current_value->value);
}
}
static void
check_flags_compatibility (GType old_type, GType current_type)
{
g_autoptr(GFlagsClass) old_class = g_type_class_ref (old_type);
g_autoptr(GFlagsClass) current_class = g_type_class_ref (current_type);
int i;
g_debug ("Checking Flags %s", g_type_name (current_type));
for (i = 0; i < old_class->n_values; ++i)
{
GFlagsValue *old_value = &old_class->values[i];
GFlagsValue *current_value = g_flags_get_value_by_nick (current_class,
old_value->value_nick);
g_debug (" .. %s", old_value->value_nick);
g_assert_nonnull (current_value);
g_assert_cmpuint (old_value->value, ==, current_value->value);
}
}
static void
check_compatiblity_auto (GType old_type, GType current_type)
{
if (G_TYPE_IS_ENUM (old_type))
return check_enum_compatibility (old_type, current_type);
if (G_TYPE_IS_FLAGS (old_type))
return check_flags_compatibility (old_type, current_type);
g_assert_not_reached ();
}
#define check_type_compatibility(type) \
check_compatiblity_auto (type ## _TOD_V1, type)
#define check_struct_size(type) \
g_debug ("Checking " # type " size"); \
g_assert_cmpuint (sizeof (type ## TODV1), ==, sizeof (type))
#define check_struct_member(type, member) \
g_debug ("Checking " # type "'s " # member " offset"); \
g_assert_cmpuint (G_STRUCT_OFFSET (type ## TODV1, member), ==, G_STRUCT_OFFSET (type, member))
static void
test_device_type (void)
{
check_struct_size (FpIdEntry);
check_struct_size (FpDeviceClass);
check_struct_member (FpIdEntry, virtual_envvar);
check_struct_member (FpIdEntry, driver_data);
check_struct_member (FpDeviceClass, id);
check_struct_member (FpDeviceClass, full_name);
check_struct_member (FpDeviceClass, type);
check_struct_member (FpDeviceClass, id_table);
check_struct_member (FpDeviceClass, nr_enroll_stages);
check_struct_member (FpDeviceClass, scan_type);
check_struct_member (FpDeviceClass, usb_discover);
check_struct_member (FpDeviceClass, probe);
check_struct_member (FpDeviceClass, open);
check_struct_member (FpDeviceClass, close);
check_struct_member (FpDeviceClass, enroll);
check_struct_member (FpDeviceClass, verify);
check_struct_member (FpDeviceClass, identify);
check_struct_member (FpDeviceClass, capture);
check_struct_member (FpDeviceClass, list);
check_struct_member (FpDeviceClass, delete);
check_struct_member (FpDeviceClass, cancel);
}
static void
test_image_device_private (void)
{
check_struct_size (FpImage);
check_struct_size (FpImageDeviceClass);
check_struct_member (FpImageDeviceClass, bz3_threshold);
check_struct_member (FpImageDeviceClass, img_width);
check_struct_member (FpImageDeviceClass, img_height);
check_struct_member (FpImageDeviceClass, img_open);
check_struct_member (FpImageDeviceClass, img_close);
check_struct_member (FpImageDeviceClass, activate);
check_struct_member (FpImageDeviceClass, change_state);
check_struct_member (FpImageDeviceClass, deactivate);
}
static void
test_usb_private (void)
{
check_struct_size (FpiUsbTransfer);
check_struct_member (FpiUsbTransfer, device);
check_struct_member (FpiUsbTransfer, ssm);
check_struct_member (FpiUsbTransfer, length);
check_struct_member (FpiUsbTransfer, actual_length);
check_struct_member (FpiUsbTransfer, buffer);
check_struct_member (FpiUsbTransfer, ref_count);
check_struct_member (FpiUsbTransfer, type);
check_struct_member (FpiUsbTransfer, endpoint);
check_struct_member (FpiUsbTransfer, direction);
check_struct_member (FpiUsbTransfer, request_type);
check_struct_member (FpiUsbTransfer, recipient);
check_struct_member (FpiUsbTransfer, request);
check_struct_member (FpiUsbTransfer, value);
check_struct_member (FpiUsbTransfer, idx);
check_struct_member (FpiUsbTransfer, short_is_error);
check_struct_member (FpiUsbTransfer, user_data);
check_struct_member (FpiUsbTransfer, callback);
check_struct_member (FpiUsbTransfer, free_buffer);
}
static void
test_device_public_enums (void)
{
check_type_compatibility (FP_TYPE_DEVICE_TYPE);
check_type_compatibility (FP_TYPE_SCAN_TYPE);
check_type_compatibility (FP_TYPE_DEVICE_RETRY);
check_type_compatibility (FP_TYPE_DEVICE_ERROR);
}
static void
test_device_private_enums (void)
{
check_type_compatibility (FPI_TYPE_DEVICE_ACTION);
}
static void
test_print_public_enums (void)
{
check_type_compatibility (FP_TYPE_FINGER);
check_type_compatibility (FP_TYPE_FINGER_STATUS_FLAGS);
}
static void
test_print_private_enums (void)
{
check_type_compatibility (FPI_TYPE_PRINT_TYPE);
check_type_compatibility (FPI_TYPE_MATCH_RESULT);
}
static void
test_image_device_enums (void)
{
check_type_compatibility (FPI_TYPE_IMAGE_FLAGS);
check_type_compatibility (FPI_TYPE_IMAGE_DEVICE_STATE);
}
static void
test_usb_enums (void)
{
check_type_compatibility (FPI_TYPE_TRANSFER_TYPE);
}
int
main (int argc, char *argv[])
{
if (!strstr (g_getenv ("FP_TOD_TEST_DRIVER_NAME"), "v1"))
return 77;
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/type/device/private", test_device_type);
g_test_add_func ("/type/device/enums", test_device_public_enums);
g_test_add_func ("/type/device/private/enums", test_device_private_enums);
g_test_add_func ("/type/print/enums", test_print_public_enums);
g_test_add_func ("/type/print/private/enums", test_print_private_enums);
g_test_add_func ("/type/image-device/private", test_image_device_private);
g_test_add_func ("/type/image-device/enums", test_image_device_enums);
g_test_add_func ("/type/usb/private", test_usb_private);
g_test_add_func ("/type/usb/enums", test_usb_enums);
return g_test_run ();
}
+51
View File
@@ -0,0 +1,51 @@
/*
* FpDevice - A fingerprint reader device
* Copyright (C) 2021 Marco Trevisan <marco.trevisan@canonical.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
typedef struct _FpDevice FpDevice;
typedef enum {
FP_DEVICE_TYPE_TODV1_VIRTUAL,
FP_DEVICE_TYPE_TODV1_USB,
} FpDeviceTypeTODV1;
typedef enum {
FP_SCAN_TYPE_TODV1_SWIPE,
FP_SCAN_TYPE_TODV1_PRESS,
} FpScanTypeTODV1;
typedef enum {
FP_DEVICE_RETRY_TODV1_GENERAL,
FP_DEVICE_RETRY_TODV1_TOO_SHORT,
FP_DEVICE_RETRY_TODV1_CENTER_FINGER,
FP_DEVICE_RETRY_TODV1_REMOVE_FINGER,
} FpDeviceRetryTODV1;
typedef enum {
FP_DEVICE_ERROR_TODV1_GENERAL,
FP_DEVICE_ERROR_TODV1_NOT_SUPPORTED,
FP_DEVICE_ERROR_TODV1_NOT_OPEN,
FP_DEVICE_ERROR_TODV1_ALREADY_OPEN,
FP_DEVICE_ERROR_TODV1_BUSY,
FP_DEVICE_ERROR_TODV1_PROTO,
FP_DEVICE_ERROR_TODV1_DATA_INVALID,
FP_DEVICE_ERROR_TODV1_DATA_NOT_FOUND,
FP_DEVICE_ERROR_TODV1_DATA_FULL,
} FpDeviceErrorTODV1;
+57
View File
@@ -0,0 +1,57 @@
/*
* FpDevice - A fingerprint reader device
* Copyright (C) 2021 Marco Trevisan <marco.trevisan@canonical.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
typedef enum {
FP_FINGER_TODV1_UNKNOWN = 0,
FP_FINGER_TODV1_LEFT_THUMB,
FP_FINGER_TODV1_LEFT_INDEX,
FP_FINGER_TODV1_LEFT_MIDDLE,
FP_FINGER_TODV1_LEFT_RING,
FP_FINGER_TODV1_LEFT_LITTLE,
FP_FINGER_TODV1_RIGHT_THUMB,
FP_FINGER_TODV1_RIGHT_INDEX,
FP_FINGER_TODV1_RIGHT_MIDDLE,
FP_FINGER_TODV1_RIGHT_RING,
FP_FINGER_TODV1_RIGHT_LITTLE,
FP_FINGER_TODV1_FIRST = FP_FINGER_TODV1_LEFT_THUMB,
FP_FINGER_TODV1_LAST = FP_FINGER_TODV1_RIGHT_LITTLE,
} FpFingerTODV1;
typedef enum {
FP_FINGER_STATUS_TODV1_NONE = 0,
FP_FINGER_STATUS_TODV1_NEEDED = 1 << 0,
FP_FINGER_STATUS_TODV1_PRESENT = 1 << 1,
} FpFingerStatusFlagsTODV1;
/* Private flags */
typedef enum {
FPI_PRINT_TODV1_UNDEFINED = 0,
FPI_PRINT_TODV1_RAW,
FPI_PRINT_TODV1_NBIS,
} FpiPrintTypeTODV1;
typedef enum {
FPI_MATCH_TODV1_ERROR = -1,
FPI_MATCH_TODV1_FAIL,
FPI_MATCH_TODV1_SUCCESS,
} FpiMatchResultTODV1;
+97
View File
@@ -0,0 +1,97 @@
/*
* FpDevice - A fingerprint reader device
* Copyright (C) 2021 Marco Trevisan <marco.trevisan@canonical.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <glib.h>
#include <glib-object.h>
#include "base-fp-device.h"
typedef struct _GUsbDevice GUsbDevice;
typedef struct _FpIdEntryTODV1 FpIdEntryTODV1;
struct _FpIdEntryTODV1
{
union
{
struct
{
guint pid;
guint vid;
};
const gchar *virtual_envvar;
};
guint64 driver_data;
/*< private >*/
/* padding for future expansion */
gpointer _padding_dummy[16];
};
struct _FpDeviceClassTODV1
{
/*< private >*/
GObjectClass parent_class;
/*< public >*/
/* Static information about the driver. */
const gchar *id;
const gchar *full_name;
FpDeviceTypeTODV1 type;
const FpIdEntryTODV1 *id_table;
/* Defaults for device properties */
gint nr_enroll_stages;
FpScanTypeTODV1 scan_type;
/* Callbacks */
gint (*usb_discover) (GUsbDevice *usb_device);
void (*probe) (FpDevice *device);
void (*open) (FpDevice *device);
void (*close) (FpDevice *device);
void (*enroll) (FpDevice *device);
void (*verify) (FpDevice *device);
void (*identify) (FpDevice *device);
void (*capture) (FpDevice *device);
void (*list) (FpDevice *device);
void (*delete) (FpDevice * device);
void (*cancel) (FpDevice *device);
/*< private >*/
/* padding for future expansion */
gpointer _padding_dummy[32];
};
typedef struct _FpDeviceClassTODV1 FpDeviceClassTODV1;
typedef enum {
FPI_DEVICE_ACTION_TODV1_NONE = 0,
FPI_DEVICE_ACTION_TODV1_PROBE,
FPI_DEVICE_ACTION_TODV1_OPEN,
FPI_DEVICE_ACTION_TODV1_CLOSE,
FPI_DEVICE_ACTION_TODV1_ENROLL,
FPI_DEVICE_ACTION_TODV1_VERIFY,
FPI_DEVICE_ACTION_TODV1_IDENTIFY,
FPI_DEVICE_ACTION_TODV1_CAPTURE,
FPI_DEVICE_ACTION_TODV1_LIST,
FPI_DEVICE_ACTION_TODV1_DELETE,
} FpiDeviceActionTODV1;
+83
View File
@@ -0,0 +1,83 @@
/*
* FpImageDevice - An image based fingerprint reader device
* Copyright (C) 2021 Marco Trevisan <marco.trevisan@canonical.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include "base-fpi-device.h"
typedef struct _FpImageDevice FpImageDevice;
typedef enum {
FPI_IMAGE_DEVICE_STATE_TODV1_INACTIVE,
FPI_IMAGE_DEVICE_STATE_TODV1_AWAIT_FINGER_ON,
FPI_IMAGE_DEVICE_STATE_TODV1_CAPTURE,
FPI_IMAGE_DEVICE_STATE_TODV1_AWAIT_FINGER_OFF,
} FpiImageDeviceStateTODV1;
typedef struct _FpImageDeviceClassTODV1
{
FpDeviceClassTODV1 parent_class;
gint bz3_threshold;
gint img_width;
gint img_height;
void (*img_open)(FpImageDevice *dev);
void (*img_close)(FpImageDevice *dev);
void (*activate)(FpImageDevice *dev);
void (*change_state)(FpImageDevice *dev,
FpiImageDeviceStateTODV1 state);
void (*deactivate)(FpImageDevice *dev);
/*< private >*/
/* padding for future expansion */
gpointer _padding_dummy[32];
} FpImageDeviceClassTODV1;
/* fpi-image */
typedef enum {
FPI_IMAGE_TODV1_V_FLIPPED = 1 << 0,
FPI_IMAGE_TODV1_H_FLIPPED = 1 << 1,
FPI_IMAGE_TODV1_COLORS_INVERTED = 1 << 2,
FPI_IMAGE_TODV1_PARTIAL = 1 << 3,
} FpiImageFlagsTODV1;
typedef struct _FpImageTODV1
{
/*< private >*/
GObject parent;
/*< public >*/
guint width;
guint height;
gdouble ppmm;
FpiImageFlagsTODV1 flags;
/*< private >*/
guint8 *data;
guint8 *binarized;
GPtrArray *minutiae;
guint ref_count;
gpointer _padding_dummy[32];
} FpImageTODV1;
+81
View File
@@ -0,0 +1,81 @@
/*
* FpDevice - A fingerprint reader device
* Copyright (C) 2021 Marco Trevisan <marco.trevisan@canonical.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <gusb.h>
#include "base-fpi-device.h"
typedef struct _FpiUsbTransferTODV1 FpiUsbTransferTODV1;
typedef struct _FpiSsm FpiSsm;
typedef void (*FpiUsbTransferCallbackTODV1)(FpiUsbTransferTODV1 *transfer,
FpDevice *dev,
gpointer user_data,
GError *error);
typedef enum {
FP_TRANSFER_TODV1_NONE = -1,
FP_TRANSFER_TODV1_CONTROL = 0,
FP_TRANSFER_TODV1_BULK = 2,
FP_TRANSFER_TODV1_INTERRUPT = 3,
} FpiTransferTypeTODV1;
struct _FpiUsbTransferTODV1
{
/*< public >*/
FpDevice *device;
FpiSsm *ssm;
gssize length;
gssize actual_length;
guchar *buffer;
/*< private >*/
guint ref_count;
/* USB Transfer information */
FpiTransferTypeTODV1 type;
guint8 endpoint;
/* Control Transfer options */
GUsbDeviceDirection direction;
GUsbDeviceRequestType request_type;
GUsbDeviceRecipient recipient;
guint8 request;
guint16 value;
guint16 idx;
/* Flags */
gboolean short_is_error;
/* Callbacks */
gpointer user_data;
FpiUsbTransferCallbackTODV1 callback;
/* Data free function */
GDestroyNotify free_buffer;
/*< private >*/
/* padding for future expansion */
gpointer _padding_dummy[32];
};