[libvirt] [PATCH 0/3] Trivial fixes mocking fixes

I'm not pushing these just yet. I'm leaving some time for our grammar enthusiasts to fix my grammar. Michal Prívozník (3): virfilemock: Init symbols in canonicalize_file_name() virtestmock: Initialize symbols from stat() and its friends lib: Build sources before running 'check-access' Makefile.am | 2 +- tests/virfilemock.c | 3 +++ tests/virtestmock.c | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) -- 2.21.0

If a program that is using this mock calls canonicalize_file_name() as the very first function then it will face SIGSEGV because real_canonicalize_file_name is uninitialized. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/virfilemock.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/virfilemock.c b/tests/virfilemock.c index 89e14c5b67..106032f857 100644 --- a/tests/virfilemock.c +++ b/tests/virfilemock.c @@ -177,6 +177,9 @@ statfs(const char *path, struct statfs *buf) char * canonicalize_file_name(const char *path) { + + init_syms(); + if (getenv("LIBVIRT_MTAB")) { const char *p; char *ret; -- 2.21.0

ACK

Introduced by ff376c6283c97. Previously, init_syms() was called from stat() mock and its friends. This is crucial because checkPath() might call printFile() which in turn calls real_fopen(). But if stat() or one of its friends is the first function called then because of lacking init_syms() call no real_* is initialized. The other thing is that we really want the recorded action to be "stat" instead of __FUNCTION__ because there's no good in recording that it was __xstat64 who touched some file. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/virtestmock.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/virtestmock.c b/tests/virtestmock.c index bc62312444..ad6958ac87 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -190,7 +190,9 @@ int access(const char *path, int mode) } -#define VIR_MOCK_STAT_HOOK CHECK_PATH(path) +#define VIR_MOCK_STAT_HOOK \ + init_syms(); \ + checkPath(path, "stat") #include "virmockstathelpers.c" -- 2.21.0

On Mon, May 06, 2019 at 04:34:07PM +0200, Michal Privoznik wrote:
Introduced by ff376c6283c97.
Previously, init_syms() was called from stat() mock and its friends. This is crucial because checkPath() might call printFile() which in turn calls real_fopen(). But if stat() or one of its friends is the first function called then because of lacking init_syms() call no real_* is initialized.
The other thing is that we really want the recorded action to be "stat" instead of __FUNCTION__ because there's no good in recording that it was __xstat64 who touched some file.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/virtestmock.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tests/virtestmock.c b/tests/virtestmock.c index bc62312444..ad6958ac87 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -190,7 +190,9 @@ int access(const char *path, int mode) }
-#define VIR_MOCK_STAT_HOOK CHECK_PATH(path) +#define VIR_MOCK_STAT_HOOK \ + init_syms(); \ + checkPath(path, "stat")
Just for the cleanliness of things, I would prefer the macro to be written as a single block: do { init_syms(); \ checkPath(path, "stat") while (0) even when it is not used like that (at least not yet). ACK either way.
#include "virmockstathelpers.c"
-- 2.21.0
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

If the source tree was freshly configured and no objects are built yet then 'make check-access' has no test to run. Build the sources beforehand. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index eba5916352..0d8bb733e6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -83,7 +83,7 @@ srpm: clean check-local: all tests -check-access: +check-access: all @($(MAKE) $(AM_MAKEFLAGS) -C tests check-access) MAINTAINERCLEANFILES = .git-module-status -- 2.21.0

ACK
participants (2)
-
Martin Kletzander
-
Michal Privoznik