From 820dac7fdea5806e16d00905f7cc09172b1f3bc9 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Sat, 16 Sep 2017 17:46:41 +0100 Subject: [PATCH] trivial: Use a different SYSFSFIRMWAREDIR for self tests This means we can drop some self-test specific code in fu_smbios_setup(). --- src/fu-engine.c | 2 +- src/fu-self-test.c | 12 ++---------- src/fu-smbios.c | 11 +++-------- src/fu-smbios.h | 1 - src/fu-util.c | 2 +- src/meson.build | 3 +++ 6 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/fu-engine.c b/src/fu-engine.c index 5b7035e04..712694038 100644 --- a/src/fu-engine.c +++ b/src/fu-engine.c @@ -2813,7 +2813,7 @@ fu_engine_load (FuEngine *self, GError **error) } /* load SMBIOS and the hwids */ - if (!fu_smbios_setup (self->smbios, NULL, &error_smbios)) + if (!fu_smbios_setup (self->smbios, &error_smbios)) g_warning ("Failed to load SMBIOS: %s", error_smbios->message); if (!fu_hwids_setup (self->hwids, self->smbios, &error_hwids)) g_warning ("Failed to load HWIDs: %s", error_hwids->message); diff --git a/src/fu-self-test.c b/src/fu-self-test.c index ba4e08cab..1db6079c5 100644 --- a/src/fu-self-test.c +++ b/src/fu-self-test.c @@ -81,15 +81,11 @@ fu_smbios_func (void) const gchar *str; gboolean ret; g_autofree gchar *dump = NULL; - g_autofree gchar *sysfsdir = NULL; g_autoptr(FuSmbios) smbios = NULL; g_autoptr(GError) error = NULL; - sysfsdir = fu_test_get_filename (TESTDATADIR, "."); - g_assert (sysfsdir != NULL); - smbios = fu_smbios_new (); - ret = fu_smbios_setup (smbios, sysfsdir, &error); + ret = fu_smbios_setup (smbios, &error); g_assert_no_error (error); g_assert (ret); dump = fu_smbios_to_string (smbios); @@ -120,7 +116,6 @@ fu_hwids_func (void) g_autoptr(FuHwids) hwids = NULL; g_autoptr(FuSmbios) smbios = NULL; g_autoptr(GError) error = NULL; - g_autofree gchar *sysfsdir = NULL; gboolean ret; struct { @@ -146,11 +141,8 @@ fu_hwids_func (void) { NULL, NULL } }; - sysfsdir = fu_test_get_filename (TESTDATADIR, "."); - g_assert (sysfsdir != NULL); - smbios = fu_smbios_new (); - ret = fu_smbios_setup (smbios, sysfsdir, &error); + ret = fu_smbios_setup (smbios, &error); g_assert_no_error (error); g_assert (ret); diff --git a/src/fu-smbios.c b/src/fu-smbios.c index 507d17925..aa033f36f 100644 --- a/src/fu-smbios.c +++ b/src/fu-smbios.c @@ -138,7 +138,6 @@ fu_smbios_setup_from_file (FuSmbios *self, const gchar *filename, GError **error /** * fu_smbios_setup: * @self: A #FuSmbios - * @sysfsdir: A file path, e.g. '/sys/firmware' or %NULL * @error: A #GError or %NULL * * Reads all the SMBIOS values from the hardware. @@ -146,7 +145,7 @@ fu_smbios_setup_from_file (FuSmbios *self, const gchar *filename, GError **error * Returns: %TRUE for success **/ gboolean -fu_smbios_setup (FuSmbios *self, const gchar *sysfsdir, GError **error) +fu_smbios_setup (FuSmbios *self, GError **error) { FuSmbiosStructureEntryPoint *ep; gsize sz = 0; @@ -158,12 +157,8 @@ fu_smbios_setup (FuSmbios *self, const gchar *sysfsdir, GError **error) g_return_val_if_fail (FU_IS_SMBIOS (self), FALSE); - /* default value */ - if (sysfsdir == NULL) - sysfsdir = "/sys/firmware"; - /* get the smbios entry point */ - ep_fn = g_build_filename (sysfsdir, "dmi", "tables", "smbios_entry_point", NULL); + ep_fn = g_build_filename (SYSFSFIRMWAREDIR, "dmi", "tables", "smbios_entry_point", NULL); if (!g_file_get_contents (ep_fn, &ep_raw, &sz, error)) return FALSE; if (sz != sizeof(FuSmbiosStructureEntryPoint)) { @@ -215,7 +210,7 @@ fu_smbios_setup (FuSmbios *self, const gchar *sysfsdir, GError **error) ep->smbios_minor_ver); /* get the DMI data */ - dmi_fn = g_build_filename (sysfsdir, "dmi", "tables", "DMI", NULL); + dmi_fn = g_build_filename (SYSFSFIRMWAREDIR, "dmi", "tables", "DMI", NULL); if (!g_file_get_contents (dmi_fn, &dmi_raw, &sz, error)) return FALSE; if (sz != GUINT16_FROM_LE (ep->structure_table_len)) { diff --git a/src/fu-smbios.h b/src/fu-smbios.h index 506927a22..5c33f81b8 100644 --- a/src/fu-smbios.h +++ b/src/fu-smbios.h @@ -38,7 +38,6 @@ FuSmbios *fu_smbios_new (void); #define FU_SMBIOS_STRUCTURE_TYPE_CHASSIS 0x03 gboolean fu_smbios_setup (FuSmbios *self, - const gchar *sysfsdir, GError **error); gboolean fu_smbios_setup_from_file (FuSmbios *self, const gchar *filename, diff --git a/src/fu-util.c b/src/fu-util.c index 04d026c9d..59b262cc1 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -1496,7 +1496,7 @@ fu_util_hwids (FuUtilPrivate *priv, gchar **values, GError **error) NULL }; /* read DMI data */ - if (!fu_smbios_setup (smbios, g_getenv ("SYSFSPATH"), error)) + if (!fu_smbios_setup (smbios, error)) return FALSE; if (!fu_hwids_setup (hwids, smbios, error)) return FALSE; diff --git a/src/meson.build b/src/meson.build index 425941f13..0b06e00ee 100644 --- a/src/meson.build +++ b/src/meson.build @@ -48,6 +48,7 @@ libfwupdprivate = static_library( c_args : [ cargs, '-DLOCALSTATEDIR="' + localstatedir + '"', + '-DSYSFSFIRMWAREDIR="/sys/firmware"', '-DFU_OFFLINE_DESTDIR=""', ], ) @@ -134,6 +135,7 @@ executable( cargs, '-DLOCALSTATEDIR="' + localstatedir + '"', '-DPLUGINDIR="' + plugin_dir + '"', + '-DSYSFSFIRMWAREDIR="/sys/firmware"', '-DFU_OFFLINE_DESTDIR=""', ], install : true, @@ -193,6 +195,7 @@ if get_option('enable-tests') '-DPLUGINBUILDDIR="' + pluginbuilddir + '"', '-DFU_OFFLINE_DESTDIR="/tmp/fwupd-self-test"', '-DPLUGINDIR="' + testdatadir_src + '"', + '-DSYSFSFIRMWAREDIR="' + testdatadir_src + '"', ], ) test('fu-self-test', e, is_parallel:false)