2 # Copyright (C) 2010 Red Hat Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 # Test that 2 simultaneous launches in a clean cache directory will both succeed
23 use File::Temp qw(tempdir);
28 # Use a temporary TMPDIR to ensure it's clean
29 my $tmpdir = tempdir (CLEANUP => 1);
30 $ENV{TMPDIR} = $tmpdir;
32 my $testimg = $tmpdir.'/test.img';
33 system ("touch $testimg");
36 die ("fork failed: $!") if ($pid < 0);
39 my $g = Sys::Guestfs->new ();
40 $g->add_drive ($testimg);
45 my $g = Sys::Guestfs->new ();
46 $g->add_drive ($testimg);
50 waitpid ($pid, 0) or die ("waitpid: $!");
51 die ("child failed") unless ($? == 0);
53 # Check that only 1 temporary cache directory was created.
55 # No cache directory is OK too (as long as the appliance launched w/o
56 # failure) because it indicates we're not using supermin.
58 opendir ($dh, $tmpdir) or die ("Failed to open $tmpdir: $!");
59 my @cachedirs = grep { /^guestfs\./ } readdir ($dh);
60 closedir ($dh) or die ("Failed to close $tmpdir: $!");
62 my $ncachedirs = scalar(@cachedirs);
63 die "Expected 0 or 1 cachedir, found $ncachedirs"
64 unless $ncachedirs == 0 || $ncachedirs == 1;