mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
tests: Use new guestfs_add_drive_scratch API where possible in tests.
Replaces code such as: fd = open "test1.img" ftruncate fd, size close fd g.add_drive "test1.img" with the shorter and simpler: g.add_drive_scratch size
This commit is contained in:
@@ -20,7 +20,6 @@ package guestfs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"os"
|
|
||||||
// "sort"
|
// "sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,17 +30,7 @@ func Test100Launch (t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer g.Close ()
|
defer g.Close ()
|
||||||
|
|
||||||
f, ferr := os.Create ("test.img")
|
err := g.Add_drive_scratch (500 * 1024 * 1024, nil);
|
||||||
if ferr != nil {
|
|
||||||
t.Errorf ("could not create file: %s", ferr)
|
|
||||||
}
|
|
||||||
defer os.Remove ("test.img")
|
|
||||||
if ferr := f.Truncate (500 * 1024 * 1024); ferr != nil {
|
|
||||||
t.Errorf ("could not truncate file: %s", ferr)
|
|
||||||
}
|
|
||||||
f.Close ()
|
|
||||||
|
|
||||||
err := g.Add_drive ("test.img", nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf ("%s", err)
|
t.Errorf ("%s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import Control.Monad
|
|||||||
|
|
||||||
main = do
|
main = do
|
||||||
g <- G.create
|
g <- G.create
|
||||||
|
{- XXX replace with a call to add_drive_scratch once
|
||||||
|
optional arguments are supported -}
|
||||||
fd <- openFile "test.img" WriteMode
|
fd <- openFile "test.img" WriteMode
|
||||||
hSetFileSize fd (500 * 1024 * 1024)
|
hSetFileSize fd (500 * 1024 * 1024)
|
||||||
hClose fd
|
hClose fd
|
||||||
|
|||||||
@@ -25,16 +25,8 @@ public class GuestFS100Launch
|
|||||||
public static void main (String[] argv)
|
public static void main (String[] argv)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Delete any previous test file if one was left around.
|
|
||||||
File old = new File ("test.img");
|
|
||||||
old.delete ();
|
|
||||||
|
|
||||||
RandomAccessFile f = new RandomAccessFile ("test.img", "rw");
|
|
||||||
f.setLength (500 * 1024 * 1024);
|
|
||||||
f.close ();
|
|
||||||
|
|
||||||
GuestFS g = new GuestFS ();
|
GuestFS g = new GuestFS ();
|
||||||
g.add_drive ("test.img");
|
g.add_drive_scratch (500 * 1024 * 1024, null);
|
||||||
g.launch ();
|
g.launch ();
|
||||||
|
|
||||||
g.pvcreate ("/dev/sda");
|
g.pvcreate ("/dev/sda");
|
||||||
@@ -57,9 +49,6 @@ public class GuestFS100Launch
|
|||||||
|
|
||||||
g.shutdown ();
|
g.shutdown ();
|
||||||
g.close ();
|
g.close ();
|
||||||
|
|
||||||
File f2 = new File ("test.img");
|
|
||||||
f2.delete ();
|
|
||||||
}
|
}
|
||||||
catch (Exception exn) {
|
catch (Exception exn) {
|
||||||
System.err.println (exn);
|
System.err.println (exn);
|
||||||
|
|||||||
@@ -23,12 +23,7 @@ local G = require "guestfs"
|
|||||||
|
|
||||||
local g = G.create ()
|
local g = G.create ()
|
||||||
|
|
||||||
file = io.open ("test.img", "w")
|
g:add_drive_scratch (500 * 1024 * 1024)
|
||||||
file:seek ("set", 500 * 1024 * 1024)
|
|
||||||
file:write (' ')
|
|
||||||
file:close ()
|
|
||||||
|
|
||||||
g:add_drive ("test.img")
|
|
||||||
|
|
||||||
g:launch ()
|
g:launch ()
|
||||||
|
|
||||||
@@ -45,5 +40,3 @@ assert (table.getn (lvs) == 2 and
|
|||||||
g:shutdown ()
|
g:shutdown ()
|
||||||
|
|
||||||
g:close ()
|
g:close ()
|
||||||
|
|
||||||
os.remove ("test.img")
|
|
||||||
|
|||||||
@@ -23,12 +23,7 @@ local G = require "guestfs"
|
|||||||
|
|
||||||
local g = G.create ()
|
local g = G.create ()
|
||||||
|
|
||||||
file = io.open ("test.img", "w")
|
g:add_drive_scratch (10 * 1024 * 1024)
|
||||||
file:seek ("set", 10 * 1024 * 1024)
|
|
||||||
file:write (' ')
|
|
||||||
file:close ()
|
|
||||||
|
|
||||||
g:add_drive ("test.img")
|
|
||||||
|
|
||||||
g:launch ()
|
g:launch ()
|
||||||
|
|
||||||
@@ -60,5 +55,3 @@ assert (dirs[5]["name"] == "q", "incorrect name in slot 5")
|
|||||||
g:shutdown ()
|
g:shutdown ()
|
||||||
|
|
||||||
g:close ()
|
g:close ()
|
||||||
|
|
||||||
os.remove ("test.img")
|
|
||||||
|
|||||||
@@ -20,12 +20,7 @@ open Unix
|
|||||||
|
|
||||||
let () =
|
let () =
|
||||||
let g = new Guestfs.guestfs () in
|
let g = new Guestfs.guestfs () in
|
||||||
|
g#add_drive_scratch (Int64.of_int (500 * 1024 * 1024));
|
||||||
let fd = openfile "test.img" [O_WRONLY;O_CREAT;O_NOCTTY;O_TRUNC] 0o666 in
|
|
||||||
ftruncate fd (500 * 1024 * 1024);
|
|
||||||
close fd;
|
|
||||||
|
|
||||||
g#add_drive "test.img";
|
|
||||||
g#launch ();
|
g#launch ();
|
||||||
|
|
||||||
g#pvcreate "/dev/sda";
|
g#pvcreate "/dev/sda";
|
||||||
@@ -58,7 +53,6 @@ let () =
|
|||||||
failwith "Guestfs.readdir returned incorrect result";
|
failwith "Guestfs.readdir returned incorrect result";
|
||||||
|
|
||||||
g#shutdown ();
|
g#shutdown ();
|
||||||
g#close ();
|
g#close ()
|
||||||
unlink "test.img"
|
|
||||||
|
|
||||||
let () = Gc.compact ()
|
let () = Gc.compact ()
|
||||||
|
|||||||
@@ -17,18 +17,13 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Test::More tests => 26;
|
use Test::More tests => 25;
|
||||||
|
|
||||||
use Sys::Guestfs;
|
use Sys::Guestfs;
|
||||||
|
|
||||||
my $g = Sys::Guestfs->new ();
|
my $g = Sys::Guestfs->new ();
|
||||||
ok ($g);
|
ok ($g);
|
||||||
open FILE, ">test.img";
|
$g->add_drive_scratch (500*1024*1024);
|
||||||
truncate FILE, 500*1024*1024;
|
|
||||||
close FILE;
|
|
||||||
ok (1);
|
|
||||||
|
|
||||||
$g->add_drive ("test.img");
|
|
||||||
ok (1);
|
ok (1);
|
||||||
|
|
||||||
$g->launch ();
|
$g->launch ();
|
||||||
@@ -76,6 +71,4 @@ $g->shutdown ();
|
|||||||
ok (1);
|
ok (1);
|
||||||
|
|
||||||
undef $g;
|
undef $g;
|
||||||
ok (1);
|
ok (1)
|
||||||
|
|
||||||
unlink ("test.img");
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Test::More tests => 15;
|
use Test::More tests => 14;
|
||||||
|
|
||||||
use Errno;
|
use Errno;
|
||||||
|
|
||||||
@@ -27,13 +27,7 @@ use Sys::Guestfs;
|
|||||||
|
|
||||||
my $g = Sys::Guestfs->new ();
|
my $g = Sys::Guestfs->new ();
|
||||||
ok ($g);
|
ok ($g);
|
||||||
|
$g->add_drive_scratch (500*1024*1024);
|
||||||
open FILE, ">test.img";
|
|
||||||
truncate FILE, 500*1024*1024;
|
|
||||||
close FILE;
|
|
||||||
ok (1);
|
|
||||||
|
|
||||||
$g->add_drive ("test.img", format => "raw");
|
|
||||||
ok (1);
|
ok (1);
|
||||||
|
|
||||||
$g->launch ();
|
$g->launch ();
|
||||||
@@ -72,5 +66,3 @@ ok ($err != Errno::EEXIST());
|
|||||||
|
|
||||||
undef $g;
|
undef $g;
|
||||||
ok (1);
|
ok (1);
|
||||||
|
|
||||||
unlink ("test.img");
|
|
||||||
|
|||||||
@@ -22,15 +22,7 @@ if ($g == false) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmp = dirname(__FILE__)."/test.img";
|
if (! guestfs_add_drive_scratch ($g, 100 * 1024 * 1024) ||
|
||||||
$size = 100 * 1024 * 1024;
|
|
||||||
if (! $fp = fopen ($tmp, 'w+')) {
|
|
||||||
die ("Error: cannot create file '".$tmp."'\n");
|
|
||||||
}
|
|
||||||
ftruncate ($fp, $size);
|
|
||||||
fclose ($fp);
|
|
||||||
|
|
||||||
if (! guestfs_add_drive ($g, $tmp) ||
|
|
||||||
! guestfs_launch ($g) ||
|
! guestfs_launch ($g) ||
|
||||||
! guestfs_part_disk ($g, "/dev/sda", "mbr") ||
|
! guestfs_part_disk ($g, "/dev/sda", "mbr") ||
|
||||||
! guestfs_pvcreate ($g, "/dev/sda1") ||
|
! guestfs_pvcreate ($g, "/dev/sda1") ||
|
||||||
@@ -52,8 +44,6 @@ if (!is_int ($version["major"]) ||
|
|||||||
echo ("Error: incorrect return type from guestfs_version\n");
|
echo ("Error: incorrect return type from guestfs_version\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink ($tmp);
|
|
||||||
|
|
||||||
echo ("OK\n");
|
echo ("OK\n");
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ import os
|
|||||||
import guestfs
|
import guestfs
|
||||||
|
|
||||||
g = guestfs.GuestFS (python_return_dict=True)
|
g = guestfs.GuestFS (python_return_dict=True)
|
||||||
f = open ("test.img", "w")
|
g.add_drive_scratch (500 * 1024 * 1024)
|
||||||
f.truncate (500 * 1024 * 1024)
|
|
||||||
f.close ()
|
|
||||||
g.add_drive ("test.img")
|
|
||||||
g.launch ()
|
g.launch ()
|
||||||
|
|
||||||
g.pvcreate ("/dev/sda")
|
g.pvcreate ("/dev/sda")
|
||||||
@@ -33,5 +30,3 @@ if (g.lvs () != ["/dev/VG/LV1", "/dev/VG/LV2"]):
|
|||||||
raise "Error: g.lvs() returned incorrect result"
|
raise "Error: g.lvs() returned incorrect result"
|
||||||
g.shutdown ()
|
g.shutdown ()
|
||||||
g.close ()
|
g.close ()
|
||||||
|
|
||||||
os.unlink ("test.img")
|
|
||||||
|
|||||||
@@ -24,11 +24,7 @@ class TestLoad < Test::Unit::TestCase
|
|||||||
def test_launch
|
def test_launch
|
||||||
g = Guestfs::create()
|
g = Guestfs::create()
|
||||||
|
|
||||||
File.open("test.img", "w") {
|
g.add_drive_scratch(500*1024*1024)
|
||||||
|f| f.seek(500*1024*1024); f.write("\0")
|
|
||||||
}
|
|
||||||
|
|
||||||
g.add_drive("test.img")
|
|
||||||
g.launch()
|
g.launch()
|
||||||
|
|
||||||
g.pvcreate("/dev/sda")
|
g.pvcreate("/dev/sda")
|
||||||
@@ -42,7 +38,5 @@ class TestLoad < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
g.sync()
|
g.sync()
|
||||||
|
|
||||||
File.unlink("test.img")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,19 +23,12 @@ require 'guestfs'
|
|||||||
class TestLoad < Test::Unit::TestCase
|
class TestLoad < Test::Unit::TestCase
|
||||||
def test_rhbz507346
|
def test_rhbz507346
|
||||||
g = Guestfs::create()
|
g = Guestfs::create()
|
||||||
|
g.add_drive_scratch(10*1024*1024)
|
||||||
File.open("test.img", "w") {
|
|
||||||
|f| f.seek(10*1024*1024); f.write("\0")
|
|
||||||
}
|
|
||||||
|
|
||||||
g.add_drive("test.img")
|
|
||||||
g.launch()
|
g.launch()
|
||||||
|
|
||||||
exception = assert_raise TypeError do
|
exception = assert_raise TypeError do
|
||||||
g.command(1)
|
g.command(1)
|
||||||
end
|
end
|
||||||
assert_match /wrong argument type Fixnum \(expected Array\)/, exception.message
|
assert_match /wrong argument type Fixnum \(expected Array\)/, exception.message
|
||||||
|
|
||||||
File.unlink("test.img")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -45,9 +45,7 @@
|
|||||||
#define DEFAULT_TIMEOUT 600
|
#define DEFAULT_TIMEOUT 600
|
||||||
|
|
||||||
static int timeout = DEFAULT_TIMEOUT;
|
static int timeout = DEFAULT_TIMEOUT;
|
||||||
static char tmpf[] = P_tmpdir "/libguestfs-test-tool-sda-XXXXXX";
|
|
||||||
|
|
||||||
static void make_files (void);
|
|
||||||
static void set_qemu (guestfs_h *g, const char *path, int use_wrapper);
|
static void set_qemu (guestfs_h *g, const char *path, int use_wrapper);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -192,8 +190,6 @@ main (int argc, char *argv[])
|
|||||||
if (qemu)
|
if (qemu)
|
||||||
set_qemu (g, qemu, qemu_use_wrapper);
|
set_qemu (g, qemu, qemu_use_wrapper);
|
||||||
|
|
||||||
make_files ();
|
|
||||||
|
|
||||||
/* Print out any environment variables which may relate to this test. */
|
/* Print out any environment variables which may relate to this test. */
|
||||||
for (i = 0; environ[i] != NULL; ++i) {
|
for (i = 0; environ[i] != NULL; ++i) {
|
||||||
if (STRPREFIX (environ[i], "LIBGUESTFS_"))
|
if (STRPREFIX (environ[i], "LIBGUESTFS_"))
|
||||||
@@ -224,12 +220,9 @@ main (int argc, char *argv[])
|
|||||||
ignore_value (system ("getenforce"));
|
ignore_value (system ("getenforce"));
|
||||||
|
|
||||||
/* Configure the handle. */
|
/* Configure the handle. */
|
||||||
if (guestfs_add_drive_opts (g, tmpf,
|
if (guestfs_add_drive_scratch (g, 100*1024*1024, -1) == -1) {
|
||||||
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
|
|
||||||
-1) == -1) {
|
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
_("libguestfs-test-tool: failed to add drive '%s'\n"),
|
_("libguestfs-test-tool: failed to add scratch drive\n"));
|
||||||
tmpf);
|
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,40 +394,3 @@ set_qemu (guestfs_h *g, const char *path, int use_wrapper)
|
|||||||
guestfs_set_qemu (g, qemuwrapper);
|
guestfs_set_qemu (g, qemuwrapper);
|
||||||
atexit (cleanup_wrapper);
|
atexit (cleanup_wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
cleanup_tmpfiles (void)
|
|
||||||
{
|
|
||||||
unlink (tmpf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
make_files (void)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
/* Allocate the sparse file for /dev/sda. */
|
|
||||||
fd = mkstemp (tmpf);
|
|
||||||
if (fd == -1) {
|
|
||||||
perror (tmpf);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lseek (fd, 100 * 1024 * 1024 - 1, SEEK_SET) == -1) {
|
|
||||||
perror ("lseek");
|
|
||||||
close (fd);
|
|
||||||
unlink (tmpf);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (write (fd, "\0", 1) == -1) {
|
|
||||||
perror ("write");
|
|
||||||
close (fd);
|
|
||||||
unlink (tmpf);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
close (fd);
|
|
||||||
|
|
||||||
atexit (cleanup_tmpfiles); /* Removes tmpf. */
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -29,12 +29,7 @@ my $g = Sys::Guestfs->new ();
|
|||||||
my $nr_files = 1000000;
|
my $nr_files = 1000000;
|
||||||
my $image_size = 2*1024*1024*1024;
|
my $image_size = 2*1024*1024*1024;
|
||||||
|
|
||||||
unlink "test.img";
|
$g->add_drive_scratch ($image_size);
|
||||||
open FILE, ">test.img" or die "test.img: $!";
|
|
||||||
truncate FILE, $image_size or die "test.img: truncate: $!";
|
|
||||||
close FILE or die "test.img: $!";
|
|
||||||
|
|
||||||
$g->add_drive ("test.img", format => "raw");
|
|
||||||
|
|
||||||
$g->launch ();
|
$g->launch ();
|
||||||
|
|
||||||
@@ -79,5 +74,3 @@ die unless @a == $nr_files;
|
|||||||
|
|
||||||
$g->shutdown ();
|
$g->shutdown ();
|
||||||
$g->close ();
|
$g->close ();
|
||||||
|
|
||||||
unlink "test.img"
|
|
||||||
|
|||||||
@@ -26,16 +26,9 @@ use Sys::Guestfs;
|
|||||||
# Allow the test to be skipped since btrfs is often broken.
|
# Allow the test to be skipped since btrfs is often broken.
|
||||||
exit 77 if $ENV{SKIP_TEST_BTRFS_SUBVOLUME_DEFAULT_PL};
|
exit 77 if $ENV{SKIP_TEST_BTRFS_SUBVOLUME_DEFAULT_PL};
|
||||||
|
|
||||||
my $testimg = "test1.img";
|
|
||||||
|
|
||||||
unlink $testimg;
|
|
||||||
open FILE, ">$testimg" or die "$testimg: $!";
|
|
||||||
truncate FILE, 1024*1024*1024 or die "$testimg: truncate: $!";
|
|
||||||
close FILE or die "$testimg: $!";
|
|
||||||
|
|
||||||
my $g = Sys::Guestfs->new ();
|
my $g = Sys::Guestfs->new ();
|
||||||
|
|
||||||
$g->add_drive ($testimg, format => "raw");
|
$g->add_drive_scratch (1024*1024*1024);
|
||||||
$g->launch ();
|
$g->launch ();
|
||||||
|
|
||||||
# If btrfs is not available, bail.
|
# If btrfs is not available, bail.
|
||||||
@@ -94,5 +87,3 @@ $g->mkdir ("/test1/foo/bar/baz");
|
|||||||
|
|
||||||
$g->shutdown ();
|
$g->shutdown ();
|
||||||
$g->close ();
|
$g->close ();
|
||||||
|
|
||||||
unlink $testimg or die "$testimg: unlink: $!";
|
|
||||||
|
|||||||
@@ -36,9 +36,8 @@ int
|
|||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
guestfs_h *g;
|
guestfs_h *g;
|
||||||
int fd, r, err;
|
int r, err;
|
||||||
struct guestfs_stat *stat;
|
struct guestfs_stat *stat;
|
||||||
const char *filename = "test1.img";
|
|
||||||
|
|
||||||
g = guestfs_create ();
|
g = guestfs_create ();
|
||||||
if (g == NULL) {
|
if (g == NULL) {
|
||||||
@@ -46,26 +45,7 @@ main (int argc, char *argv[])
|
|||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = open (filename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0666);
|
if (guestfs_add_drive_scratch (g, 524288000, -1) == -1)
|
||||||
if (fd == -1) {
|
|
||||||
perror (filename);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if (ftruncate (fd, 524288000) == -1) {
|
|
||||||
perror (filename);
|
|
||||||
close (fd);
|
|
||||||
unlink (filename);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if (close (fd) == -1) {
|
|
||||||
perror (filename);
|
|
||||||
unlink (filename);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (guestfs_add_drive_opts (g, filename,
|
|
||||||
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
|
|
||||||
-1) == -1)
|
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
|
|
||||||
if (guestfs_launch (g) == -1)
|
if (guestfs_launch (g) == -1)
|
||||||
@@ -137,7 +117,5 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
guestfs_close (g);
|
guestfs_close (g);
|
||||||
|
|
||||||
unlink (filename);
|
|
||||||
|
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,10 +47,8 @@
|
|||||||
#include "guestfs.h"
|
#include "guestfs.h"
|
||||||
#include "guestfs-internal-frontend.h"
|
#include "guestfs-internal-frontend.h"
|
||||||
|
|
||||||
static const char *filename = "test.img";
|
|
||||||
static const off_t filesize = 1024*1024*1024;
|
static const off_t filesize = 1024*1024*1024;
|
||||||
|
|
||||||
static void remove_test_img (void);
|
|
||||||
static void *start_test_thread (void *) __attribute__((noreturn));
|
static void *start_test_thread (void *) __attribute__((noreturn));
|
||||||
static off_t random_cancel_posn (void);
|
static off_t random_cancel_posn (void);
|
||||||
|
|
||||||
@@ -68,8 +66,6 @@ int
|
|||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
guestfs_h *g;
|
guestfs_h *g;
|
||||||
int fd;
|
|
||||||
char c = 0;
|
|
||||||
pthread_t test_thread;
|
pthread_t test_thread;
|
||||||
struct test_thread_data data;
|
struct test_thread_data data;
|
||||||
int fds[2], r, op_error, op_errno, errors = 0;
|
int fds[2], r, op_error, op_errno, errors = 0;
|
||||||
@@ -83,35 +79,7 @@ main (int argc, char *argv[])
|
|||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a test image and test data. */
|
if (guestfs_add_drive_scratch (g, filesize, -1) == -1)
|
||||||
fd = open (filename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, 0666);
|
|
||||||
if (fd == -1) {
|
|
||||||
perror (filename);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
atexit (remove_test_img);
|
|
||||||
|
|
||||||
if (lseek (fd, filesize - 1, SEEK_SET) == (off_t) -1) {
|
|
||||||
perror ("lseek");
|
|
||||||
close (fd);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (write (fd, &c, 1) != 1) {
|
|
||||||
perror ("write");
|
|
||||||
close (fd);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (close (fd) == -1) {
|
|
||||||
perror ("test.img");
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (guestfs_add_drive_opts (g, filename,
|
|
||||||
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
|
|
||||||
-1) == -1)
|
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
|
|
||||||
if (guestfs_launch (g) == -1)
|
if (guestfs_launch (g) == -1)
|
||||||
@@ -256,12 +224,6 @@ main (int argc, char *argv[])
|
|||||||
exit (errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
exit (errors == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
remove_test_img (void)
|
|
||||||
{
|
|
||||||
unlink (filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char buffer[BUFSIZ];
|
static char buffer[BUFSIZ];
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
|
|||||||
@@ -74,8 +74,6 @@ main (int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
guestfs_h *g;
|
guestfs_h *g;
|
||||||
char tmp[] = "/tmp/charsetXXXXXX";
|
|
||||||
int fd;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
struct filesystem *fs;
|
struct filesystem *fs;
|
||||||
|
|
||||||
@@ -91,17 +89,7 @@ main (int argc, char *argv[])
|
|||||||
if (g == NULL)
|
if (g == NULL)
|
||||||
error (EXIT_FAILURE, 0, "failed to create handle");
|
error (EXIT_FAILURE, 0, "failed to create handle");
|
||||||
|
|
||||||
fd = mkstemp (tmp);
|
if (guestfs_add_drive_scratch (g, 1024*1024*1024, -1) == -1)
|
||||||
if (fd == -1)
|
|
||||||
error (EXIT_FAILURE, errno, "mkstemp");
|
|
||||||
|
|
||||||
if (ftruncate (fd, 1024 * 1024 * 1024) == -1)
|
|
||||||
error (EXIT_FAILURE, errno, "ftruncate: %s", tmp);
|
|
||||||
|
|
||||||
if (close (fd) == -1)
|
|
||||||
error (EXIT_FAILURE, errno, "close: %s", tmp);
|
|
||||||
|
|
||||||
if (guestfs_add_drive_opts (g, tmp, -1) == -1)
|
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
|
|
||||||
if (guestfs_launch (g) == -1)
|
if (guestfs_launch (g) == -1)
|
||||||
@@ -116,7 +104,6 @@ main (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
guestfs_close (g);
|
guestfs_close (g);
|
||||||
unlink (tmp);
|
|
||||||
|
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,12 +28,8 @@ exit 77 if $ENV{SKIP_TEST_DISK_LABELS_PL};
|
|||||||
my $g = Sys::Guestfs->new ();
|
my $g = Sys::Guestfs->new ();
|
||||||
|
|
||||||
# Add two drives.
|
# Add two drives.
|
||||||
foreach (["test1.img", "a"], ["test2.img", "b"]) {
|
foreach ("a", "b") {
|
||||||
my ($output, $label) = @$_;
|
$g->add_drive_scratch (512*1024*1024, label => $_);
|
||||||
open FILE, ">$output" or die "$output: $!";
|
|
||||||
truncate FILE, 512 * 1024 * 1024 or die "$output: truncate: $!";
|
|
||||||
close FILE or die "$output: $!";
|
|
||||||
$g->add_drive ($output, readonly => 0, format => "raw", label => $label);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$g->launch ();
|
$g->launch ();
|
||||||
@@ -68,7 +64,4 @@ die unless $labels{"b1"} eq "/dev/sdb1";
|
|||||||
die unless exists $labels{"b2"};
|
die unless exists $labels{"b2"};
|
||||||
die unless $labels{"b2"} eq "/dev/sdb2";
|
die unless $labels{"b2"} eq "/dev/sdb2";
|
||||||
|
|
||||||
unlink "test1.img";
|
|
||||||
unlink "test2.img";
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
@@ -32,15 +32,7 @@ printf "max_disks is %d\n", $max_disks;
|
|||||||
# Create large number of disks.
|
# Create large number of disks.
|
||||||
my ($name, $i, $j);
|
my ($name, $i, $j);
|
||||||
for ($i = 0; $i < $max_disks; ++$i) {
|
for ($i = 0; $i < $max_disks; ++$i) {
|
||||||
$name = sprintf "test%d.img", $i;
|
$g->add_drive_scratch (1024*1024);
|
||||||
#print "adding $name => /dev/sd", drive_name($i), "\n";
|
|
||||||
|
|
||||||
unlink $name;
|
|
||||||
open FILE, ">$name" or die "$name: $!";
|
|
||||||
truncate FILE, 1024*1024 or die "$name: truncate: $!";
|
|
||||||
close FILE or die "$name: $!";
|
|
||||||
|
|
||||||
$g->add_drive ($name, format => "raw");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$g->launch ();
|
$g->launch ();
|
||||||
@@ -143,11 +135,6 @@ for ($i = 0, $j = 0; $i < $max_disks; ++$i) {
|
|||||||
$g->shutdown ();
|
$g->shutdown ();
|
||||||
$g->close ();
|
$g->close ();
|
||||||
|
|
||||||
for ($i = 0; $i < $max_disks; ++$i) {
|
|
||||||
$name = sprintf "test%d.img", $i;
|
|
||||||
unlink $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
exit ($errors == 0 ? 0 : 1);
|
exit ($errors == 0 ? 0 : 1);
|
||||||
|
|
||||||
sub drive_name
|
sub drive_name
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ $progname =~ s{.*/}{};
|
|||||||
|
|
||||||
my $trace_depth = 0;
|
my $trace_depth = 0;
|
||||||
|
|
||||||
my $testimg = "test1.img";
|
|
||||||
|
|
||||||
my $srcdir = $ENV{srcdir} || ".";
|
my $srcdir = $ENV{srcdir} || ".";
|
||||||
# Location of tests/data.
|
# Location of tests/data.
|
||||||
my $datasrcdir = $srcdir . "/../data";
|
my $datasrcdir = $srcdir . "/../data";
|
||||||
@@ -86,15 +84,6 @@ $| = 1;
|
|||||||
print "$progname: random seed: $seed\n";
|
print "$progname: random seed: $seed\n";
|
||||||
|
|
||||||
my $disksize = 1024 * 1024 * 1024;
|
my $disksize = 1024 * 1024 * 1024;
|
||||||
eval { unlink $testimg };
|
|
||||||
open FILE, ">$testimg" or die "$testimg: $!";
|
|
||||||
truncate FILE, $disksize or die "$testimg: truncate: $disksize: $!";
|
|
||||||
close FILE or die "$testimg: $!";
|
|
||||||
|
|
||||||
END {
|
|
||||||
eval { unlink $testimg }
|
|
||||||
};
|
|
||||||
|
|
||||||
my $g = Sys::Guestfs->new ();
|
my $g = Sys::Guestfs->new ();
|
||||||
|
|
||||||
# Note this is a fuzz test so the results are different each time it
|
# Note this is a fuzz test so the results are different each time it
|
||||||
@@ -102,7 +91,7 @@ my $g = Sys::Guestfs->new ();
|
|||||||
# results can be reproduced.
|
# results can be reproduced.
|
||||||
$g->set_trace (1);
|
$g->set_trace (1);
|
||||||
|
|
||||||
$g->add_drive ($testimg, format => "raw");
|
$g->add_drive_scratch ($disksize);
|
||||||
$g->launch ();
|
$g->launch ();
|
||||||
|
|
||||||
if ($iterations == 0) {
|
if ($iterations == 0) {
|
||||||
|
|||||||
@@ -22,16 +22,9 @@ use warnings;
|
|||||||
|
|
||||||
use Sys::Guestfs;
|
use Sys::Guestfs;
|
||||||
|
|
||||||
my $testimg = "test.img";
|
|
||||||
|
|
||||||
unlink $testimg;
|
|
||||||
open FILE, ">$testimg" or die "$testimg: $!";
|
|
||||||
truncate FILE, 256*1024*1024 or die "$testimg: truncate: $!";
|
|
||||||
close FILE or die "$testimg: $!";
|
|
||||||
|
|
||||||
my $g = Sys::Guestfs->new ();
|
my $g = Sys::Guestfs->new ();
|
||||||
|
|
||||||
$g->add_drive ($testimg, format => "raw");
|
$g->add_drive_scratch (256 * 1024 * 1024);
|
||||||
$g->launch ();
|
$g->launch ();
|
||||||
|
|
||||||
# Create an arrangement of PVs, VGs and LVs.
|
# Create an arrangement of PVs, VGs and LVs.
|
||||||
@@ -92,5 +85,3 @@ unless (@lvs_in_VG == 3 &&
|
|||||||
}
|
}
|
||||||
|
|
||||||
undef $g;
|
undef $g;
|
||||||
|
|
||||||
unlink $testimg or die "$testimg: unlink: $!";
|
|
||||||
|
|||||||
@@ -49,7 +49,6 @@
|
|||||||
|
|
||||||
struct thread_state {
|
struct thread_state {
|
||||||
pthread_t thread; /* Thread handle. */
|
pthread_t thread; /* Thread handle. */
|
||||||
char *filename; /* Disk image. */
|
|
||||||
char *mp; /* Mount point. */
|
char *mp; /* Mount point. */
|
||||||
int exit_status; /* Thread exit status. */
|
int exit_status; /* Thread exit status. */
|
||||||
};
|
};
|
||||||
@@ -82,7 +81,7 @@ main (int argc, char *argv[])
|
|||||||
size_t i;
|
size_t i;
|
||||||
char *skip;
|
char *skip;
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
int fd, r, errors = 0;
|
int r, errors = 0;
|
||||||
void *status;
|
void *status;
|
||||||
|
|
||||||
srandom (time (NULL));
|
srandom (time (NULL));
|
||||||
@@ -120,28 +119,7 @@ main (int argc, char *argv[])
|
|||||||
printf ("starting test with %zu threads\n", nr_threads);
|
printf ("starting test with %zu threads\n", nr_threads);
|
||||||
|
|
||||||
for (i = 0; i < nr_threads; ++i) {
|
for (i = 0; i < nr_threads; ++i) {
|
||||||
/* Create an image file and a mount point for this thread to use. */
|
/* Create a mount point for this thread to use. */
|
||||||
if (asprintf (&threads[i].filename, "test%zu.img", i) == -1)
|
|
||||||
error (EXIT_FAILURE, errno, "asprintf");
|
|
||||||
if (asprintf (&threads[i].mp, "mp%zu", i) == -1)
|
|
||||||
error (EXIT_FAILURE, errno, "asprintf");
|
|
||||||
|
|
||||||
fd = open (threads[i].filename, O_WRONLY|O_CREAT|O_NOCTTY|O_CLOEXEC, 0600);
|
|
||||||
if (fd == -1) {
|
|
||||||
cleanup_thread_state ();
|
|
||||||
error (EXIT_FAILURE, errno, "open: %s", threads[i].filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ftruncate (fd, 512*1024*1024) == -1) {
|
|
||||||
cleanup_thread_state ();
|
|
||||||
error (EXIT_FAILURE, errno, "truncate: %s", threads[i].filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (close (fd) == -1) {
|
|
||||||
cleanup_thread_state ();
|
|
||||||
error (EXIT_FAILURE, errno, "close: %s", threads[i].filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
rmdir (threads[i].mp);
|
rmdir (threads[i].mp);
|
||||||
if (mkdir (threads[i].mp, 0700) == -1) {
|
if (mkdir (threads[i].mp, 0700) == -1) {
|
||||||
cleanup_thread_state ();
|
cleanup_thread_state ();
|
||||||
@@ -196,8 +174,7 @@ start_thread (void *statevp)
|
|||||||
pthread_exit (&state->exit_status);
|
pthread_exit (&state->exit_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guestfs_add_drive_opts (g, state->filename,
|
if (guestfs_add_drive_scratch (g, 512*1024*1024, -1) == -1)
|
||||||
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", -1) == -1)
|
|
||||||
goto error;
|
goto error;
|
||||||
if (guestfs_launch (g) == -1)
|
if (guestfs_launch (g) == -1)
|
||||||
goto error;
|
goto error;
|
||||||
@@ -406,11 +383,6 @@ cleanup_thread_state (void)
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < nr_threads; ++i) {
|
for (i = 0; i < nr_threads; ++i) {
|
||||||
if (threads[i].filename) {
|
|
||||||
unlink (threads[i].filename);
|
|
||||||
free (threads[i].filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (threads[i].mp) {
|
if (threads[i].mp) {
|
||||||
guestunmount (threads[i].mp, GUESTUNMOUNT_SILENT|GUESTUNMOUNT_RMDIR);
|
guestunmount (threads[i].mp, GUESTUNMOUNT_SILENT|GUESTUNMOUNT_RMDIR);
|
||||||
free (threads[i].mp);
|
free (threads[i].mp);
|
||||||
|
|||||||
@@ -27,47 +27,22 @@
|
|||||||
#include "guestfs.h"
|
#include "guestfs.h"
|
||||||
#include "guestfs-internal-all.h"
|
#include "guestfs-internal-all.h"
|
||||||
|
|
||||||
#define IMG "test.img"
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd;
|
|
||||||
guestfs_h *g;
|
guestfs_h *g;
|
||||||
struct guestfs_internal_mountable *mountable;
|
struct guestfs_internal_mountable *mountable;
|
||||||
const char *devices[] = { "/dev/VG/LV", NULL };
|
const char *devices[] = { "/dev/VG/LV", NULL };
|
||||||
|
|
||||||
fd = open (IMG, O_WRONLY | O_CREAT | O_TRUNC, 0600);
|
|
||||||
if (fd == -1) {
|
|
||||||
perror ("open " IMG);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ftruncate (fd, 1024 * 1024 * 1024) == -1) {
|
|
||||||
perror ("truncate " IMG " 1G");
|
|
||||||
unlink (IMG);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (close (fd) == -1) {
|
|
||||||
perror ("close " IMG);
|
|
||||||
unlink (IMG);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
g = guestfs_create ();
|
g = guestfs_create ();
|
||||||
if (g == NULL) {
|
if (g == NULL) {
|
||||||
perror ("could not create handle");
|
perror ("could not create handle");
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guestfs_add_drive_opts (g, IMG,
|
if (guestfs_add_drive_scratch (g, 1024*1024*1024, -1) == -1) {
|
||||||
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
|
|
||||||
GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
|
|
||||||
-1) == -1) {
|
|
||||||
error:
|
error:
|
||||||
guestfs_close (g);
|
guestfs_close (g);
|
||||||
unlink (IMG);
|
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +88,6 @@ main (int argc, char *argv[])
|
|||||||
guestfs_free_internal_mountable (mountable);
|
guestfs_free_internal_mountable (mountable);
|
||||||
|
|
||||||
guestfs_close (g);
|
guestfs_close (g);
|
||||||
unlink (IMG);
|
|
||||||
|
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,18 +105,12 @@ my $g = Sys::Guestfs->new ();
|
|||||||
|
|
||||||
#$g->set_selinux (1) if $test_type eq "selinux";
|
#$g->set_selinux (1) if $test_type eq "selinux";
|
||||||
|
|
||||||
my $testimg = "test.img";
|
$g->add_drive_scratch (256*1024*1024);
|
||||||
open FILE, ">$testimg" or die "$testimg: $!";
|
|
||||||
truncate FILE, 256*1024*1024 or die "$testimg: truncate: $!";
|
|
||||||
close FILE or die "$testimg: $!";
|
|
||||||
|
|
||||||
$g->add_drive ($testimg, format => "raw");
|
|
||||||
$g->launch ();
|
$g->launch ();
|
||||||
|
|
||||||
unless ($g->feature_available (["linuxxattrs"])) {
|
unless ($g->feature_available (["linuxxattrs"])) {
|
||||||
print "$prog $test_type $test_via: test skipped because 'linuxxattrs' feature not available.\n";
|
print "$prog $test_type $test_via: test skipped because 'linuxxattrs' feature not available.\n";
|
||||||
$g->close ();
|
$g->close ();
|
||||||
unlink $testimg;
|
|
||||||
exit 77
|
exit 77
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +152,6 @@ if ($test_via eq "direct") {
|
|||||||
# Finish up.
|
# Finish up.
|
||||||
$g->shutdown ();
|
$g->shutdown ();
|
||||||
$g->close ();
|
$g->close ();
|
||||||
unlink $testimg or die "$testimg: $!";
|
|
||||||
|
|
||||||
exit ($errors == 0 ? 0 : 1);
|
exit ($errors == 0 ? 0 : 1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user