Skip to content

Commit

Permalink
Add a concept of "Test Mode"
Browse files Browse the repository at this point in the history
Rather than plugins being disabled via the `DisabledPlugins` key
treat the `test` and `test_ble` plugins as special plugins that
are only enabled in test mode.

When the `TestDevices` key is set in `/etc/fwupd/fwupd.conf` then these
plugins will be allowed to load.

Furthermore there is a remote loaded on all systems called "fwupd-tests"
which is only used for the test suite.

When `TestDevices` key is set then it will be allowed to be used.

Also introduce and use helper args for fwupdtool to turn on/off test
devices.  These helper args are:

`fwupdtool enable-test-devices` and `fwupdtool disable-test-devices`.

When called, 3 things will happen:
 * Allow using the fwupd-tests remote
 * Allow the test plugins to load
 * Allow emulation by default (overrides `AllowEmulation` key)

With all of these changes in place fwupd.conf can be populated
ENTIRELY EMPTY!
  • Loading branch information
superm1 committed Jan 23, 2024
1 parent e1583e6 commit fe1b78e
Show file tree
Hide file tree
Showing 31 changed files with 139 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/snap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: |
sudo snap install --dangerous ${{ needs.build-snap.outputs.snap_name }}
sudo snap connect fwupd:polkit :polkit
sudo fwupd.fwupdtool modify-config DisabledPlugins ""
sudo fwupd.fwupdtool enable-test-devices
- name: Run fwupdmgr tests
run: sudo /snap/fwupd/current/share/installed-tests/fwupd/fwupdmgr.sh
- name: Run fwupd tests
Expand Down
3 changes: 1 addition & 2 deletions contrib/ci/fedora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ mkdir -p dist
cp $HOME/rpmbuild/RPMS/*/*.rpm dist

if [ "$CI" = "true" ]; then
fwupdtool modify-config DisabledPlugins ""
fwupdtool modify-config AllowEmulation true
fwupdtool enable-test-devices

# set up enough PolicyKit and D-Bus to run the daemon
mkdir -p /run/dbus
Expand Down
2 changes: 1 addition & 1 deletion contrib/debian/fwupd-tests.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
usr/share/installed-tests/*
usr/libexec/installed-tests/fwupd/*-self-test
debian/lintian/fwupd-tests usr/share/lintian/overrides
etc/fwupd/remotes.d/fwupd-tests.conf
usr/share/fwupd/remotes.d/fwupd-tests.conf
18 changes: 4 additions & 14 deletions contrib/debian/fwupd-tests.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,9 @@ set -e

#only enable on installation not upgrade
if [ "$1" = configure ] && [ -z "$2" ]; then
if [ -f /etc/fwupd/fwupd.conf ]; then
if [ "$CI" = "true" ]; then
fwupdtool modify-config DisabledPlugins ""
fwupdtool modify-config AllowEmulation true
else
echo "To enable test suite, modify /etc/fwupd/fwupd.conf"
fi
fi
if [ -f /etc/fwupd/remotes.d/fwupd-tests.conf ]; then
if [ "$CI" = "true" ]; then
fwupdtool enable-remote fwupd-tests
else
echo "To enable test suite, enable fwupd-tests remote"
fi
if [ "$CI" = "true" ]; then
fwupdtool enable-test-devices
else
echo "To enable test suite, run `fwupdtool enable-test-devices`"
fi
fi
18 changes: 4 additions & 14 deletions contrib/debian/fwupd-tests.postrm
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,9 @@ set -e

# don't run on purge; the commands might be missing
if [ "$1" = remove ]; then
if [ -f /etc/fwupd/fwupd.conf ]; then
if [ "$CI" = "true" ]; then
fwupdtool modify-config DisabledPlugins "test;test_ble"
fwupdtool modify-config AllowEmulation false
else
echo "To disable test suite, modify /etc/fwupd/fwupd.conf"
fi
fi
if [ -f /etc/fwupd/remotes.d/fwupd-tests.conf ]; then
if [ "$CI" = "true" ]; then
fwupdtool disable-remote fwupd-tests
else
echo "To enable test suite, enable fwupd-tests remote"
fi
if [ "$CI" = "true" ]; then
fwupdtool disable-test-devices
else
echo "To disable test suite, run `fwupdtool disable-test-devices`"
fi
fi
2 changes: 1 addition & 1 deletion contrib/debian/fwupd.install
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ usr/share/bash-completion
usr/share/fish/vendor_completions.d
usr/share/fwupd/*.*
usr/share/fwupd/metainfo/*
usr/share/fwupd/remotes.d/*
usr/share/fwupd/remotes.d/vendor/*
usr/share/dbus-1/*
usr/share/icons/*
usr/share/polkit-1/*
Expand Down
4 changes: 1 addition & 3 deletions contrib/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ override_dh_install:
dh_missing -a --fail-missing

#this is placed in fwupd-tests
rm -f debian/fwupd/usr/lib/*/fwupd-plugins-*/libfu_plugin_test.so
rm -f debian/fwupd/usr/lib/*/fwupd-plugins-*/libfu_plugin_test_ble.so
rm -f debian/fwupd/etc/fwupd/remotes.d/fwupd-tests.conf
rm -f debian/fwupd/usr/share/fwupd/remotes.d/fwupd-tests.conf

# avoid shipping an empty directory
[ ! -d debian/fwupd/lib/systemd ] || find debian/fwupd/lib/systemd -type d -empty -delete
Expand Down
3 changes: 1 addition & 2 deletions contrib/debian/tests/ci
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
set -e
# try loading the mtdram module to run our mtd tests
modprobe mtdram 2>&1 || true
fwupdtool modify-config DisabledPlugins ""
fwupdtool modify-config AllowEmulation true
fwupdtool enable-test-devices
fwupdtool modify-config VerboseDomains "*"
sed "s,ConditionVirtualization=.*,," \
/lib/systemd/system/fwupd.service > \
Expand Down
3 changes: 1 addition & 2 deletions contrib/fwupd.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ systemctl --no-reload preset fwupd-refresh.timer &>/dev/null || :
%{_datadir}/fwupd/device-tests/*.json
%endif
%{_libexecdir}/installed-tests/fwupd/*
%dir %{_sysconfdir}/fwupd/remotes.d
%config(noreplace)%{_sysconfdir}/fwupd/remotes.d/fwupd-tests.conf
%{_datadir}/fwupd/remotes.d/fwupd-tests.conf
%endif

%if 0%{?qubes_packages}
Expand Down
2 changes: 1 addition & 1 deletion contrib/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ parts:
${CRAFT_PART_INSTALL}/share/installed-tests/fwupd/fwupdtool.sh
sed -i "s,\(/libexec\),/snap/fwupd/current/\1," \
${CRAFT_PART_INSTALL}/share/installed-tests/fwupd/fwupd.sh
sed -i 's,^MetadataURI=.*$,MetadataURI=file:https:///snap/fwupd/current/share/installed-tests/fwupd/fwupd-tests.xml,' "${CRAFT_PART_INSTALL}/etc/fwupd/remotes.d/fwupd-tests.conf"
sed -i 's,^MetadataURI=.*$,MetadataURI=file:https:///snap/fwupd/current/share/installed-tests/fwupd/fwupd-tests.xml,' "${CRAFT_PART_INSTALL}/share/fwupd/remotes.d/fwupd-tests.conf"
# fixes up dbus service for classic snap
sed -i 's!SystemdService=\(.*\)!SystemdService=snap.fwupd.fwupd.service!' \
${CRAFT_PART_INSTALL}/share/dbus-1/system-services/org.freedesktop.fwupd.service
Expand Down
3 changes: 2 additions & 1 deletion data/bash-completion/fwupdmgr
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ modify_config_opts=(
'ReleaseDedupe'
'ReleasePriority'
'ShowDevicePrivate'
'TestDevices'
'TrustedReports'
'TrustedUids'
'UpdateMotd'
Expand Down Expand Up @@ -314,7 +315,7 @@ _fwupdmgr()
return 0
elif [[ "$args" = "3" ]]; then
case $prev in
AllowEmulation|EnumerateAllDevices|OnlyTrusted|IgnorePower|UpdateMotd|ShowDevicePrivate|ReleaseDedupe)
AllowEmulation|EnumerateAllDevices|OnlyTrusted|IgnorePower|UpdateMotd|ShowDevicePrivate|ReleaseDedupe|TestDevices)
COMPREPLY=( $(compgen -W "True False" -- "$cur") )
;;
ReleasePriority)
Expand Down
5 changes: 4 additions & 1 deletion data/bash-completion/fwupdtool
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ _fwupdtool_cmd_list=(
'build-cabinet'
'clear-history'
'disable-remote'
'disable-test-devices'
'efivar-list'
'enable-remote'
'enable-test-devices'
'esp-list'
'esp-mount'
'esp-unmount'
Expand Down Expand Up @@ -96,6 +98,7 @@ modify_config_opts=(
'ReleaseDedupe'
'ReleasePriority'
'ShowDevicePrivate'
'TestDevices'
'TrustedReports'
'TrustedUids'
'UpdateMotd'
Expand Down Expand Up @@ -242,7 +245,7 @@ _fwupdtool()
return 0
elif [[ "$args" = "3" ]]; then
case $prev in
AllowEmulation|EnumerateAllDevices|OnlyTrusted|IgnorePower|UpdateMotd|ShowDevicePrivate|ReleaseDedupe)
AllowEmulation|EnumerateAllDevices|OnlyTrusted|IgnorePower|UpdateMotd|ShowDevicePrivate|ReleaseDedupe|TestDevices)
COMPREPLY=( $(compgen -W "True False" -- "$cur") )
;;
ReleasePriority)
Expand Down
5 changes: 1 addition & 4 deletions data/fwupd.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# use `man 5 fwupd.conf` for documentation
[fwupd]
DisabledPlugins=test;test_ble
OnlyTrusted=true
AllowEmulation=false
# use `man 5 fwupd.conf` for documentation
14 changes: 3 additions & 11 deletions data/installed-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,9 @@ By default this test suite is disabled.

To enable the test suite:

1. Modify `/etc/fwupd/fwupd.conf` to remove the `test` plugin from `DisabledPlugins`

```shell
# sed "s,^Enabled=false,Enabled=true," -i /etc/fwupd/remotes.d/fwupd-tests.conf
```

2. Enable the `fwupd-tests` remote for local CAB files.

```shell
# fwupdmgr enable-remote fwupd-tests
```
```shell
fwupdtool enable-test-devices
```

## Using test suite

Expand Down
1 change: 1 addition & 0 deletions data/installed-tests/fwupd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ run_test()
run_device_tests()
{
if [ -n "$CI_NETWORK" ] && [ -d @devicetestdir@ ]; then
fwupdmgr modify-config AllowEmulation true -y
# grab device tests from the CDN to avoid incrementing the download counter
export FWUPD_DEVICE_TESTS_BASE_URI=http:https://cdn.fwupd.org/downloads
for f in `grep --files-with-matches -r emulation-url @devicetestdir@`; do
Expand Down
5 changes: 0 additions & 5 deletions data/installed-tests/fwupdmgr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ echo "Getting the list of remotes..."
fwupdmgr get-remotes
rc=$?; if [ $rc != 0 ]; then error $rc; fi

# ---
echo "Enabling fwupd-tests remote..."
fwupdmgr enable-remote fwupd-tests
rc=$?; if [ $rc != 0 ]; then error $rc; fi

# ---
echo "Update the device hash database..."
fwupdmgr verify-update $device
Expand Down
2 changes: 1 addition & 1 deletion data/installed-tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ configure_file(
output: 'fwupd-tests.conf',
configuration: con2,
install: true,
install_dir: join_paths(sysconfdir, 'fwupd', 'remotes.d'),
install_dir: join_paths(datadir, 'fwupd', 'remotes.d'),
)
3 changes: 2 additions & 1 deletion data/installed-tests/remote.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# This is a local fwupd remote that is used only for installed tests
# either from continuous integration or for fake devices from fwupd
# frontends
# It will only be loaded when the daemon configuration has `TestDevices=true`

Enabled=false
Enabled=true
Title=fwupd test suite
Keyring=none
MetadataURI=file:https://@installedtestsdir@/fwupd-tests.xml
5 changes: 5 additions & 0 deletions docs/fwupd.conf.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ The `[fwupd]` section can contain the following parameters:

At some point in the future fwupd will change the default to `metadata,firmware`.

**TestDevices={{FU_DAEMON_CONFIG_DEFAULT_TEST_DEVICES}}**

Create virtual test devices and remote for validating daemon flows.
This is only intended for CI testing and development purposes.

{% if plugin_uefi_capsule %}

## UEFI_CAPSULE PARAMETERS
Expand Down
4 changes: 4 additions & 0 deletions libfwupd/fwupd-enums.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ fwupd_plugin_flag_to_string(FwupdPluginFlags plugin_flag)
return "measure-system-integrity";
if (plugin_flag == FWUPD_PLUGIN_FLAG_READY)
return "ready";
if (plugin_flag == FWUPD_PLUGIN_FLAG_TEST_ONLY)
return "test-only";
return NULL;
}

Expand Down Expand Up @@ -508,6 +510,8 @@ fwupd_plugin_flag_from_string(const gchar *plugin_flag)
return FWUPD_PLUGIN_FLAG_MEASURE_SYSTEM_INTEGRITY;
if (g_strcmp0(plugin_flag, "ready") == 0)
return FWUPD_PLUGIN_FLAG_READY;
if (g_strcmp0(plugin_flag, "test-only") == 0)
return FWUPD_PLUGIN_FLAG_TEST_ONLY;
return FWUPD_PLUGIN_FLAG_UNKNOWN;
}

Expand Down
8 changes: 8 additions & 0 deletions libfwupd/fwupd-enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,14 @@ typedef enum {
*
* Since: 1.5.0
*/
FWUPD_PLUGIN_FLAG_TEST_ONLY = 1ull << 18,
/**
* FWUPD_PLUGIN_FLAG_TEST_ONLY:
*
* The plugin is used for virtual devices that exercising daemon flows.
*
* Since: 2.0.0
*/
FWUPD_PLUGIN_FLAG_UNKNOWN = G_MAXUINT64
} FwupdPluginFlags;

Expand Down
1 change: 1 addition & 0 deletions plugins/test/fu-test-ble-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ G_DEFINE_TYPE(FuTestBlePlugin, fu_test_ble_plugin, FU_TYPE_PLUGIN)
static void
fu_test_ble_plugin_init(FuTestBlePlugin *self)
{
fu_plugin_add_flag(FU_PLUGIN(self), FWUPD_PLUGIN_FLAG_TEST_ONLY);
}

static void
Expand Down
2 changes: 1 addition & 1 deletion plugins/test/fu-test-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fu_test_plugin_composite_cleanup(FuPlugin *plugin, GPtrArray *devices, GError **
static void
fu_test_plugin_init(FuTestPlugin *self)
{
g_debug("init");
fu_plugin_add_flag(FU_PLUGIN(self), FWUPD_PLUGIN_FLAG_TEST_ONLY);
self->delay_request_ms = 10;
}

Expand Down
12 changes: 11 additions & 1 deletion src/fu-engine-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct _FuEngineConfig {
G_DEFINE_TYPE(FuEngineConfig, fu_engine_config, FU_TYPE_CONFIG)

/* defaults changed here will also be reflected in the fwupd.conf man page */
#define FU_DAEMON_CONFIG_DEFAULT_DISABLED_PLUGINS "test;test_ble"
#define FU_DAEMON_CONFIG_DEFAULT_DISABLED_PLUGINS ""
#define FU_DAEMON_CONFIG_DEFAULT_URI_SCHEMES "file;https;http;ipfs"
#define FU_DAEMON_CONFIG_DEFAULT_UPDATE_MOTD TRUE
#define FU_DAEMON_CONFIG_DEFAULT_IGNORE_POWER FALSE
Expand All @@ -44,6 +44,7 @@ G_DEFINE_TYPE(FuEngineConfig, fu_engine_config, FU_TYPE_CONFIG)
#define FU_DAEMON_CONFIG_DEFAULT_RELEASE_DEDUPE TRUE
#define FU_DAEMON_CONFIG_DEFAULT_RELEASE_PRIORITY "local"
#define FU_DAEMON_CONFIG_DEFAULT_IDLE_TIMEOUT 7200
#define FU_DAEMON_CONFIG_DEFAULT_TEST_DEVICES FALSE

static FwupdReport *
fu_engine_config_report_from_spec(FuEngineConfig *self, const gchar *report_spec, GError **error)
Expand Down Expand Up @@ -338,6 +339,15 @@ fu_engine_config_get_show_device_private(FuEngineConfig *self)
FU_DAEMON_CONFIG_DEFAULT_SHOW_DEVICE_PRIVATE);
}

gboolean
fu_engine_config_get_test_devices(FuEngineConfig *self)
{
return fu_config_get_value_bool(FU_CONFIG(self),
"fwupd",
"TestDevices",
FU_DAEMON_CONFIG_DEFAULT_TEST_DEVICES);
}

gboolean
fu_engine_config_get_allow_emulation(FuEngineConfig *self)
{
Expand Down
2 changes: 2 additions & 0 deletions src/fu-engine-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ fu_engine_config_get_only_trusted(FuEngineConfig *self);
gboolean
fu_engine_config_get_show_device_private(FuEngineConfig *self);
gboolean
fu_engine_config_get_test_devices(FuEngineConfig *self);
gboolean
fu_engine_config_get_allow_emulation(FuEngineConfig *self);
gboolean
fu_engine_config_get_release_dedupe(FuEngineConfig *self);
Expand Down
14 changes: 14 additions & 0 deletions src/fu-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ fu_engine_modify_config(FuEngine *self, const gchar *key, const gchar *value, GE
"ReleaseDedupe",
"ReleasePriority",
"ShowDevicePrivate",
"TestDevices",
"TrustedReports",
"TrustedUids",
"UpdateMotd",
Expand Down Expand Up @@ -6443,6 +6444,16 @@ fu_engine_is_uid_trusted(FuEngine *self, guint64 calling_uid)
return FALSE;
}

static gboolean
fu_engine_is_test_plugin_disabled(FuEngine *self, FuPlugin *plugin)
{
if (!fu_plugin_has_flag(plugin, FWUPD_PLUGIN_FLAG_TEST_ONLY))
return FALSE;
if (fu_engine_config_get_test_devices(self->config))
return FALSE;
return TRUE;
}

static gboolean
fu_engine_is_plugin_name_disabled(FuEngine *self, const gchar *name)
{
Expand Down Expand Up @@ -7240,6 +7251,7 @@ fu_engine_plugins_init(FuEngine *self, FuProgress *progress, GError **error)

/* is disabled */
if (fu_engine_is_plugin_name_disabled(self, name) ||
fu_engine_is_test_plugin_disabled(self, plugin) ||
!fu_engine_is_plugin_name_enabled(self, name)) {
g_ptr_array_add(plugins_disabled, g_strdup(name));
fu_plugin_add_flag(plugin, FWUPD_PLUGIN_FLAG_DISABLED);
Expand Down Expand Up @@ -8106,6 +8118,8 @@ fu_engine_load(FuEngine *self, FuEngineLoadFlags flags, FuProgress *progress, GE
/* read remotes */
if (flags & FU_ENGINE_LOAD_FLAG_REMOTES) {
FuRemoteListLoadFlags remote_list_flags = FU_REMOTE_LIST_LOAD_FLAG_NONE;
if (fu_engine_config_get_test_devices(self->config))
remote_list_flags |= FU_REMOTE_LIST_LOAD_FLAG_TEST_REMOTE;
if (flags & FU_ENGINE_LOAD_FLAG_READONLY)
remote_list_flags |= FU_REMOTE_LIST_LOAD_FLAG_READONLY_FS;
if (flags & FU_ENGINE_LOAD_FLAG_NO_CACHE)
Expand Down
Loading

0 comments on commit fe1b78e

Please sign in to comment.