Add an installed test for verification

This commit is contained in:
Richard Hughes 2017-06-15 14:38:30 +01:00
parent 038ab7dcb2
commit ae7e0d21b2
9 changed files with 76 additions and 15 deletions

View File

@ -8,6 +8,7 @@ meson .. \
-Denable-doc=true \
-Denable-man=true \
-Denable-tests=true \
-Denable-dummy=true \
-Denable-thunderbolt=false \
-Denable-uefi=true \
-Denable-dell=true \
@ -24,6 +25,7 @@ sed "s,#VERSION#,$VERSION,;
s,#BUILD#,1,;
s,#LONGDATE#,`date '+%a %b %d %Y'`,;
s,#ALPHATAG#,alpha,;
s,enable_dummy 0,enable_dummy 1,;
s,Source0.*,Source0:\tfwupd-$VERSION.tar.xz," \
contrib/fwupd.spec.in > build/fwupd.spec

View File

@ -25,7 +25,7 @@ override_dh_auto_configure:
else \
export DELL="-Denable-dell=false"; \
fi; \
dh_auto_configure -- $$UEFI $$DELL --libexecdir=/usr/lib
dh_auto_configure -- $$UEFI $$DELL -Denable-dummy=true --libexecdir=/usr/lib
override_dh_install:
find debian/tmp/usr -type f -name "*a" -print | xargs rm -f

View File

@ -7,6 +7,7 @@
%define alphatag #ALPHATAG#
%global enable_tests 1
%global enable_dummy 1
%ifarch x86_64 %{ix86}
%global have_smbios 1
@ -128,6 +129,11 @@ Data files for installed tests.
-Denable-tests=true \
%else
-Denable-tests=false \
%endif
%if 0%{?enable_dummy}
-Denable-dummy=true \
%else
-Denable-dummy=false \
%endif
-Denable-thunderbolt=false \
%if 0%{?have_uefi}
@ -213,7 +219,9 @@ mkdir -p --mode=0700 $RPM_BUILD_ROOT%{_localstatedir}/lib/fwupd/gnupg
%if 0%{?have_smbios}
%{_libdir}/fwupd-plugins-2/libfu_plugin_synapticsmst.so
%endif
%if 0%{?enable_dummy}
%{_libdir}/fwupd-plugins-2/libfu_plugin_test.so
%endif
%{_libdir}/fwupd-plugins-2/libfu_plugin_udev.so
%if 0%{?have_uefi}
%{_libdir}/fwupd-plugins-2/libfu_plugin_uefi.so

View File

@ -0,0 +1,3 @@
[Test]
Type=session
Exec=sh -c "@bindir@/fwupdmgr verify-update && @bindir@/fwupdmgr verify"

View File

@ -12,6 +12,7 @@ testfiles = [
'fwupdmgr-get-updates.test',
'fwupdmgr-refresh-offline.test',
'fwupdmgr-refresh.test',
'fwupdmgr-verify.test',
]
foreach arg: testfiles

View File

@ -9,4 +9,5 @@ option('enable-dell', type : 'boolean', value : true, description : 'enable Dell
option('enable-thunderbolt', type : 'boolean', value : true, description : 'enable Thunderbolt support')
option('enable-systemd', type : 'boolean', value : true, description : 'enable systemd support')
option('enable-consolekit', type : 'boolean', value : true, description : 'enable ConsoleKit support')
option('enable-dummy', type : 'boolean', value : false, description : 'enable the dummy device')
option('with-bootdir', type : 'string', value : '/boot/efi', description : 'Directory for EFI system partition')

View File

@ -32,12 +32,6 @@ void
fu_plugin_init (FuPlugin *plugin)
{
fu_plugin_alloc_data (plugin, sizeof (FuPluginData));
/* only enable when testing */
if (g_getenv ("FWUPD_ENABLE_TEST_PLUGIN") == NULL) {
fu_plugin_set_enabled (plugin, FALSE);
return;
}
g_debug ("init");
}
@ -61,12 +55,40 @@ fu_plugin_coldplug (FuPlugin *plugin, GError **error)
g_autoptr(FuDevice) device = NULL;
device = fu_device_new ();
fu_device_set_id (device, "FakeDevice");
fu_device_add_guid (device, "00000000-0000-0000-0000-000000000000");
fu_device_add_guid (device, "b585990a-003e-5270-89d5-3705a17f9a43");
fu_device_set_name (device, "Integrated_Webcam(TM)");
fu_device_add_flag (device, FWUPD_DEVICE_FLAG_ALLOW_ONLINE);
fu_device_set_description (device, "A fake webcam");
fu_device_set_vendor (device, "ACME Corp.");
fu_device_set_vendor_id (device, "USB:0x046D");
fu_device_set_version_bootloader (device, "0.1.2");
fu_device_set_version (device, "1.2.3");
fu_device_set_version_lowest (device, "1.2.0");
fu_plugin_device_add (plugin, device);
return TRUE;
}
gboolean
fu_plugin_verify (FuPlugin *plugin,
FuDevice *device,
FuPluginVerifyFlags flags,
GError **error)
{
if (g_strcmp0 (fu_device_get_version (device), "1.2.3") == 0) {
fu_device_add_checksum (device, "13fad4329b7e9cc8d0fe05afb5573f328d362f4f");
return TRUE;
}
if (g_strcmp0 (fu_device_get_version (device), "1.2.4") == 0) {
fu_device_add_checksum (device, "81bc8b33c2cefb1afdbe294b912d20a92c7d0968");
return TRUE;
}
g_set_error (error,
FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED,
"no checksum for %s", fu_device_get_version (device));
return FALSE;
}
gboolean
fu_plugin_update_online (FuPlugin *plugin,
FuDevice *device,
@ -81,6 +103,20 @@ fu_plugin_update_online (FuPlugin *plugin,
"cannot handle offline");
}
fu_plugin_set_status (plugin, FWUPD_STATUS_DECOMPRESSING);
for (guint i = 1; i <= 100; i++) {
g_usleep (1000);
fu_plugin_set_percentage (plugin, i);
}
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_WRITE);
for (guint i = 1; i <= 100; i++) {
g_usleep (1000);
fu_plugin_set_percentage (plugin, i);
}
fu_plugin_set_status (plugin, FWUPD_STATUS_DEVICE_VERIFY);
for (guint i = 1; i <= 100; i++) {
g_usleep (1000);
fu_plugin_set_percentage (plugin, i);
}
fu_device_set_version (device, "1.2.4");
return TRUE;
}

View File

@ -1,5 +1,10 @@
cargs = ['-DG_LOG_DOMAIN="FuPluginTest"']
install_dummy = false
if get_option('enable-dummy')
install_dummy = true
endif
shared_module('fu_plugin_test',
sources : [
'fu-plugin-test.c',
@ -9,7 +14,7 @@ shared_module('fu_plugin_test',
include_directories('../../src'),
include_directories('../../libfwupd'),
],
install : true,
install : install_dummy,
install_dir: plugin_dir,
c_args : cargs,
dependencies : [

View File

@ -178,8 +178,6 @@ fu_plugin_module_func (void)
g_autoptr(GBytes) blob_cab = NULL;
g_autoptr(GMappedFile) mapped_file = NULL;
g_setenv ("FWUPD_ENABLE_TEST_PLUGIN", "1", TRUE);
/* create a fake device */
plugin = fu_plugin_new ();
ret = fu_plugin_open (plugin, PLUGINBUILDDIR "/libfu_plugin_test.so", &error);
@ -202,8 +200,11 @@ fu_plugin_module_func (void)
g_assert_cmpint (cnt, ==, 0);
g_assert (device != NULL);
g_assert_cmpstr (fu_device_get_id (device), ==, "FakeDevice");
g_assert_cmpstr (fu_device_get_version_lowest (device), ==, "1.2.0");
g_assert_cmpstr (fu_device_get_version (device), ==, "1.2.3");
g_assert_cmpstr (fu_device_get_version_bootloader (device), ==, "0.1.2");
g_assert_cmpstr (fu_device_get_guid_default (device), ==,
"00000000-0000-0000-0000-000000000000");
"b585990a-003e-5270-89d5-3705a17f9a43");
g_assert_cmpstr (fu_device_get_name (device), ==,
"Integrated Webcam™");
@ -214,7 +215,7 @@ fu_plugin_module_func (void)
g_assert (mapped_file != NULL);
blob_cab = g_mapped_file_get_bytes (mapped_file);
ret = fu_plugin_runner_update (plugin, device, blob_cab, NULL,
FWUPD_INSTALL_FLAG_OFFLINE, &error);
FWUPD_INSTALL_FLAG_OFFLINE, &error);
g_assert_no_error (error);
g_assert (ret);
g_assert_cmpint (cnt, ==, 1);
@ -234,10 +235,14 @@ fu_plugin_module_func (void)
/* lets do this online */
ret = fu_plugin_runner_update (plugin, device, blob_cab, NULL,
FWUPD_INSTALL_FLAG_NONE, &error);
FWUPD_INSTALL_FLAG_NONE, &error);
g_assert_no_error (error);
g_assert (ret);
g_assert_cmpint (cnt, ==, 3);
g_assert_cmpint (cnt, ==, 4);
/* check the new version */
g_assert_cmpstr (fu_device_get_version (device), ==, "1.2.4");
g_assert_cmpstr (fu_device_get_version_bootloader (device), ==, "0.1.2");
/* lets check the pending */
res = fu_pending_get_device (pending, fu_device_get_id (device), &error);