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., 675 Mass Ave, Cambridge, MA 02139, 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 opendir ($dh, $tmpdir) or die ("Failed to open $tmpdir: $!");
56 my @cachedirs = grep { /^guestfs\./ } readdir ($dh);
57 closedir ($dh) or die ("Failed to close $tmpdir: $!");
59 my $ncachedirs = scalar(@cachedirs);
60 die ("Expected 1 cachedir, found $ncachedirs") unless ($ncachedirs == 1);