On Sat, Feb 27, 2021 at 08:34:08AM +0400, Roman Bogorodskiy wrote: > Implement "<os firmware='efi'>" support for bhyve driver. > As there are not really lot of options, try to find > "BHYVE_UEFI.fd" firmware which is installed by the > sysutils/uefi-edk2-bhyve FreeBSD port. > > If not found, just use the first found firmware > in the firmwares directory (which is configurable via > config file). > > Signed-off-by: Roman Bogorodskiy <bogorodskiy@xxxxxxxxx> > --- > Not extremely happy about the LIBVIRT_BHYVE_FIRMWARE_DIR_OVERRIDE knob, > but not sure how to test this otherwise. Agreed, that should not be part of the production code. You can use tests/bhyvexml2argvmock.c which is already used for that test where you would provide your custom implementation of opendir() system call. The implementation should check if it tries to access the default firmware dir and change it to location in our tests and all other paths simply pass to the real opendir(). Look into tests/virpcimock.c, but the addition for your use-case should look something like this: diff --git a/tests/bhyvexml2argvmock.c b/tests/bhyvexml2argvmock.c index 25b97f5e04..1c2b1f8876 100644 --- a/tests/bhyvexml2argvmock.c +++ b/tests/bhyvexml2argvmock.c @@ -4,10 +4,34 @@ #include "virstring.h" #include "virnetdev.h" #include "virnetdevtap.h" +#include "virmock.h" #include "internal.h" #define VIR_FROM_THIS VIR_FROM_BHYVE +#define DEFAULT_FIRMWARE_DIR_TEMPLATE DATADIR "/uefi-firmware" +#define FAKE_FIRMWARE_DIR_TEMPLATE abs_builddir "/bhyvefakefirmwaredir-XXXXXX" + +static int (*real_opendir)(const char *name); + +static void +init_syms(void) +{ + VIR_MOCK_REAL_INIT(opendir); +} + +DIR * +opendir(const char *path) +{ + init_syms(); + + if (STRPREFIX(path, DEFAULT_FIRMWARE_DIR_TEMPLATE)) { + return real_opendir(FAKE_FIRMWARE_DIR_TEMPLATE); + } else { + return real_opendir(path); + } +} + void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN], virMacAddrPtr addr) { I did not test it :) Pavel
Attachment:
signature.asc
Description: PGP signature