[Libguestfs] [PATCH v4 02/17] tests/c-api: Convert the C API tests to use the test harness.

Pino Toscano ptoscano at redhat.com
Fri Aug 7 15:54:54 UTC 2015


On Thursday 06 August 2015 16:05:44 Richard W.M. Jones wrote:
> 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.

This could go already on its own.

>  - Use COPYING instead of COPYING.LIB, and copy that file into
>    the test suite directory.

s/COPYING/COPYING.LIB/ looks fine as own commit as well.

>  - 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        |  28 +++++++++
>  generator/tests_c_api.ml  |   9 ++-
>  inspector/tests.mk        |   2 +-
>  tests/c-api/Makefile.am   |  84 +++++++-------------------
>  tests/c-api/test-dlopen.c |  15 ++---
>  tests/c-api/tests-main.c  |  56 +++++++++++------
>  tests/c-api/tests.h       |   2 +-
>  tests/c-api/tests.mk      |  79 ++++++++++++++++++++++++
>  11 files changed, 257 insertions(+), 175 deletions(-)
>  create mode 100644 tests/c-api/tests.mk
> 
> diff --git a/.gitignore b/.gitignore
> index 72f8cc4..045f3de 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -508,16 +508,13 @@ Makefile.in
>  /tests/c-api/test-dlopen
>  /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 2c6c8b2..ef66d4c 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -558,8 +558,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 35af981..d2b057d 100644
> --- a/generator/actions.ml
> +++ b/generator/actions.ml
> @@ -2767,19 +2767,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 = "\
> @@ -2797,19 +2797,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 = "\
> @@ -2824,19 +2824,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 = "\
> @@ -4303,67 +4303,67 @@ C<guestfs_is_file>, C<guestfs_is_blockdev> (etc), C<guestfs_is_zero>." };
>      tests = [
>        InitScratchFS, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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"]], "/"), [];
>      ];
> @@ -4407,67 +4407,67 @@ locations." };
>      tests = [
>        InitScratchFS, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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, IfNotCrossAppliance, 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\")"), []
> @@ -4680,11 +4680,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 = "\
> @@ -4702,13 +4704,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 = "\
> @@ -4800,15 +4804,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";
> @@ -4895,7 +4899,7 @@ If set to true, POSIX ACLs are saved in the output tar.
>      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";
> @@ -8247,7 +8251,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";
> @@ -8359,7 +8363,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 = "\
> @@ -8433,7 +8437,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";
> @@ -8993,9 +8997,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";
> @@ -9023,17 +9027,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 = "\
> @@ -10881,7 +10887,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"];
> @@ -11029,11 +11035,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 4be899b..d361ef8 100644
> --- a/generator/tests.ml
> +++ b/generator/tests.ml
> @@ -32,6 +32,34 @@ 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";
> +        "test-dlopen";
> +      ];
> +      check = [
> +	"tests";
> +	"test-last-errno";
> +	"test-user-cancel";
> +	"test-debug-to-file";
> +        "test-add-libvirt-dom";
> +      ];
> +      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 1522eff..5062ce1 100644
> --- a/generator/tests_c_api.ml
> +++ b/generator/tests_c_api.ml
> @@ -403,17 +403,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/inspector/tests.mk b/inspector/tests.mk
> index 67fc0bc..714486c 100644
> --- a/inspector/tests.mk
> +++ b/inspector/tests.mk
> @@ -3,7 +3,7 @@
>  #   generator/ *.ml
>  # ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
>  #
> -# Copyright (C) 2009-2014 Red Hat Inc.
> +# Copyright (C) 2009-2015 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

I guess this file should not appear.

> diff --git a/tests/c-api/Makefile.am b/tests/c-api/Makefile.am
> index 7bfffe5..5322c5e 100644
> --- a/tests/c-api/Makefile.am
> +++ b/tests/c-api/Makefile.am
> @@ -17,68 +17,16 @@
>  
>  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
> -if HAVE_LIBDL
> -check_PROGRAMS += \
> -	test-dlopen
> -endif
> -
> -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_LIBDL
> -TESTS += \
> -	test-dlopen
> -endif
> -
> -if HAVE_CXX
> -check_PROGRAMS += test-just-header-cxx
> -TESTS += test-just-header-cxx
> -endif
> -
> -if HAVE_LIBVIRT
> -check_PROGRAMS += test-add-libvirt-dom
> -TESTS += test-add-libvirt-dom
> -endif
> -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) \

Where have these checks moved to?

> -	$(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)
> +include $(srcdir)/tests.mk
>  
>  tests_SOURCES = \
>  	tests.c \
> @@ -127,6 +75,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
> @@ -142,10 +94,13 @@ test_dlopen_SOURCES = test-dlopen.c
>  test_dlopen_CPPFLAGS = \
>  	-I$(top_srcdir)/src -I$(top_builddir)/src
>  test_dlopen_CFLAGS = \
> -	$(WARN_CFLAGS) $(WERROR_CFLAGS) \
> -	-DLIBRARY=\"$(top_builddir)/src/.libs/libguestfs.so.0\"
> +	$(WARN_CFLAGS) $(WERROR_CFLAGS)
>  test_dlopen_LDADD = \
>  	-ldl
> +else
> +test-dlopen:
> +	echo 'exit 77' > $@
> +	chmod 0755 $@
>  endif
>  
>  test_config_SOURCES = test-config.c
> @@ -251,7 +206,8 @@ test_add_libvirt_dom_LDADD = \
>  	$(top_builddir)/src/libguestfs.la $(LIBVIRT_LIBS) \
>  	$(LTLIBINTL) \
>  	$(LTLIBTHREAD) $(top_builddir)/gnulib/lib/libgnu.la
> +else
> +test-add-libvirt-dom:
> +	echo 'exit 77' > $@
> +	chmod 0755 $@
>  endif
> -
> -check-valgrind:
> -	$(MAKE) VG="$(top_builddir)/run @VG@" check
> diff --git a/tests/c-api/test-dlopen.c b/tests/c-api/test-dlopen.c
> index 3efd847..c9190b0 100644
> --- a/tests/c-api/test-dlopen.c
> +++ b/tests/c-api/test-dlopen.c
> @@ -25,6 +25,11 @@
>  #include <unistd.h>
>  #include <dlfcn.h>
>  
> +/* This is found on LD_LIBRARY_PATH set by the ./run script, or
> + * from the usual libdir.
> + */
> +#define LIBRARY "libguestfs.so.0"
> +
>  /* We don't need the <guestfs.h> header file here. */
>  typedef struct guestfs_h guestfs_h;
>  
> @@ -32,10 +37,6 @@ typedef guestfs_h *(*guestfs_create_t) (void);
>  typedef const char * (*guestfs_get_program_t) (guestfs_h *);
>  typedef void (*guestfs_close_t) (guestfs_h *);
>  
> -#ifndef LIBRARY
> -#error "-DLIBRARY was not defined"
> -#endif
> -
>  static void *
>  read_symbol (void *lib, const char *symbol)
>  {
> @@ -60,12 +61,6 @@ main (int argc, char *argv[])
>    guestfs_close_t guestfs_close;
>    guestfs_h *g;
>  
> -  if (access (LIBRARY, X_OK) == -1) {
> -    fprintf (stderr, "test skipped because %s cannot be accessed: %m\n",
> -             LIBRARY);
> -    exit (77);
> -  }
> -
>    lib = dlopen (LIBRARY, RTLD_LAZY);
>    if (lib == NULL) {
>      fprintf (stderr, "could not open %s: %s\n", LIBRARY, dlerror ());
> diff --git a/tests/c-api/tests-main.c b/tests/c-api/tests-main.c
> index 71a361a..5852125 100644
> --- a/tests/c-api/tests-main.c
> +++ b/tests/c-api/tests-main.c
> @@ -360,35 +360,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);
> @@ -433,6 +443,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) {
> @@ -455,8 +467,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 2631a5d..3e14b07 100644
> --- a/tests/c-api/tests.h
> +++ b/tests/c-api/tests.h
> @@ -44,7 +44,7 @@ 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 int using_cross_appliance (void);
> -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..999221a
> --- /dev/null
> +++ b/tests/c-api/tests.mk
> @@ -0,0 +1,79 @@
> +# libguestfs generated file
> +# WARNING: THIS FILE IS GENERATED FROM:
> +#   generator/ *.ml

This file should not appear either.

> +# ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
> +#
> +# Copyright (C) 2009-2015 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-add-libvirt-dom \
> +	test-backend-settings \
> +	test-command \
> +	test-config \
> +	test-create-handle \
> +	test-debug-to-file \
> +	test-dlopen \
> +	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-libvirt:
> +	$(top_builddir)/run $(top_builddir)/test-harness --libvirt
> +
> +check-valgrind-libvirt:
> +	$(top_builddir)/run $(top_builddir)/test-harness --valgrind --libvirt
> +
> +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
> 

Thanks,
-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20150807/b7a640c6/attachment.sig>


More information about the Libguestfs mailing list