[libvirt] [PATCH v3 06/16] Add a test suite for cgroups functionality
Daniel P. Berrange
berrange at redhat.com
Thu Apr 11 10:24:02 UTC 2013
On Wed, Apr 10, 2013 at 09:04:33PM -0600, Eric Blake wrote:
> On 04/10/2013 04:08 AM, Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" <berrange at redhat.com>
> >
> > Some aspects of the cgroups setup / detection code are quite subtle
> > and easy to break. It would greatly benefit from unit testing, but
> > this is difficult because the test suite won't have privileges to
> > play around with cgroups. The solution is to use monkey patching
> > via LD_PRELOAD to override the fopen, open, mkdir, access functions
> > to redirect access of cgroups files to some magic stubs in the
> > test suite.
> >
> > Using this we provide custom content for the /proc/cgroup and
> > /proc/self/mounts files which report a fixed cgroup setup. We
> > then override open/mkdir/access so that access to the cgroups
> > filesystem gets redirected into files in a temporary directory
> > tree in the test suite build dir.
>
> Do you also need to override openat/mkdirat/faccessat, in case we (or
> even libc on our behalf) ever uses the newer *at syscalls?
Well, if glibc did try todo such magic, there'd probably be more
that needed overriding besides hte *at() functions. So we should
just wait until that day, rather than second guessing it I think.
> Wow, this looks complicated, so I'll have to defer my review to sometime
> earlier in my day when I'm thinking straight. But the premise is
> useful, and a passing 'make check' even on a system with no cgroups
> mounted is a pretty good indication of whether you got it right.
>
> > +/*
> > + * The plan:
> > + *
> > + * We fake out /proc/mounts, so make it look as is cgroups
> > + * are mounted on /not/really/sys/fs/cgroup. We don't
> > + * use /sys/fs/cgroup, because we want to make it easy to
> > + * detect places where we've not mocked enough syscalls.
>
> and so that the testsuite will run and pass even on systems without
> cgroups mounted.
Correct.
> > +mymain(void)
> > +{
> > + int ret = 0;
> > + char *fakesysfsdir;
> > +
> > + if (!(fakesysfsdir = strdup(FAKESYSFSDIRTEMPLATE))) {
> > + fprintf(stderr, "Out of memory\n");
> > + abort();
> > + }
> > +
> > + if (!mkdtemp(fakesysfsdir)) {
>
> Does this compile on mingw, or do you need to modify bootstrap.conf to
> pull in the mkdtemp gnulib module? [Then again, it won't compile on
> mingw in the first place, since the Makefile.am limits it to platforms
> with LD_PRELOAD support]
Hmm, I've not tested with win32 build. I think we actually ought to
make sure this is run on Linux only, since it doesn't make sense on
BSD either.
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the libvir-list
mailing list