From: Michal Privoznik <[email protected]> After previous commit the virt-aa-helper-test started failing. This is because the previous commit introduced mocking for access() in such way that for any path with "/dev/bus/usb" prefix zero value is returned (meaning the file exists). But later, when virt-aa-helper tries to call virFileCanonicalizePath() over such path it gets an error resulting in failed test case.
Therefore, mock also virFileCanonicalizePath() and make it just return the same path for aforementioned case. Signed-off-by: Michal Privoznik <[email protected]> --- Pushed as trivial and 'fix the broken build'. tests/virusbmock.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/virusbmock.c b/tests/virusbmock.c index c67a0ba307..17fa735360 100644 --- a/tests/virusbmock.c +++ b/tests/virusbmock.c @@ -27,6 +27,7 @@ #include <unistd.h> #include "virmock.h" +#include "virfile.h" #define USB_SYSFS "/sys/bus/usb" #define FAKE_USB_SYSFS "virusbtestdata/sys_bus_usb" @@ -43,6 +44,7 @@ static int (*real___open_2)(const char *path, int flags); #endif static DIR *(*real_opendir)(const char *name); static int (*real_access)(const char *path, int mode); +static char *(*real_virFileCanonicalizePath)(const char *path); static void init_syms(void) { @@ -59,6 +61,7 @@ static void init_syms(void) #endif VIR_MOCK_REAL_INIT(opendir); VIR_MOCK_REAL_INIT(access); + VIR_MOCK_REAL_INIT(virFileCanonicalizePath); } static char *get_fake_path(const char *real_path) @@ -95,7 +98,7 @@ int access(const char *path, int mode) * device that is meant to be inaccessible in the current mount namespace * (as happens inside a container). This lets us exercise the code path * without shipping empty device-node files. */ - if (STRPREFIX(path, USB_DEVFS)) { + if (STRSKIP(path, USB_DEVFS)) { if (STREQ(path, INACCESSIBLE_USB_NODE)) { errno = ENOENT; return -1; @@ -106,6 +109,20 @@ int access(const char *path, int mode) return real_access(path, mode); } +char * +virFileCanonicalizePath(const char *path) +{ + init_syms(); + + /* Since we pretend any /dev/bus/usb node exists (see access() above) we + * must also make sure to return an expected value here. */ + if (STRPREFIX(path, USB_DEVFS)) { + return g_strdup(path); + } + + return real_virFileCanonicalizePath(path); +} + int open(const char *pathname, int flags, ...) { g_autofree char *path = NULL; -- 2.56.0
