[libvirt] [PATCH] test: Return Libvirt logo as domain screenshot

This is just a bare Easter Egg. Whenever user run virDomainScreenshot over a domain in test driver, he'll get the Libvirt PNG logo in return. --- docs/Makefile.am | 1 + src/test/test_driver.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/docs/Makefile.am b/docs/Makefile.am index 7583772..b5d7575 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -287,6 +287,7 @@ install-data-local: for file in $(devhelphtml) $(devhelppng) $(devhelpcss); do \ $(INSTALL) -m 0644 $(srcdir)/$${file} $(DESTDIR)$(DEVHELP_DIR) ; \ done + $(INSTALL_DATA) $(srcdir)/../docs/libvirtLogo.png $(DESTDIR)$(pkgdatadir) uninstall-local: for h in $(apihtml); do rm $(DESTDIR)$(HTML_DIR)/$$h; done diff --git a/src/test/test_driver.c b/src/test/test_driver.c index c5fffb9..ad683f7 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -39,11 +39,13 @@ #include "virutil.h" #include "viruuid.h" #include "capabilities.h" +#include "configmake.h" #include "viralloc.h" #include "network_conf.h" #include "interface_conf.h" #include "domain_conf.h" #include "domain_event.h" +#include "fdstream.h" #include "storage_conf.h" #include "node_device_conf.h" #include "virxml.h" @@ -5773,6 +5775,25 @@ cleanup: return ret; } +static char * +testDomainScreenshot(virDomainPtr dom ATTRIBUTE_UNUSED, + virStreamPtr st, + unsigned int screen ATTRIBUTE_UNUSED, + unsigned int flags) +{ + char *ret = NULL; + + virCheckFlags(0, NULL); + + if (virFDStreamOpenFile(st, PKGDATADIR "/libvirtLogo.png", 0, 0, O_RDONLY < 0)) + goto cleanup; + + ret = strdup("image/png"); + +cleanup: + return ret; +} + static virDriver testDriver = { .no = VIR_DRV_TEST, @@ -5843,6 +5864,7 @@ static virDriver testDriver = { .domainEventDeregisterAny = testDomainEventDeregisterAny, /* 0.8.0 */ .isAlive = testIsAlive, /* 0.9.8 */ .nodeGetCPUMap = testNodeGetCPUMap, /* 1.0.0 */ + .domainScreenshot = testDomainScreenshot, /* 1.0.4 */ }; static virNetworkDriver testNetworkDriver = { -- 1.8.1.5

On 03/29/2013 03:52 PM, Michal Privoznik wrote:
This is just a bare Easter Egg. Whenever user run virDomainScreenshot over a domain in test driver, he'll get the Libvirt PNG logo in return.
Cute idea, and handy for easier testing of screenshot API.
+static char * +testDomainScreenshot(virDomainPtr dom ATTRIBUTE_UNUSED, + virStreamPtr st, + unsigned int screen ATTRIBUTE_UNUSED, + unsigned int flags) +{ + char *ret = NULL; + + virCheckFlags(0, NULL); + + if (virFDStreamOpenFile(st, PKGDATADIR "/libvirtLogo.png", 0, 0, O_RDONLY < 0)) + goto cleanup; + + ret = strdup("image/png");
Missing an OOM check, in which case you also end up leaking an incomplete stream. I'd swap the strdup to happen first so you don't have to clean up a stream.
@@ -5843,6 +5864,7 @@ static virDriver testDriver = { .domainEventDeregisterAny = testDomainEventDeregisterAny, /* 0.8.0 */ .isAlive = testIsAlive, /* 0.9.8 */ .nodeGetCPUMap = testNodeGetCPUMap, /* 1.0.0 */ + .domainScreenshot = testDomainScreenshot, /* 1.0.4 */
That's pushing it; this is probably post-release material. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Fri, Mar 29, 2013 at 10:52:10PM +0100, Michal Privoznik wrote:
This is just a bare Easter Egg. Whenever user run virDomainScreenshot over a domain in test driver, he'll get the Libvirt PNG logo in return.
Yeah, smart idea :-), agreed with Eric it should got after the release and somehow I smell the icon path also need to be added to libvirt.spec.in . Since it is implemented on the client side of the library this probably ought to go in the client section of the spec not the server one. Daniel -- Daniel Veillard | Open Source and Standards, Red Hat veillard@redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (3)
-
Daniel Veillard
-
Eric Blake
-
Michal Privoznik