From b5ee13e32981aa0e1dd9c924921c75194060ea18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Fri, 5 Jul 2019 18:14:52 +0100 Subject: [PATCH] tests: fix mocking of virFileGetXAttrQuiet on FreeBSD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The qemusecuritytest is failing on FreeBSD 11/12, reporting that files are not correctly restored. Debugging code printfs show that the virFileGetXAttrQuiet mock is returning 0, but the virFileGetXAttr function is seeing -1 as the return value. Essentially there appears to be some kind of optimization between the real virFileGetXAttrQuiet and the real virFileGetXAttr, which breaks when we mock virFileGetXAttrQuiet. Rather than trying to figure out how to avoid this, it is simpler to just mock virFileGetXAttr too since it is very short code. Signed-off-by: Daniel P. Berrangé --- tests/qemusecuritymock.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c index 2a9095e1bf..a15eef29c9 100644 --- a/tests/qemusecuritymock.c +++ b/tests/qemusecuritymock.c @@ -156,6 +156,34 @@ virFileGetXAttrQuiet(const char *path, } +/* + * This may look redundant but is needed to work around an + * compiler quirk. The call from the real virFileGetXAttr + * to the real virFileGetXAttrQuiet has a quirk where the + * return value from virFileGetXAttrQuiet gets scrambled + * if we mock virFileGetXAttrQuiet, returning -1 instead + * of 0 despite succeeding. This happens on FreeBSD 11/12 + * hosts with CLang, and is suspected to be some kind of + * compiler optimization. By mocking this function too we + * can workaround it. + */ +int +virFileGetXAttr(const char *path, + const char *name, + char **value) +{ + int ret; + + if ((ret = virFileGetXAttrQuiet(path, name, value)) < 0) { + virReportSystemError(errno, + "Unable to get XATTR %s on %s", + name, path); + } + + return ret; +} + + int virFileSetXAttr(const char *path, const char *name, const char *value)