trivial: Use a different SYSFSFIRMWAREDIR for self tests

This means we can drop some self-test specific code in fu_smbios_setup().
This commit is contained in:
Richard Hughes 2017-09-16 17:46:41 +01:00
parent e7c6bcab3a
commit 820dac7fde
6 changed files with 10 additions and 21 deletions

View File

@ -2813,7 +2813,7 @@ fu_engine_load (FuEngine *self, GError **error)
} }
/* load SMBIOS and the hwids */ /* 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); g_warning ("Failed to load SMBIOS: %s", error_smbios->message);
if (!fu_hwids_setup (self->hwids, self->smbios, &error_hwids)) if (!fu_hwids_setup (self->hwids, self->smbios, &error_hwids))
g_warning ("Failed to load HWIDs: %s", error_hwids->message); g_warning ("Failed to load HWIDs: %s", error_hwids->message);

View File

@ -81,15 +81,11 @@ fu_smbios_func (void)
const gchar *str; const gchar *str;
gboolean ret; gboolean ret;
g_autofree gchar *dump = NULL; g_autofree gchar *dump = NULL;
g_autofree gchar *sysfsdir = NULL;
g_autoptr(FuSmbios) smbios = NULL; g_autoptr(FuSmbios) smbios = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
sysfsdir = fu_test_get_filename (TESTDATADIR, ".");
g_assert (sysfsdir != NULL);
smbios = fu_smbios_new (); smbios = fu_smbios_new ();
ret = fu_smbios_setup (smbios, sysfsdir, &error); ret = fu_smbios_setup (smbios, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (ret); g_assert (ret);
dump = fu_smbios_to_string (smbios); dump = fu_smbios_to_string (smbios);
@ -120,7 +116,6 @@ fu_hwids_func (void)
g_autoptr(FuHwids) hwids = NULL; g_autoptr(FuHwids) hwids = NULL;
g_autoptr(FuSmbios) smbios = NULL; g_autoptr(FuSmbios) smbios = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
g_autofree gchar *sysfsdir = NULL;
gboolean ret; gboolean ret;
struct { struct {
@ -146,11 +141,8 @@ fu_hwids_func (void)
{ NULL, NULL } { NULL, NULL }
}; };
sysfsdir = fu_test_get_filename (TESTDATADIR, ".");
g_assert (sysfsdir != NULL);
smbios = fu_smbios_new (); smbios = fu_smbios_new ();
ret = fu_smbios_setup (smbios, sysfsdir, &error); ret = fu_smbios_setup (smbios, &error);
g_assert_no_error (error); g_assert_no_error (error);
g_assert (ret); g_assert (ret);

View File

@ -138,7 +138,6 @@ fu_smbios_setup_from_file (FuSmbios *self, const gchar *filename, GError **error
/** /**
* fu_smbios_setup: * fu_smbios_setup:
* @self: A #FuSmbios * @self: A #FuSmbios
* @sysfsdir: A file path, e.g. '/sys/firmware' or %NULL
* @error: A #GError or %NULL * @error: A #GError or %NULL
* *
* Reads all the SMBIOS values from the hardware. * 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 * Returns: %TRUE for success
**/ **/
gboolean gboolean
fu_smbios_setup (FuSmbios *self, const gchar *sysfsdir, GError **error) fu_smbios_setup (FuSmbios *self, GError **error)
{ {
FuSmbiosStructureEntryPoint *ep; FuSmbiosStructureEntryPoint *ep;
gsize sz = 0; 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); g_return_val_if_fail (FU_IS_SMBIOS (self), FALSE);
/* default value */
if (sysfsdir == NULL)
sysfsdir = "/sys/firmware";
/* get the smbios entry point */ /* 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)) if (!g_file_get_contents (ep_fn, &ep_raw, &sz, error))
return FALSE; return FALSE;
if (sz != sizeof(FuSmbiosStructureEntryPoint)) { if (sz != sizeof(FuSmbiosStructureEntryPoint)) {
@ -215,7 +210,7 @@ fu_smbios_setup (FuSmbios *self, const gchar *sysfsdir, GError **error)
ep->smbios_minor_ver); ep->smbios_minor_ver);
/* get the DMI data */ /* 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)) if (!g_file_get_contents (dmi_fn, &dmi_raw, &sz, error))
return FALSE; return FALSE;
if (sz != GUINT16_FROM_LE (ep->structure_table_len)) { if (sz != GUINT16_FROM_LE (ep->structure_table_len)) {

View File

@ -38,7 +38,6 @@ FuSmbios *fu_smbios_new (void);
#define FU_SMBIOS_STRUCTURE_TYPE_CHASSIS 0x03 #define FU_SMBIOS_STRUCTURE_TYPE_CHASSIS 0x03
gboolean fu_smbios_setup (FuSmbios *self, gboolean fu_smbios_setup (FuSmbios *self,
const gchar *sysfsdir,
GError **error); GError **error);
gboolean fu_smbios_setup_from_file (FuSmbios *self, gboolean fu_smbios_setup_from_file (FuSmbios *self,
const gchar *filename, const gchar *filename,

View File

@ -1496,7 +1496,7 @@ fu_util_hwids (FuUtilPrivate *priv, gchar **values, GError **error)
NULL }; NULL };
/* read DMI data */ /* read DMI data */
if (!fu_smbios_setup (smbios, g_getenv ("SYSFSPATH"), error)) if (!fu_smbios_setup (smbios, error))
return FALSE; return FALSE;
if (!fu_hwids_setup (hwids, smbios, error)) if (!fu_hwids_setup (hwids, smbios, error))
return FALSE; return FALSE;

View File

@ -48,6 +48,7 @@ libfwupdprivate = static_library(
c_args : [ c_args : [
cargs, cargs,
'-DLOCALSTATEDIR="' + localstatedir + '"', '-DLOCALSTATEDIR="' + localstatedir + '"',
'-DSYSFSFIRMWAREDIR="/sys/firmware"',
'-DFU_OFFLINE_DESTDIR=""', '-DFU_OFFLINE_DESTDIR=""',
], ],
) )
@ -134,6 +135,7 @@ executable(
cargs, cargs,
'-DLOCALSTATEDIR="' + localstatedir + '"', '-DLOCALSTATEDIR="' + localstatedir + '"',
'-DPLUGINDIR="' + plugin_dir + '"', '-DPLUGINDIR="' + plugin_dir + '"',
'-DSYSFSFIRMWAREDIR="/sys/firmware"',
'-DFU_OFFLINE_DESTDIR=""', '-DFU_OFFLINE_DESTDIR=""',
], ],
install : true, install : true,
@ -193,6 +195,7 @@ if get_option('enable-tests')
'-DPLUGINBUILDDIR="' + pluginbuilddir + '"', '-DPLUGINBUILDDIR="' + pluginbuilddir + '"',
'-DFU_OFFLINE_DESTDIR="/tmp/fwupd-self-test"', '-DFU_OFFLINE_DESTDIR="/tmp/fwupd-self-test"',
'-DPLUGINDIR="' + testdatadir_src + '"', '-DPLUGINDIR="' + testdatadir_src + '"',
'-DSYSFSFIRMWAREDIR="' + testdatadir_src + '"',
], ],
) )
test('fu-self-test', e, is_parallel:false) test('fu-self-test', e, is_parallel:false)