mirror of
https://gitlab.freedesktop.org/libfprint/libfprint.git
synced 2026-06-11 18:38:07 +00:00
tests: Add versions check on TOD drivers based on their IDs
Recompile tod drivers using libfprint-tod-test-drivers project [1] so that we don't have to reorder the private driver structure, plus use a versioned driver ID and parse it to check whether a feature is supported for such TOD test driver. https://gitlab.freedesktop.org/3v1n0/libfprint-tod-test-drivers
This commit is contained in:
+120
-43
@@ -46,24 +46,101 @@ fpt_context_device_driver_get_type (void)
|
||||
return G_TYPE_FROM_CLASS (FP_DEVICE_GET_CLASS (tctx->device));
|
||||
}
|
||||
|
||||
static int
|
||||
tod_get_version (FpDeviceClass *device_class,
|
||||
const char **sub_version)
|
||||
{
|
||||
g_autofree char *tod_version = NULL;
|
||||
const char *tod_version_info;
|
||||
const char *tod_subversion_info;
|
||||
|
||||
g_debug ("Getting TOD version for driver '%s'", device_class->id);
|
||||
g_assert_true (g_str_has_prefix (device_class->id, "fake_test_dev_tod"));
|
||||
|
||||
tod_version_info = device_class->id + sizeof ("fake_test_dev_tod");
|
||||
g_debug ("Tod version info is '%s'", tod_version_info);
|
||||
g_assert (*tod_version_info != '\0');
|
||||
|
||||
if (sub_version)
|
||||
*sub_version = NULL;
|
||||
|
||||
if (g_str_equal (tod_version_info, "current"))
|
||||
{
|
||||
*sub_version = TOD_CURRENT_SUBVERSION;
|
||||
return TOD_CURRENT_VERSION;
|
||||
}
|
||||
|
||||
g_assert_true (g_str_has_prefix (device_class->id, "fake_test_dev_tod_v"));
|
||||
|
||||
tod_version_info = device_class->id + sizeof ("fake_test_dev_tod_v") - 1;
|
||||
tod_subversion_info = strchr (tod_version_info, '+');
|
||||
g_assert_nonnull (tod_subversion_info);
|
||||
g_assert (*tod_subversion_info != '\0');
|
||||
|
||||
tod_version = g_strndup (tod_version_info,
|
||||
tod_subversion_info - tod_version_info);
|
||||
tod_subversion_info += 1;
|
||||
|
||||
g_debug ("Tod version is '%s', subversion '%s'",
|
||||
tod_version, tod_subversion_info);
|
||||
|
||||
g_assert_nonnull (tod_version);
|
||||
g_assert (*tod_version != '\0');
|
||||
g_assert (*tod_subversion_info != '\0');
|
||||
|
||||
if (sub_version)
|
||||
*sub_version = tod_subversion_info;
|
||||
|
||||
return atoi (tod_version);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static gboolean
|
||||
tod_is_v1_class (FpDeviceClass *device_class)
|
||||
tod_check_version (FpDeviceClass *device_class,
|
||||
int tod_version,
|
||||
const char *tod_subversion)
|
||||
{
|
||||
#ifdef TEST_TOD_DRIVER
|
||||
return g_str_has_suffix (device_class->id, "_tod_v1");
|
||||
g_auto(GStrv) versions = NULL;
|
||||
g_auto(GStrv) wanted_versions = NULL;
|
||||
int version;
|
||||
const char *sub_version;
|
||||
|
||||
version = tod_get_version (device_class, &sub_version);
|
||||
|
||||
if (version != tod_version)
|
||||
return FALSE;
|
||||
|
||||
if (!tod_subversion)
|
||||
return TRUE;
|
||||
|
||||
versions = g_strsplit (sub_version, ".", -1);
|
||||
g_assert_cmpuint (g_strv_length (versions), ==, 2);
|
||||
|
||||
wanted_versions = g_strsplit (tod_subversion, ".", -1);
|
||||
g_assert_cmpuint (g_strv_length (wanted_versions), ==, 2);
|
||||
|
||||
if (atoi (wanted_versions[0]) > atoi (versions[0]))
|
||||
return FALSE;
|
||||
|
||||
if (atoi (wanted_versions[1]) > atoi (versions[1]))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
|
||||
#endif
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
tod_is_v1_device (FpDevice *device)
|
||||
tod_check_device_version (FpDevice *device_class,
|
||||
int tod_version,
|
||||
const char *tod_subversion)
|
||||
{
|
||||
#ifdef TEST_TOD_DRIVER
|
||||
return tod_is_v1_class (FP_DEVICE_GET_CLASS (device));
|
||||
#endif
|
||||
return FALSE;
|
||||
return tod_check_version (FP_DEVICE_GET_CLASS (device_class),
|
||||
tod_version,
|
||||
tod_subversion);
|
||||
}
|
||||
|
||||
/* Utility functions */
|
||||
@@ -557,9 +634,9 @@ test_driver_features_probe_updates (void)
|
||||
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
|
||||
FpiDeviceFake *fake_dev;
|
||||
|
||||
if (tod_is_v1_device (device))
|
||||
if (!tod_check_device_version (device, 1, "1.92"))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
g_test_skip ("Feature not supported by TODv1 versions before 1.92");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -616,7 +693,7 @@ test_driver_initial_features (void)
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
if (!tod_is_v1_device (device))
|
||||
if (tod_check_device_version (device, 1, "1.92"))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
@@ -633,7 +710,7 @@ test_driver_initial_features (void)
|
||||
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_STORAGE));
|
||||
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_STORAGE_LIST));
|
||||
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_STORAGE_DELETE));
|
||||
if (!tod_is_v1_device (device))
|
||||
if (tod_check_device_version (device, 1, "1.92"))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
@@ -646,8 +723,8 @@ test_driver_initial_features (void)
|
||||
FP_DEVICE_FEATURE_STORAGE |
|
||||
FP_DEVICE_FEATURE_STORAGE_LIST |
|
||||
FP_DEVICE_FEATURE_STORAGE_DELETE |
|
||||
(tod_is_v1_device (device) ?
|
||||
0 : FP_DEVICE_FEATURE_STORAGE_CLEAR));
|
||||
(tod_check_device_version (device, 1, "1.92") ?
|
||||
FP_DEVICE_FEATURE_STORAGE_CLEAR : 0));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -694,7 +771,7 @@ test_driver_initial_features_no_capture (void)
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
if (tod_check_version (dev_class, 1, "1.92"))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
@@ -718,7 +795,7 @@ test_driver_initial_features_no_verify (void)
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
if (tod_check_version (dev_class, 1, "1.92"))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
@@ -742,7 +819,7 @@ test_driver_initial_features_no_identify (void)
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
if (tod_check_version (dev_class, 1, "1.92"))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
@@ -766,7 +843,7 @@ test_driver_initial_features_no_storage (void)
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
if (tod_check_version (dev_class, 1, "1.92"))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
@@ -787,13 +864,13 @@ test_driver_initial_features_no_list (void)
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_IDENTIFY);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_VERIFY);
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_DUPLICATES_CHECK);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
if (tod_check_version (dev_class, 1, "1.92"))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
if (tod_check_version (dev_class, 1, "1.92"))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
@@ -817,7 +894,7 @@ test_driver_initial_features_no_delete (void)
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE);
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_LIST);
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_DELETE);
|
||||
if (!tod_is_v1_class (dev_class))
|
||||
if (tod_check_version (dev_class, 1, "1.92"))
|
||||
g_assert_true (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
else
|
||||
g_assert_false (dev_class->features & FP_DEVICE_FEATURE_STORAGE_CLEAR);
|
||||
@@ -2057,9 +2134,9 @@ test_driver_identify_suspend_continues (void)
|
||||
FpiDeviceFake *fake_dev;
|
||||
FpPrint *expected_matched;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
if (!tod_check_version (dev_class, 1, "1.94"))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
g_test_skip ("Feature not supported by TODv1 versions before 1.94");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2129,9 +2206,9 @@ test_driver_identify_suspend_succeeds (void)
|
||||
FpiDeviceFake *fake_dev;
|
||||
FpPrint *expected_matched;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
if (!tod_check_version (dev_class, 1, "1.94"))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
g_test_skip ("Feature not supported by TODv1 versions before 1.94");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2197,9 +2274,9 @@ test_driver_identify_suspend_busy_error (void)
|
||||
FpiDeviceFake *fake_dev;
|
||||
FpPrint *expected_matched;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
if (!tod_check_version (dev_class, 1, "1.94"))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
g_test_skip ("Feature not supported by TODv1 versions before 1.94");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2260,9 +2337,9 @@ test_driver_identify_suspend_while_idle (void)
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpiDeviceFake *fake_dev;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
if (!tod_check_version (dev_class, 1, "1.94"))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
g_test_skip ("Feature not supported by TODv1 versions before 1.94");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2310,9 +2387,9 @@ test_driver_identify_warmup_cooldown (void)
|
||||
FpiDeviceFake *fake_dev;
|
||||
gint64 start_time;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
if (!tod_check_version (dev_class, 1, "1.94"))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
g_test_skip ("Feature not supported by TODv1 versions before 1.94");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2614,9 +2691,9 @@ test_driver_clear_storage (void)
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
gboolean ret;
|
||||
|
||||
if (tod_is_v1_device (device))
|
||||
if (!tod_check_device_version (device, 1, "1.92"))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
g_test_skip ("Feature not supported by TODv1 versions before 1.92");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2635,9 +2712,9 @@ test_driver_clear_storage_error (void)
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
gboolean ret;
|
||||
|
||||
if (tod_is_v1_device (device))
|
||||
if (!tod_check_device_version (device, 1, "1.92"))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
g_test_skip ("Feature not supported by TODv1 versions before 1.92");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2747,9 +2824,9 @@ test_driver_critical (void)
|
||||
void (*orig_verify) (FpDevice *device) = dev_class->verify;
|
||||
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
|
||||
|
||||
if (tod_is_v1_device (device))
|
||||
if (!tod_check_device_version (device, 1, "1.94"))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
g_test_skip ("Feature not supported by TODv1 versions before 1.94");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2961,9 +3038,9 @@ test_driver_action_is_cancelled_open (void)
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpiDeviceFake *fake_dev;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
if (!tod_check_version (dev_class, 1, "1.94"))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
g_test_skip ("Feature not supported by TODv1 versions before 1.94");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2987,9 +3064,9 @@ test_driver_action_internally_cancelled_open (void)
|
||||
g_autoptr(GError) error = NULL;
|
||||
FpiDeviceFake *fake_dev;
|
||||
|
||||
if (tod_is_v1_class (dev_class))
|
||||
if (!tod_check_version (dev_class, 1, "1.94"))
|
||||
{
|
||||
g_test_skip ("Feature not supported by TODv1 interface");
|
||||
g_test_skip ("Feature not supported by TODv1 versions before 1.94");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3142,7 +3219,7 @@ test_driver_action_error_all (void)
|
||||
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_INVALID);
|
||||
g_clear_error (&error);
|
||||
|
||||
if (!tod_is_v1_device (device))
|
||||
if (tod_check_device_version (device, 1, "1.92"))
|
||||
{
|
||||
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID);
|
||||
g_assert_false (fp_device_clear_storage_sync (device, NULL, &error));
|
||||
@@ -3256,7 +3333,7 @@ test_driver_action_error_fallback_all (void)
|
||||
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
|
||||
g_clear_error (&error);
|
||||
|
||||
if (!tod_is_v1_device (device))
|
||||
if (tod_check_device_version (device, 1, "1.92"))
|
||||
{
|
||||
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
|
||||
"*Device failed to pass an error to generic action "
|
||||
|
||||
Reference in New Issue
Block a user