This involves some significant changes to this test framework.
In particular:
- Instead of just specifying $srcdir at the start of a FileIn
path, you can now specify arbitrary environment variables.
This is necessary to allow the tests to run from a tmpdir.
- Use COPYING instead of COPYING.LIB, and copy that file into
the test suite directory.
- Require the static binaries (test-command, test-pwd) in order
to run tests.
- Don't conditionalize the C++ tests. Instead if a C++ compiler
is not available then we build a "skip" script.
---
.gitignore | 3 -
Makefile.am | 4 +-
generator/actions.ml | 150 ++++++++++++++++++++++++-----------------------
generator/tests.ml | 26 ++++++++
generator/tests_c_api.ml | 9 ++-
tests/c-api/Makefile.am | 65 ++++----------------
tests/c-api/tests-main.c | 56 ++++++++++++------
tests/c-api/tests.h | 2 +-
tests/c-api/tests.mk | 71 ++++++++++++++++++++++
9 files changed, 233 insertions(+), 153 deletions(-)
create mode 100644 tests/c-api/tests.mk
diff --git a/.gitignore b/.gitignore
index e4b8881..859a264 100644
--- a/.gitignore
+++ b/.gitignore
@@ -485,16 +485,13 @@ Makefile.in
/tests/c-api/test-debug-to-file
/tests/c-api/test-environment
/tests/c-api/test-event-string
-/tests/c-api/test*.img
/tests/c-api/test-just-header
/tests/c-api/test-just-header-cxx
/tests/c-api/test-last-errno
-/tests/c-api/test.log
/tests/c-api/test-private-data
/tests/c-api/test-pwd
/tests/c-api/tests
/tests/c-api/tests.c
-/tests/c-api/test*.tmp
/tests/c-api/test-user-cancel
/tests/charsets/test-charset-fidelity
/tests/data/100kallnewlines
diff --git a/Makefile.am b/Makefile.am
index 510a97e..f6feaa8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -518,8 +518,8 @@ check-slow: build-test-guests
build-test-guests:
$(MAKE) -C tests/guests check
-# Install valgrind suppressions file in test directory.
-alltests_DATA = valgrind-suppressions
+# Install some files in the test directory.
+alltests_DATA = COPYING valgrind-suppressions
# Print subdirs.
#
diff --git a/generator/actions.ml b/generator/actions.ml
index eec3b94..fde0b25 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -2732,19 +2732,19 @@ data." };
style = RString "format", [String "filename"], [];
tests = [
InitEmpty, Always, TestResultString (
- [["disk_format"; "../data/blank-disk-1s.raw"]],
"raw"), [];
+ [["disk_format"; "$datadir/blank-disk-1s.raw"]],
"raw"), [];
InitEmpty, Always, TestResultString (
- [["disk_format"; "../data/blank-disk-1s.qcow2"]],
"qcow2"), [];
+ [["disk_format"; "$datadir/blank-disk-1s.qcow2"]],
"qcow2"), [];
InitEmpty, Always, TestResultString (
- [["disk_format"; "../data/blank-disk-1K.raw"]],
"raw"), [];
+ [["disk_format"; "$datadir/blank-disk-1K.raw"]],
"raw"), [];
InitEmpty, Always, TestResultString (
- [["disk_format"; "../data/blank-disk-1K.qcow2"]],
"qcow2"), [];
+ [["disk_format"; "$datadir/blank-disk-1K.qcow2"]],
"qcow2"), [];
InitEmpty, Always, TestResultString (
- [["disk_format"; "../data/blank-disk-1M.raw"]],
"raw"), [];
+ [["disk_format"; "$datadir/blank-disk-1M.raw"]],
"raw"), [];
InitEmpty, Always, TestResultString (
- [["disk_format"; "../data/blank-disk-1M.qcow2"]],
"qcow2"), [];
+ [["disk_format"; "$datadir/blank-disk-1M.qcow2"]],
"qcow2"), [];
InitEmpty, Always, TestResultString (
- [["disk_format"; "../data/blank-disk-with-backing.qcow2"]],
"qcow2"), [];
+ [["disk_format"; "$datadir/blank-disk-with-backing.qcow2"]],
"qcow2"), [];
];
shortdesc = "detect the disk format of a disk image";
longdesc = "\
@@ -2762,19 +2762,19 @@ See also: L<guestfs(3)/DISK IMAGE FORMATS>" };
style = RInt64 "size", [String "filename"], [];
tests = [
InitEmpty, Always, TestResult (
- [["disk_virtual_size"; "../data/blank-disk-1s.raw"]],
"ret == 512"), [];
+ [["disk_virtual_size"; "$datadir/blank-disk-1s.raw"]],
"ret == 512"), [];
InitEmpty, Always, TestResult (
- [["disk_virtual_size"; "../data/blank-disk-1s.qcow2"]],
"ret == 512"), [];
+ [["disk_virtual_size"; "$datadir/blank-disk-1s.qcow2"]],
"ret == 512"), [];
InitEmpty, Always, TestResult (
- [["disk_virtual_size"; "../data/blank-disk-1K.raw"]],
"ret == 1024"), [];
+ [["disk_virtual_size"; "$datadir/blank-disk-1K.raw"]],
"ret == 1024"), [];
InitEmpty, Always, TestResult (
- [["disk_virtual_size"; "../data/blank-disk-1K.qcow2"]],
"ret == 1024"), [];
+ [["disk_virtual_size"; "$datadir/blank-disk-1K.qcow2"]],
"ret == 1024"), [];
InitEmpty, Always, TestResult (
- [["disk_virtual_size"; "../data/blank-disk-1M.raw"]],
"ret == 1024*1024"), [];
+ [["disk_virtual_size"; "$datadir/blank-disk-1M.raw"]],
"ret == 1024*1024"), [];
InitEmpty, Always, TestResult (
- [["disk_virtual_size"; "../data/blank-disk-1M.qcow2"]],
"ret == 1024*1024"), [];
+ [["disk_virtual_size"; "$datadir/blank-disk-1M.qcow2"]],
"ret == 1024*1024"), [];
InitEmpty, Always, TestResult (
- [["disk_virtual_size";
"../data/blank-disk-with-backing.qcow2"]], "ret == 1024*1024"), [];
+ [["disk_virtual_size";
"$datadir/blank-disk-with-backing.qcow2"]], "ret == 1024*1024"), [];
];
shortdesc = "return virtual size of a disk";
longdesc = "\
@@ -2789,19 +2789,19 @@ circumstances. See L<guestfs(3)/CVE-2010-3851>." };
style = RBool "backingfile", [String "filename"], [];
tests = [
InitEmpty, Always, TestResultFalse (
- [["disk_has_backing_file"; "../data/blank-disk-1s.raw"]]),
[];
+ [["disk_has_backing_file"; "$datadir/blank-disk-1s.raw"]]),
[];
InitEmpty, Always, TestResultFalse (
- [["disk_has_backing_file"; "../data/blank-disk-1s.qcow2"]]),
[];
+ [["disk_has_backing_file"; "$datadir/blank-disk-1s.qcow2"]]),
[];
InitEmpty, Always, TestResultFalse (
- [["disk_has_backing_file"; "../data/blank-disk-1K.raw"]]),
[];
+ [["disk_has_backing_file"; "$datadir/blank-disk-1K.raw"]]),
[];
InitEmpty, Always, TestResultFalse (
- [["disk_has_backing_file"; "../data/blank-disk-1K.qcow2"]]),
[];
+ [["disk_has_backing_file"; "$datadir/blank-disk-1K.qcow2"]]),
[];
InitEmpty, Always, TestResultFalse (
- [["disk_has_backing_file"; "../data/blank-disk-1M.raw"]]),
[];
+ [["disk_has_backing_file"; "$datadir/blank-disk-1M.raw"]]),
[];
InitEmpty, Always, TestResultFalse (
- [["disk_has_backing_file"; "../data/blank-disk-1M.qcow2"]]),
[];
+ [["disk_has_backing_file"; "$datadir/blank-disk-1M.qcow2"]]),
[];
InitEmpty, Always, TestResultTrue (
- [["disk_has_backing_file";
"../data/blank-disk-with-backing.qcow2"]]), [];
+ [["disk_has_backing_file";
"$datadir/blank-disk-with-backing.qcow2"]]), [];
];
shortdesc = "return whether disk has a backing file";
longdesc = "\
@@ -4226,67 +4226,67 @@ C<guestfs_is_file>, C<guestfs_is_blockdev> (etc),
C<guestfs_is_zero>." };
tests = [
InitScratchFS, Always, TestResultString (
[["mkdir"; "/command"];
- ["upload"; "test-command";
"/command/test-command"];
+ ["upload"; "$builddir/test-command";
"/command/test-command"];
["chmod"; "0o755"; "/command/test-command"];
["command"; "/command/test-command 1"]],
"Result1"), [];
InitScratchFS, Always, TestResultString (
[["mkdir"; "/command2"];
- ["upload"; "test-command";
"/command2/test-command"];
+ ["upload"; "$builddir/test-command";
"/command2/test-command"];
["chmod"; "0o755"; "/command2/test-command"];
["command"; "/command2/test-command 2"]],
"Result2\n"), [];
InitScratchFS, Always, TestResultString (
[["mkdir"; "/command3"];
- ["upload"; "test-command";
"/command3/test-command"];
+ ["upload"; "$builddir/test-command";
"/command3/test-command"];
["chmod"; "0o755"; "/command3/test-command"];
["command"; "/command3/test-command 3"]],
"\nResult3"), [];
InitScratchFS, Always, TestResultString (
[["mkdir"; "/command4"];
- ["upload"; "test-command";
"/command4/test-command"];
+ ["upload"; "$builddir/test-command";
"/command4/test-command"];
["chmod"; "0o755"; "/command4/test-command"];
["command"; "/command4/test-command 4"]],
"\nResult4\n"), [];
InitScratchFS, Always, TestResultString (
[["mkdir"; "/command5"];
- ["upload"; "test-command";
"/command5/test-command"];
+ ["upload"; "$builddir/test-command";
"/command5/test-command"];
["chmod"; "0o755"; "/command5/test-command"];
["command"; "/command5/test-command 5"]],
"\nResult5\n\n"), [];
InitScratchFS, Always, TestResultString (
[["mkdir"; "/command6"];
- ["upload"; "test-command";
"/command6/test-command"];
+ ["upload"; "$builddir/test-command";
"/command6/test-command"];
["chmod"; "0o755"; "/command6/test-command"];
["command"; "/command6/test-command 6"]],
"\n\nResult6\n\n"), [];
InitScratchFS, Always, TestResultString (
[["mkdir"; "/command7"];
- ["upload"; "test-command";
"/command7/test-command"];
+ ["upload"; "$builddir/test-command";
"/command7/test-command"];
["chmod"; "0o755"; "/command7/test-command"];
["command"; "/command7/test-command 7"]], ""),
[];
InitScratchFS, Always, TestResultString (
[["mkdir"; "/command8"];
- ["upload"; "test-command";
"/command8/test-command"];
+ ["upload"; "$builddir/test-command";
"/command8/test-command"];
["chmod"; "0o755"; "/command8/test-command"];
["command"; "/command8/test-command 8"]], "\n"),
[];
InitScratchFS, Always, TestResultString (
[["mkdir"; "/command9"];
- ["upload"; "test-command";
"/command9/test-command"];
+ ["upload"; "$builddir/test-command";
"/command9/test-command"];
["chmod"; "0o755"; "/command9/test-command"];
["command"; "/command9/test-command 9"]], "\n\n"),
[];
InitScratchFS, Always, TestResultString (
[["mkdir"; "/command10"];
- ["upload"; "test-command";
"/command10/test-command"];
+ ["upload"; "$builddir/test-command";
"/command10/test-command"];
["chmod"; "0o755"; "/command10/test-command"];
["command"; "/command10/test-command 10"]],
"Result10-1\nResult10-2\n"), [];
InitScratchFS, Always, TestResultString (
[["mkdir"; "/command11"];
- ["upload"; "test-command";
"/command11/test-command"];
+ ["upload"; "$builddir/test-command";
"/command11/test-command"];
["chmod"; "0o755"; "/command11/test-command"];
["command"; "/command11/test-command 11"]],
"Result11-1\nResult11-2"), [];
InitScratchFS, Always, TestLastFail (
[["mkdir"; "/command12"];
- ["upload"; "test-command";
"/command12/test-command"];
+ ["upload"; "$builddir/test-command";
"/command12/test-command"];
["chmod"; "0o755"; "/command12/test-command"];
["command"; "/command12/test-command"]]), [];
InitScratchFS, Always, TestResultString (
[["mkdir"; "/pwd"];
- ["upload"; "test-pwd"; "/pwd/test-pwd"];
+ ["upload"; "$builddir/test-pwd";
"/pwd/test-pwd"];
["chmod"; "0o755"; "/pwd/test-pwd"];
["command"; "/pwd/test-pwd"]], "/"), [];
];
@@ -4330,67 +4330,67 @@ locations." };
tests = [
InitScratchFS, Always, TestResult (
[["mkdir"; "/command_lines"];
- ["upload"; "test-command";
"/command_lines/test-command"];
+ ["upload"; "$builddir/test-command";
"/command_lines/test-command"];
["chmod"; "0o755";
"/command_lines/test-command"];
["command_lines"; "/command_lines/test-command 1"]],
"is_string_list (ret, 1, \"Result1\")"), [];
InitScratchFS, Always, TestResult (
[["mkdir"; "/command_lines2"];
- ["upload"; "test-command";
"/command_lines2/test-command"];
+ ["upload"; "$builddir/test-command";
"/command_lines2/test-command"];
["chmod"; "0o755";
"/command_lines2/test-command"];
["command_lines"; "/command_lines2/test-command 2"]],
"is_string_list (ret, 1, \"Result2\")"), [];
InitScratchFS, Always, TestResult (
[["mkdir"; "/command_lines3"];
- ["upload"; "test-command";
"/command_lines3/test-command"];
+ ["upload"; "$builddir/test-command";
"/command_lines3/test-command"];
["chmod"; "0o755";
"/command_lines3/test-command"];
["command_lines"; "/command_lines3/test-command 3"]],
"is_string_list (ret, 2, \"\", \"Result3\")"), [];
InitScratchFS, Always, TestResult (
[["mkdir"; "/command_lines4"];
- ["upload"; "test-command";
"/command_lines4/test-command"];
+ ["upload"; "$builddir/test-command";
"/command_lines4/test-command"];
["chmod"; "0o755";
"/command_lines4/test-command"];
["command_lines"; "/command_lines4/test-command 4"]],
"is_string_list (ret, 2, \"\", \"Result4\")"), [];
InitScratchFS, Always, TestResult (
[["mkdir"; "/command_lines5"];
- ["upload"; "test-command";
"/command_lines5/test-command"];
+ ["upload"; "$builddir/test-command";
"/command_lines5/test-command"];
["chmod"; "0o755";
"/command_lines5/test-command"];
["command_lines"; "/command_lines5/test-command 5"]],
"is_string_list (ret, 3, \"\", \"Result5\",
\"\")"), [];
InitScratchFS, Always, TestResult (
[["mkdir"; "/command_lines6"];
- ["upload"; "test-command";
"/command_lines6/test-command"];
+ ["upload"; "$builddir/test-command";
"/command_lines6/test-command"];
["chmod"; "0o755";
"/command_lines6/test-command"];
["command_lines"; "/command_lines6/test-command 6"]],
"is_string_list (ret, 4, \"\", \"\",
\"Result6\", \"\")"), [];
InitScratchFS, Always, TestResult (
[["mkdir"; "/command_lines7"];
- ["upload"; "test-command";
"/command_lines7/test-command"];
+ ["upload"; "$builddir/test-command";
"/command_lines7/test-command"];
["chmod"; "0o755";
"/command_lines7/test-command"];
["command_lines"; "/command_lines7/test-command 7"]],
"is_string_list (ret, 0)"), [];
InitScratchFS, Always, TestResult (
[["mkdir"; "/command_lines8"];
- ["upload"; "test-command";
"/command_lines8/test-command"];
+ ["upload"; "$builddir/test-command";
"/command_lines8/test-command"];
["chmod"; "0o755";
"/command_lines8/test-command"];
["command_lines"; "/command_lines8/test-command 8"]],
"is_string_list (ret, 1, \"\")"), [];
InitScratchFS, Always, TestResult (
[["mkdir"; "/command_lines9"];
- ["upload"; "test-command";
"/command_lines9/test-command"];
+ ["upload"; "$builddir/test-command";
"/command_lines9/test-command"];
["chmod"; "0o755";
"/command_lines9/test-command"];
["command_lines"; "/command_lines9/test-command 9"]],
"is_string_list (ret, 2, \"\", \"\")"), [];
InitScratchFS, Always, TestResult (
[["mkdir"; "/command_lines10"];
- ["upload"; "test-command";
"/command_lines10/test-command"];
+ ["upload"; "$builddir/test-command";
"/command_lines10/test-command"];
["chmod"; "0o755";
"/command_lines10/test-command"];
["command_lines"; "/command_lines10/test-command 10"]],
"is_string_list (ret, 2, \"Result10-1\",
\"Result10-2\")"), [];
InitScratchFS, Always, TestResult (
[["mkdir"; "/command_lines11"];
- ["upload"; "test-command";
"/command_lines11/test-command"];
+ ["upload"; "$builddir/test-command";
"/command_lines11/test-command"];
["chmod"; "0o755";
"/command_lines11/test-command"];
["command_lines"; "/command_lines11/test-command 11"]],
"is_string_list (ret, 2, \"Result11-1\",
\"Result11-2\")"), []
@@ -4603,11 +4603,13 @@ This uses the L<blockdev(8)> command." };
progress = true; cancellable = true;
tests = [
InitScratchFS, Always, TestResultString (
- (* Pick a file from cwd which isn't likely to change. *)
[["mkdir"; "/upload"];
- ["upload"; "$srcdir/../../COPYING.LIB";
"/upload/COPYING.LIB"];
- ["checksum"; "md5"; "/upload/COPYING.LIB"]],
- Digest.to_hex (Digest.file "COPYING.LIB")), []
+ (* Pick a file from the top-level directory which is included
+ * in the external test suite.
+ *)
+ ["upload"; "$top_srcdir/COPYING";
"/upload/COPYING"];
+ ["checksum"; "md5"; "/upload/COPYING"]],
+ Digest.to_hex (Digest.file "COPYING")), []
];
shortdesc = "upload a file from the local machine";
longdesc = "\
@@ -4625,13 +4627,15 @@ See also C<guestfs_download>." };
progress = true; cancellable = true;
tests = [
InitScratchFS, Always, TestResultString (
- (* Pick a file from cwd which isn't likely to change. *)
[["mkdir"; "/download"];
- ["upload"; "$srcdir/../../COPYING.LIB";
"/download/COPYING.LIB"];
- ["download"; "/download/COPYING.LIB";
"testdownload.tmp"];
+ (* Pick a file from the top-level directory which is included
+ * in the external test suite.
+ *)
+ ["upload"; "$top_srcdir/COPYING";
"/download/COPYING"];
+ ["download"; "/download/COPYING";
"testdownload.tmp"];
["upload"; "testdownload.tmp";
"/download/upload"];
["checksum"; "md5"; "/download/upload"]],
- Digest.to_hex (Digest.file "COPYING.LIB")), []
+ Digest.to_hex (Digest.file "COPYING")), []
];
shortdesc = "download a file to the local machine";
longdesc = "\
@@ -4723,15 +4727,15 @@ To get the checksums for many files, use
C<guestfs_checksums_out>." };
tests = [
InitScratchFS, Always, TestResultString (
[["mkdir"; "/tar_in"];
- ["tar_in"; "$srcdir/../data/helloworld.tar";
"/tar_in"; "NOARG"];
+ ["tar_in"; "$datadir/helloworld.tar"; "/tar_in";
"NOARG"];
["cat"; "/tar_in/hello"]], "hello\n"), [];
InitScratchFS, Always, TestResultString (
[["mkdir"; "/tar_in_gz"];
- ["tar_in"; "$srcdir/../data/helloworld.tar.gz";
"/tar_in_gz"; "gzip"];
+ ["tar_in"; "$datadir/helloworld.tar.gz";
"/tar_in_gz"; "gzip"];
["cat"; "/tar_in_gz/hello"]], "hello\n"), [];
InitScratchFS, IfAvailable "xz", TestResultString (
[["mkdir"; "/tar_in_xz"];
- ["tar_in"; "$srcdir/../data/helloworld.tar.xz";
"/tar_in_xz"; "xz"];
+ ["tar_in"; "$datadir/helloworld.tar.xz";
"/tar_in_xz"; "xz"];
["cat"; "/tar_in_xz/hello"]], "hello\n"), []
];
shortdesc = "unpack tarfile to directory";
@@ -4788,7 +4792,7 @@ instead of user/group names.
tests = [
InitScratchFS, Always, TestResultString (
[["mkdir"; "/tgz_in"];
- ["tgz_in"; "$srcdir/../data/helloworld.tar.gz";
"/tgz_in"];
+ ["tgz_in"; "$datadir/helloworld.tar.gz";
"/tgz_in"];
["cat"; "/tgz_in/hello"]], "hello\n"), []
];
shortdesc = "unpack compressed tarball to directory";
@@ -8118,7 +8122,7 @@ or growing unnecessarily." };
tests = [
InitScratchFS, Always, TestResultString (
[["mkdir"; "/txz_in"];
- ["txz_in"; "$srcdir/../data/helloworld.tar.xz";
"/txz_in"];
+ ["txz_in"; "$datadir/helloworld.tar.xz";
"/txz_in"];
["cat"; "/txz_in/hello"]], "hello\n"), []
];
shortdesc = "unpack compressed tarball to directory";
@@ -8230,7 +8234,7 @@ types (see C<guestfs_part_get_parttype>)." };
tests = [
InitISOFS, Always, TestResult (
[["checksum_device"; "md5"; "/dev/sdd"]],
- "check_file_md5 (ret, \"../data/test.iso\") == 0"), []
+ "check_file_md5 (ret, \"$datadir/test.iso\") == 0"), []
];
shortdesc = "compute MD5, SHAx or CRC checksum of the contents of a
device";
longdesc = "\
@@ -8304,7 +8308,7 @@ to find out what it is for." };
cancellable = true;
tests = [
InitScratchFS, Always, TestResultString (
- [["base64_in"; "../data/hello.b64"; "/base64_in"];
+ [["base64_in"; "$datadir/hello.b64";
"/base64_in"];
["cat"; "/base64_in"]], "hello\n"), []
];
shortdesc = "upload base64-encoded data to file";
@@ -8850,9 +8854,9 @@ See also C<guestfs_part_to_partnum>,
C<guestfs_device_index>." };
proc_nr = Some 273;
progress = true; cancellable = true;
tests =
- (let md5 = Digest.to_hex (Digest.file "COPYING.LIB") in [
+ (let md5 = Digest.to_hex (Digest.file "COPYING") in [
InitScratchFS, Always, TestResultString (
- [["upload_offset"; "$srcdir/../../COPYING.LIB";
"/upload_offset"; "0"];
+ [["upload_offset"; "$top_srcdir/COPYING";
"/upload_offset"; "0"];
["checksum"; "md5"; "/upload_offset"]], md5),
[]
]);
shortdesc = "upload a file from the local machine with offset";
@@ -8880,17 +8884,19 @@ See also C<guestfs_upload>, C<guestfs_pwrite>."
};
proc_nr = Some 274;
progress = true; cancellable = true;
tests =
- (let md5 = Digest.to_hex (Digest.file "COPYING.LIB") in
+ (let md5 = Digest.to_hex (Digest.file "COPYING") in
let offset = string_of_int 100 in
- let size = string_of_int ((Unix.stat "COPYING.LIB").Unix.st_size - 100)
in
+ let size = string_of_int ((Unix.stat "COPYING").Unix.st_size - 100) in
[
InitScratchFS, Always, TestResultString (
- (* Pick a file from cwd which isn't likely to change. *)
[["mkdir"; "/download_offset"];
- ["upload"; "$srcdir/../../COPYING.LIB";
"/download_offset/COPYING.LIB"];
- ["download_offset"; "/download_offset/COPYING.LIB";
"testdownload.tmp"; offset; size];
- ["upload_offset"; "testdownload.tmp";
"/download_offset/COPYING.LIB"; offset];
- ["checksum"; "md5";
"/download_offset/COPYING.LIB"]], md5), []
+ (* Pick a file from the top-level directory which is included
+ * in the external test suite.
+ *)
+ ["upload"; "$top_srcdir/COPYING";
"/download_offset/COPYING"];
+ ["download_offset"; "/download_offset/COPYING";
"testdownload.tmp"; offset; size];
+ ["upload_offset"; "testdownload.tmp";
"/download_offset/COPYING"; offset];
+ ["checksum"; "md5";
"/download_offset/COPYING"]], md5), []
]);
shortdesc = "download a file to the local machine with offset and size";
longdesc = "\
@@ -10696,7 +10702,7 @@ C<guestfs_xfs_growfs> calls." };
optional = Some "hivex";
tests = [
InitScratchFS, Always, TestRun (
- [["upload"; "$srcdir/../data/minimal";
"/hivex_open"];
+ [["upload"; "$datadir/minimal"; "/hivex_open"];
["hivex_open"; "/hivex_open"; ""; "";
"false"];
["hivex_root"]; (* in this hive, it returns 0x1020 *)
["hivex_node_name"; "0x1020"];
@@ -10844,11 +10850,11 @@ See also: C<guestfs_hivex_value_utf8>." };
optional = Some "hivex";
tests = [
InitScratchFS, Always, TestRun (
- [["upload"; "$srcdir/../data/minimal";
"/hivex_commit1"];
+ [["upload"; "$datadir/minimal"; "/hivex_commit1"];
["hivex_open"; "/hivex_commit1"; ""; "";
"true"];
["hivex_commit"; "NULL"]]), [["hivex_close"]];
InitScratchFS, Always, TestResultTrue (
- [["upload"; "$srcdir/../data/minimal";
"/hivex_commit2"];
+ [["upload"; "$datadir/minimal"; "/hivex_commit2"];
["hivex_open"; "/hivex_commit2"; ""; "";
"true"];
["hivex_commit"; "/hivex_commit2_copy"];
["is_file"; "/hivex_commit2_copy"; "false"]]),
[["hivex_close"]]
diff --git a/generator/tests.ml b/generator/tests.ml
index 3882a09..53f3a17 100644
--- a/generator/tests.ml
+++ b/generator/tests.ml
@@ -32,6 +32,32 @@ let defaults = {
(* The tests in each subdirectory. *)
let tests = [
+
+ "tests/c-api", {
+ defaults with
+ check_fast = [
+ "test-just-header";
+ "test-just-header-cxx";
+ "test-add-drive-opts";
+ "test-backend-settings";
+ "test-create-handle";
+ "test-config";
+ "test-event-string";
+ "test-environment";
+ "test-private-data";
+ ];
+ check = [
+ "tests";
+ "test-last-errno";
+ "test-user-cancel";
+ "test-debug-to-file";
+ ];
+ check_programs = [
+ "test-command";
+ "test-pwd";
+ ];
+ };
+
"inspector", {
defaults with
check = [
diff --git a/generator/tests_c_api.ml b/generator/tests_c_api.ml
index 88aa07e..86bf08e 100644
--- a/generator/tests_c_api.ml
+++ b/generator/tests_c_api.ml
@@ -385,17 +385,16 @@ and generate_test_command_call ?(expect_error = false) ?test ?ret
test_name cmd=
| String _, arg, sym
| OptString _, arg, sym
| Key _, arg, sym
- | GUID _, arg, sym ->
- pr " const char *%s = \"%s\";\n" sym (c_quote arg);
+ | GUID _, arg, sym
+ | FileIn _, arg, sym ->
+ pr " CLEANUP_FREE char *%s = substitute_environment
(\"%s\");\n"
+ sym (c_quote arg)
| BufferIn _, arg, sym ->
pr " const char *%s = \"%s\";\n" sym (c_quote arg);
pr " size_t %s_size = %d;\n" sym (String.length arg)
| Int _, _, _
| Int64 _, _, _
| Bool _, _, _ -> ()
- | FileIn _, arg, sym ->
- pr " CLEANUP_FREE char *%s = substitute_srcdir (\"%s\");\n"
- sym (c_quote arg)
| FileOut _, _, _ -> ()
| StringList _, "", sym
| DeviceList _, "", sym ->
diff --git a/tests/c-api/Makefile.am b/tests/c-api/Makefile.am
index 6ea22e9..f626d50 100644
--- a/tests/c-api/Makefile.am
+++ b/tests/c-api/Makefile.am
@@ -17,62 +17,20 @@
include $(top_srcdir)/subdir-rules.mk
-generator_built = tests.c
+generator_built = tests.c tests.mk
-BUILT_SOURCES = $(generator_built)
+BUILT_SOURCES = tests.c
-EXTRA_DIST = $(BUILT_SOURCES)
+EXTRA_DIST = \
+ tests.c \
+ test-command.c \
+ test-pwd.c
-check_PROGRAMS = \
- tests \
- test-command \
- test-just-header \
- test-create-handle \
- test-config \
- test-add-drive-opts \
- test-last-errno \
- test-backend-settings \
- test-private-data \
- test-user-cancel \
- test-debug-to-file \
- test-environment \
- test-pwd \
- test-event-string
+include $(srcdir)/tests.mk
-TESTS = \
- tests \
- test-just-header \
- test-create-handle \
- test-config \
- test-add-drive-opts \
- test-last-errno \
- test-backend-settings \
- test-private-data \
- test-user-cancel \
- test-debug-to-file \
- test-environment \
- test-event-string
-
-if HAVE_CXX
-check_PROGRAMS += test-just-header-cxx
-TESTS += test-just-header-cxx
-endif
-
-# The API behind this test is not baked yet.
-#if HAVE_LIBVIRT
-#check_PROGRAMS += test-add-libvirt-dom
-#TESTS += test-add-libvirt-dom
-#endif
+# The API behind this test is not baked yet, so we only distribute the source.
EXTRA_DIST += test-add-libvirt-dom.c
-TESTS_ENVIRONMENT = \
- SKIP_TEST_COMMAND=$(shell ldd test-command | grep -sq 'not a dynamic executable'
|| echo 1) \
- SKIP_TEST_COMMAND_LINES=$(shell ldd test-command | grep -sq 'not a dynamic
executable' || echo 1) \
- SKIP_TEST_COMMAND=$(shell ldd test-pwd | grep -sq 'not a dynamic executable' ||
echo 1) \
- $(top_builddir)/run --test $(VG)
-
-#SKIP_TEST_CHECKSUM_8=$(shell if test `find ../initramfs -name squashfs.ko | wc -l` -eq
0; then echo 1; fi)
-
tests_SOURCES = \
tests.c \
tests.h \
@@ -119,6 +77,10 @@ test_just_header_cxx_CXXFLAGS = \
$(WARN_CFLAGS) $(WERROR_CFLAGS)
test_just_header_cxx_LDADD = \
$(top_builddir)/src/libguestfs.la
+else
+test-just-header-cxx:
+ echo 'exit 77' > $@
+ chmod 0755 $@
endif
test_create_handle_SOURCES = test-create-handle.c
@@ -227,6 +189,3 @@ test_event_string_LDADD = \
# $(top_builddir)/src/libguestfs.la $(LIBVIRT_LIBS) \
# $(LTLIBTHREAD) $(top_builddir)/gnulib/lib/libgnu.la
#endif
-
-check-valgrind:
- $(MAKE) VG="$(top_builddir)/run @VG@" check
diff --git a/tests/c-api/tests-main.c b/tests/c-api/tests-main.c
index e81e15e..d98445e 100644
--- a/tests/c-api/tests-main.c
+++ b/tests/c-api/tests-main.c
@@ -357,35 +357,45 @@ match_re (const char *str, const char *pattern)
return r != PCRE_ERROR_NOMATCH;
}
-/* Used for FileIn parameters in tests. If the path starts with
- * "$srcdir" then replace that with the contents of the $srcdir
- * environment variable (this is set by automake and run time). The
- * caller must free the returned string.
+/* Used for some parameters in tests. If the string starts with
+ * "$variable" then replace that with the contents of the named
+ * environment variable. The caller must free the returned string.
*/
char *
-substitute_srcdir (const char *path)
+substitute_environment (const char *str)
{
char *ret;
+ size_t len;
+ CLEANUP_FREE char *name = NULL;
+ const char *value;
- if (STRPREFIX (path, "$srcdir")) {
- const char *srcdir;
+ if (STRPREFIX (str, "$")) {
+ len = strspn (str+1,
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_");
+ if (len == 0) {
+ fprintf (stderr, "tests: invalid environment variable in string (%s)\n",
+ str);
+ exit (EXIT_FAILURE);
+ }
+ name = strndup (str+1, len);
+ if (name == NULL) {
+ perror ("strndup");
+ exit (EXIT_FAILURE);
+ }
- srcdir = getenv ("srcdir");
- if (!srcdir) {
- fprintf (stderr, "tests: environment variable $srcdir is not defined.\n"
- "Normally it is defined by automake. If you are running the\n"
- "tests directly, set $srcdir to point to the source
tests/c-api\n"
- "directory.\n");
+ value = getenv (name);
+ if (!value) {
+ fprintf (stderr, "tests: environment variable $%s is not defined.\n",
+ name);
exit (EXIT_FAILURE);
}
- if (asprintf (&ret, "%s%s", srcdir, path + 7) == -1) {
+ if (asprintf (&ret, "%s%s", value, str + 1 + len) == -1) {
perror ("asprintf");
exit (EXIT_FAILURE);
}
}
else {
- ret = strdup (path);
+ ret = strdup (str);
if (!ret) {
perror ("strdup");
exit (EXIT_FAILURE);
@@ -424,6 +434,8 @@ static guestfs_h *
create_handle (void)
{
guestfs_h *g;
+ const char *datadir;
+ CLEANUP_FREE char *test_iso = NULL;
g = guestfs_create ();
if (g == NULL) {
@@ -446,8 +458,18 @@ create_handle (void)
exit (EXIT_FAILURE);
}
- if (guestfs_add_drive_ro (g, "../data/test.iso") == -1) {
- printf ("FAIL: guestfs_add_drive_ro ../data/test.iso\n");
+ datadir = getenv ("datadir");
+ if (datadir == NULL) {
+ fprintf (stderr, "environment variable $datadir is not defined\n");
+ exit (EXIT_FAILURE);
+ }
+ if (asprintf (&test_iso, "%s/test.iso", datadir) == -1) {
+ perror ("asprintf");
+ exit (EXIT_FAILURE);
+ }
+
+ if (guestfs_add_drive_ro (g, test_iso) == -1) {
+ printf ("FAIL: guestfs_add_drive_ro $datadir/test.iso\n");
exit (EXIT_FAILURE);
}
diff --git a/tests/c-api/tests.h b/tests/c-api/tests.h
index 7959570..129aee6 100644
--- a/tests/c-api/tests.h
+++ b/tests/c-api/tests.h
@@ -43,7 +43,7 @@ extern int check_file_md5 (const char *ret, const char *filename);
extern const char *get_key (char **hash, const char *key);
extern int check_hash (char **ret, const char *key, const char *expected);
extern int match_re (const char *str, const char *pattern);
-extern char *substitute_srcdir (const char *path);
+extern char *substitute_environment (const char *str);
extern void skipped (const char *test_name, const char *fs, ...) __attribute__((format
(printf,2,3)));
#endif /* TESTS_H_ */
diff --git a/tests/c-api/tests.mk b/tests/c-api/tests.mk
new file mode 100644
index 0000000..9b52f25
--- /dev/null
+++ b/tests/c-api/tests.mk
@@ -0,0 +1,71 @@
+# libguestfs generated file
+# WARNING: THIS FILE IS GENERATED FROM:
+# generator/ *.ml
+# ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
+#
+# Copyright (C) 2009-2014 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+localtestsdir = $(alltestsdir)/tests/c-api
+
+localtests_PROGRAMS = \
+ test-add-drive-opts \
+ test-backend-settings \
+ test-command \
+ test-config \
+ test-create-handle \
+ test-debug-to-file \
+ test-environment \
+ test-event-string \
+ test-just-header \
+ test-just-header-cxx \
+ test-last-errno \
+ test-private-data \
+ test-pwd \
+ test-user-cancel \
+ tests
+
+# Note that we cannot create a simple 'check:' target since
+# automake will (silently) overrule it, so we do this instead:
+
+TESTS_ENVIRONMENT = $(top_builddir)/run
+TESTS = $(top_builddir)/test-harness
+
+check-valgrind:
+ $(top_builddir)/run $(top_builddir)/test-harness --valgrind
+
+check-direct:
+ $(top_builddir)/run $(top_builddir)/test-harness --direct
+
+check-valgrind-direct:
+ $(top_builddir)/run $(top_builddir)/test-harness --valgrind --direct
+
+check-uml:
+ $(top_builddir)/run $(top_builddir)/test-harness --uml
+
+check-valgrind-uml:
+ $(top_builddir)/run $(top_builddir)/test-harness --valgrind --uml
+
+check-with-upstream-qemu:
+ $(top_builddir)/run $(top_builddir)/test-harness --upstream-qemu
+
+check-with-upstream-libvirt:
+ $(top_builddir)/run $(top_builddir)/test-harness --upstream-libvirt
+
+check-fast:
+ $(top_builddir)/run $(top_builddir)/test-harness --fast
+
+EXTRA_DIST += tests.mk
--
2.0.4