plugins: Wire up nbd plugin support for NBD_INFO_INIT_STATE
[nbdkit/ericb.git] / tests / Makefile.am
blobca659d755eab8f7ad49e952a8583373305c4cae6
1 # nbdkit
2 # Copyright (C) 2013-2020 Red Hat Inc.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # * Neither the name of Red Hat nor the names of its contributors may be
16 # used to endorse or promote products derived from this software without
17 # specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
23 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # SUCH DAMAGE.
32 include $(top_srcdir)/common-rules.mk
34 #----------------------------------------------------------------------
35 # This directory contains most of the nbdkit tests.
37 # Test variables:
39 #   TESTS            Tests that don't have any special requirements.
41 #   LIBNBD_TESTS     Tests that link to the libnbd C library should be
42 #                    added to this variable.
44 #   LIBGUESTFS_TESTS Tests that link to libguestfs C library should be
45 #                    added to this variable.
47 # check_*, noinst_*, EXTRA_PROGRAMS: These are the usual automake
48 # variables.  Consult the automake manual for the meaning of these.
50 TESTS =
51 LIBNBD_TESTS =
52 LIBGUESTFS_TESTS =
54 check_PROGRAMS =
55 check_DATA =
56 check_SCRIPTS =
57 check_LTLIBRARIES =
58 noinst_LTLIBRARIES =
59 EXTRA_PROGRAMS =
61 # Ensure we're testing the local copy by running everything through
62 # the nbdkit helper script in the top build directory.
64 # Use the 'direct' backend, and ensure maximum libguestfs debugging.
66 # Enable libnbd debugging.
67 TESTS_ENVIRONMENT = \
68         PATH=$(abs_top_builddir):$(PATH) \
69         SRCDIR=$(srcdir) \
70         PYTHON=$(PYTHON) \
71         LIBGUESTFS_ATTACH_METHOD=appliance \
72         LIBGUESTFS_DEBUG=1 \
73         LIBGUESTFS_TRACE=1 \
74         LIBNBD_DEBUG=1 \
75         $(NULL)
77 # All files that need to go into the tarball must be added here.
78 EXTRA_DIST = \
79         generate-file-data.sh \
80         make-pki.sh \
81         make-psk.sh \
82         python-exception.py \
83         README.tests \
84         shebang.pl \
85         shebang.py \
86         shebang.rb \
87         ssh/sshd_config.in \
88         test-ansi-c.sh \
89         test-blocksize.sh \
90         test-cache.sh \
91         test-cache-max-size.sh \
92         test-cache-on-read.sh \
93         test-cacheextents.sh \
94         test-captive.sh \
95         test-cow.sh \
96         test-cow-null.sh \
97         test-cxx.sh \
98         test-data-7E.sh \
99         test-data-base64.sh \
100         test-data-extents.sh \
101         test-data-file.sh \
102         test-data-raw.sh \
103         test-debug-flags.sh \
104         test-dump-config.sh \
105         test-dump-plugin.sh \
106         test-dump-plugin-example4.sh \
107         test-eflags.sh \
108         test-error0.sh \
109         test-error10.sh \
110         test-error100.sh \
111         test-error-triggered.sh \
112         test-eval.sh \
113         test-eval-init.sh \
114         test-export-name.sh \
115         test-extentlist.sh \
116         test-file-extents.sh \
117         test-file-init.sh \
118         test-floppy.sh \
119         test-foreground.sh \
120         test-fua.sh \
121         test-full.sh \
122         test-help.sh \
123         test-help-plugin.sh \
124         test-info-address.sh \
125         test-info-base64.sh \
126         test-info-raw.sh \
127         test-info-time.sh \
128         test-info-uptime.sh \
129         test-info-conntime.sh \
130         test-ip.sh \
131         test-ip-filter.sh \
132         test-iso.sh \
133         test-layers.sh \
134         test-linuxdisk.sh \
135         test-linuxdisk-copy-out.sh \
136         test-log.sh \
137         test-long-name.sh \
138         test.lua \
139         test-memory-init.sh \
140         test-memory-largest.sh \
141         test-memory-largest-for-qemu.sh \
142         test-nbd-extents.sh \
143         test-nbd-tls.sh \
144         test-nbd-tls-psk.sh \
145         test-nbdkit-backend-debug.sh \
146         test-nofilter.sh \
147         test-nozero.sh \
148         test-null-extents.sh \
149         test_ocaml_plugin.ml \
150         test-ocaml.c \
151         test-offset2.sh \
152         test-offset-extents.sh \
153         test-parallel-file.sh \
154         test-parallel-nbd.sh \
155         test-parallel-sh.sh \
156         test-partition1.sh \
157         test-partition2.sh \
158         test-partitioning1.sh \
159         test-partitioning2.sh \
160         test-partitioning3.sh \
161         test-partitioning4.sh \
162         test-partitioning5.sh \
163         test-partitioning6.sh \
164         test-pattern.sh \
165         test-pattern-largest.sh \
166         test-pattern-largest-for-qemu.sh \
167         test-probe-filter.sh \
168         test-probe-plugin.sh \
169         test-python-exception.sh \
170         test.pl \
171         test_python.py \
172         test-python-plugin.py \
173         test-python.sh \
174         test-rate.sh \
175         test-rate-dynamic.sh \
176         test.rb \
177         test-readahead.sh \
178         test-readahead-copy.sh \
179         test-readahead-test-plugin.sh \
180         test-readahead-test-request.py \
181         test-retry.sh \
182         test-retry-extents.sh \
183         test-retry-size.sh \
184         test-retry-readonly.sh \
185         test-retry-reopen-fail.sh \
186         test-retry-zero-flags.sh \
187         test-shutdown.sh \
188         test-ssh.sh \
189         test-swap.sh \
190         test.tcl \
191         test-shebang-perl.sh \
192         test-shebang-python.sh \
193         test-shebang-ruby.sh \
194         test-shell.sh \
195         test-sh-errors.sh \
196         test-sh-extents.sh \
197         test-single.sh \
198         test-single-from-file.sh \
199         test-split-extents.sh \
200         test-start.sh \
201         test-random-sock.sh \
202         test-tls.sh \
203         test-tls-psk.sh \
204         test-truncate1.sh \
205         test-truncate2.sh \
206         test-truncate3.sh \
207         test-truncate4.sh \
208         test-truncate-extents.sh \
209         test-vddk.sh \
210         test-vddk-real.sh \
211         test-version.sh \
212         test-version-filter.sh \
213         test-version-plugin.sh \
214         test-vsock.sh \
215         test-zero.sh \
216         $(NULL)
218 #----------------------------------------------------------------------
219 # Use 'make check' to run the ordinary tests as non-root.  The
220 # following are special commands for particular scenarios:
222 # To run all the tests under valgrind, use the following rule:
223 check-valgrind:
224         NBDKIT_VALGRIND=1 $(MAKE) check
226 # To run only tests which require root, use:
227 check-root:
228         $(MAKE) check TESTS="test-file-block test-swap.sh"
230 if HAVE_VDDK
231 # Run a basic check against a real copy of VDDK.  You must set
232 # vddkdir to point to the library location, eg:
234 #   make check-vddk vddkdir=vmware-vix-disklib-distrib
235 check-vddk:
236         $(MAKE) check TESTS=test-vddk-real.sh
237 endif HAVE_VDDK
239 #----------------------------------------------------------------------
240 # Basic server command line and start-up tests.
242 TESTS += \
243         test-help.sh \
244         test-version.sh \
245         test-dump-config.sh \
246         $(NULL)
248 if HAVE_PLUGINS
250 TESTS += \
251         test-help-plugin.sh \
252         test-version-plugin.sh \
253         test-version-filter.sh \
254         test-probe-filter.sh \
255         test-probe-plugin.sh \
256         test-dump-plugin.sh \
257         test-start.sh \
258         test-single.sh \
259         test-single-from-file.sh \
260         test-captive.sh \
261         test-random-sock.sh \
262         test-tls.sh \
263         test-tls-psk.sh \
264         test-ip.sh \
265         test-vsock.sh \
266         test-socket-activation \
267         test-foreground.sh \
268         test-debug-flags.sh \
269         test-long-name.sh \
270         test-swap.sh \
271         $(NULL)
273 check_PROGRAMS += \
274         test-socket-activation \
275         $(NULL)
277 test_socket_activation_SOURCES = test-socket-activation.c
278 test_socket_activation_CPPFLAGS = \
279         -I$(top_srcdir)/common/include \
280         -I$(top_srcdir)/common/protocol \
281         $(NULL)
282 test_socket_activation_CFLAGS = $(WARNINGS_CFLAGS)
284 endif HAVE_PLUGINS
286 # Test the header files can be included on their own.
287 check_PROGRAMS += \
288         test-just-plugin-header \
289         test-just-filter-header
290         $(NULL)
291 TESTS += \
292         test-just-plugin-header \
293         test-just-filter-header
294         $(NULL)
296 test_just_plugin_header_SOURCES = \
297         test-just-plugin-header.c \
298         $(NULL)
299 test_just_plugin_header_CPPFLAGS = \
300         -I$(top_srcdir)/include \
301         $(NULL)
302 test_just_plugin_header_CFLAGS = $(WARNINGS_CFLAGS)
304 test_just_filter_header_SOURCES = \
305         test-just-filter-header.c \
306         $(NULL)
307 test_just_filter_header_CPPFLAGS = \
308         -I$(top_srcdir)/include \
309         $(NULL)
310 test_just_filter_header_CFLAGS = $(WARNINGS_CFLAGS)
312 if CAN_TEST_ANSI_C
313 # This builds a plugin using an ANSI (ISO C90) compiler to ensure that
314 # the header file is compatible.  The plugin does nothing very
315 # interesting, it's mainly a compile test.
316 TESTS += \
317         test-ansi-c.sh \
318         $(NULL)
319 # check_LTLIBRARIES won't build a shared library (see automake manual).
320 # So we have to do this and add a dependency.
321 noinst_LTLIBRARIES += test-ansi-c-plugin.la
322 test-ansi-c.sh: test-ansi-c-plugin.la
324 test_ansi_c_plugin_la_SOURCES = \
325         test-ansi-c-plugin.c \
326         $(top_srcdir)/include/nbdkit-plugin.h \
327         $(NULL)
328 test_ansi_c_plugin_la_CPPFLAGS = \
329         -std=c90 -pedantic \
330         -I$(top_srcdir)/include \
331         $(NULL)
332 test_ansi_c_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
333 # For use of the -rpath option, see:
334 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
335 test_ansi_c_plugin_la_LDFLAGS = \
336         -module -avoid-version -shared -rpath /nowhere \
337         $(NULL)
338 endif CAN_TEST_ANSI_C
340 if HAVE_CXX
341 # This builds a plugin and a filter using the C++ compiler.  They
342 # don't do anything interesting when run.
343 TESTS += \
344         test-cxx.sh \
345         $(NULL)
346 # check_LTLIBRARIES won't build a shared library (see automake manual).
347 # So we have to do this and add a dependency.
348 noinst_LTLIBRARIES += test-cxx-plugin.la test-cxx-filter.la
349 test-cxx.sh: test-cxx-plugin.la test-cxx-filter.la
351 test_cxx_plugin_la_SOURCES = \
352         test-cxx-plugin.cpp \
353         $(top_srcdir)/include/nbdkit-plugin.h \
354         $(NULL)
355 test_cxx_plugin_la_CPPFLAGS = \
356         -I$(top_srcdir)/include \
357         $(NULL)
358 test_cxx_plugin_la_CXXFLAGS = $(WARNINGS_CFLAGS)
359 # For use of the -rpath option, see:
360 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
361 test_cxx_plugin_la_LDFLAGS = \
362         -module -avoid-version -shared -rpath /nowhere \
363         $(NULL)
365 test_cxx_filter_la_SOURCES = \
366         test-cxx-filter.cpp \
367         $(top_srcdir)/include/nbdkit-filter.h \
368         $(NULL)
369 test_cxx_filter_la_CPPFLAGS = \
370         -I$(top_srcdir)/include \
371         $(NULL)
372 test_cxx_filter_la_CXXFLAGS = $(WARNINGS_CFLAGS)
373 # For use of the -rpath option, see:
374 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
375 test_cxx_filter_la_LDFLAGS = \
376         -module -avoid-version -shared -rpath /nowhere \
377         $(NULL)
378 endif HAVE_CXX
380 # Exit with parent test.
381 check_PROGRAMS += test-exit-with-parent
382 TESTS += test-exit-with-parent
384 test_exit_with_parent_SOURCES = \
385         test-exit-with-parent.c test.h \
386         $(NULL)
387 test_exit_with_parent_CPPFLAGS = \
388         -I$(top_srcdir)/common/include \
389         $(NULL)
390 test_exit_with_parent_CFLAGS = \
391         $(WARNINGS_CFLAGS) \
392         $(LIBGUESTFS_CFLAGS) \
393         $(NULL)
395 # PKI files for the TLS tests.
396 check_DATA += pki/.stamp
397 pki/.stamp: $(srcdir)/make-pki.sh
398         SRCDIR=$(srcdir) $(srcdir)/make-pki.sh
400 # PSK keys for the TLS-PSK tests.
401 check_DATA += keys.psk
402 keys.psk: $(srcdir)/make-psk.sh
403         SRCDIR=$(srcdir) $(srcdir)/make-psk.sh
405 # Keys are expensive to recreate so only delete them when we do
406 # â€˜make distclean’.
407 DISTCLEANFILES = keys.psk
408 distclean-local: distclean-local-tls
409 distclean-local-tls:
410         rm -rf pki
412 #----------------------------------------------------------------------
413 # Tests of C plugins or tests which require plugins.
415 if HAVE_PLUGINS
417 # Common data shared by multiple tests
418 check_DATA += file-data
419 CLEANFILES += file-data
420 file-data: generate-file-data.sh
421         $(srcdir)/generate-file-data.sh $@
423 # While most tests need libguestfs, testing parallel I/O is easier when
424 # using qemu-io to kick off asynchronous requests.
425 TESTS += \
426         test-parallel-file.sh \
427         test-parallel-nbd.sh \
428         test-parallel-sh.sh \
429         $(NULL)
431 # Common test library.
432 check_LTLIBRARIES += libtest.la
433 libtest_la_SOURCES = test.c test.h
434 libtest_la_CFLAGS = $(WARNINGS_CFLAGS)
436 # Basic connection test.
437 LIBNBD_TESTS += test-connect
439 test_connect_SOURCES = test-connect.c
440 test_connect_CFLAGS = $(WARNINGS_CFLAGS) $(LIBNBD_CFLAGS)
441 test_connect_LDADD = $(LIBNBD_LIBS)
443 # newstyle protocol test.
444 LIBNBD_TESTS += test-newstyle
446 test_newstyle_SOURCES = test-newstyle.c
447 test_newstyle_CFLAGS = $(WARNINGS_CFLAGS) $(LIBNBD_CFLAGS)
448 test_newstyle_LDADD = $(LIBNBD_LIBS)
450 # oldstyle protocol test.
451 LIBNBD_TESTS += test-oldstyle
453 test_oldstyle_SOURCES = test-oldstyle.c
454 test_oldstyle_CFLAGS = $(WARNINGS_CFLAGS) $(LIBNBD_CFLAGS)
455 test_oldstyle_LDADD = $(LIBNBD_LIBS)
457 # Test export flags.
458 TESTS += test-eflags.sh
460 # Test export name.
461 TESTS += test-export-name.sh
463 # common disk image shared with several tests
464 check_DATA += disk
465 CLEANFILES += disk
467 disk:
468         rm -rf disk.tmp $@ $@-t
469         mkdir disk.tmp
470         echo -n "hello,world" > disk.tmp/hello.txt
471         $(top_builddir)/nbdkit -fv -U - linuxdisk disk.tmp size=100M \
472             --run 'qemu-img convert $$nbd $@-t'
473         rm -rf disk.tmp
474         mv $@-t $@
476 # curl plugin test.
477 if HAVE_CURL
478 LIBGUESTFS_TESTS += test-curl
480 test_curl_SOURCES = \
481         test-curl.c \
482         web-server.c \
483         web-server.h \
484         test.h \
485         $(NULL)
486 test_curl_CPPFLAGS = \
487         -I$(top_srcdir)/common/utils
488 test_curl_CFLAGS = \
489         $(WARNINGS_CFLAGS) \
490         $(LIBGUESTFS_CFLAGS) \
491         $(PTHREAD_CFLAGS) \
492         $(NULL)
493 test_curl_LDFLAGS = \
494         $(top_builddir)/common/utils/libutils.la \
495         $(PTHREAD_LIBS) \
496         $(NULL)
497 test_curl_LDADD = \
498         libtest.la \
499         $(LIBGUESTFS_LIBS) \
500         $(NULL)
501 endif HAVE_CURL
503 # data plugin test.
504 LIBGUESTFS_TESTS += test-data
505 TESTS += \
506         test-data-7E.sh \
507         test-data-base64.sh \
508         test-data-extents.sh \
509         test-data-file.sh \
510         test-data-raw.sh \
511         $(NULL)
513 test_data_SOURCES = test-data.c test.h
514 test_data_CPPFLAGS = -I$(top_srcdir)/common/include
515 test_data_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
516 test_data_LDADD = libtest.la $(LIBGUESTFS_LIBS)
518 # eval plugin test.
519 TESTS += test-eval.sh test-eval-init.sh
521 # ext2 plugin test.
522 if HAVE_EXT2
523 if HAVE_GUESTFISH
525 LIBGUESTFS_TESTS += test-ext2
526 check_DATA += ext2.img
527 CLEANFILES += ext2.img
529 ext2.img: disk
530         rm -f $@ $@-t
531         guestfish \
532             sparse $@-t 2G : \
533             run : \
534             mkfs ext4 /dev/sda : \
535             mount /dev/sda / : \
536             mkdir /disks : \
537             upload $< /disks/disk.img
538         mv $@-t $@
540 test_ext2_SOURCES = test-ext2.c test.h
541 test_ext2_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
542 test_ext2_LDADD = libtest.la $(LIBGUESTFS_LIBS)
544 endif HAVE_GUESTFISH
545 endif HAVE_EXT2
547 # file plugin test.
548 LIBNBD_TESTS += test-file
549 LIBGUESTFS_TESTS += test-file-block
551 test_file_SOURCES = test-file.c
552 test_file_CFLAGS = $(WARNINGS_CFLAGS) $(LIBNBD_CFLAGS)
553 test_file_LDADD = $(LIBNBD_LIBS)
555 test_file_block_SOURCES = test-file-block.c test.h
556 test_file_block_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
557 test_file_block_LDADD = libtest.la $(LIBGUESTFS_LIBS)
559 TESTS += test-file-extents.sh test-file-init.sh
561 # floppy plugin test.
562 TESTS += test-floppy.sh
564 # full plugin test.
565 TESTS += test-full.sh
567 # gzip plugin test.
568 if HAVE_ZLIB
569 LIBGUESTFS_TESTS += test-gzip
570 check_DATA += disk.gz
571 CLEANFILES += disk.gz
573 test_gzip_SOURCES = test-gzip.c test.h
574 test_gzip_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
575 test_gzip_LDADD = libtest.la $(LIBGUESTFS_LIBS)
577 disk.gz: disk
578         rm -f $@
579         gzip -9 -c disk > $@
580 endif HAVE_ZLIB
582 # info plugin test.
583 TESTS += \
584         test-info-address.sh \
585         test-info-base64.sh \
586         test-info-raw.sh \
587         test-info-time.sh \
588         test-info-uptime.sh \
589         test-info-conntime.sh \
590         $(NULL)
592 # iso plugin test.
593 if HAVE_ISO
594 TESTS += test-iso.sh
595 endif HAVE_ISO
597 # linuxdisk plugin test.
598 TESTS += \
599         test-linuxdisk.sh \
600         test-linuxdisk-copy-out.sh \
601         $(NULL)
603 # memory plugin test.
604 LIBGUESTFS_TESTS += test-memory
605 TESTS += test-memory-largest.sh test-memory-largest-for-qemu.sh
606 TESTS += test-memory-init.sh
608 test_memory_SOURCES = test-memory.c test.h
609 test_memory_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
610 test_memory_LDADD = libtest.la $(LIBGUESTFS_LIBS)
612 # partitioning plugin test.
613 TESTS += \
614         test-partitioning1.sh \
615         test-partitioning2.sh \
616         test-partitioning3.sh \
617         test-partitioning4.sh \
618         test-partitioning5.sh \
619         test-partitioning6.sh \
620         $(NULL)
622 # pattern plugin test.
623 TESTS += \
624         test-pattern.sh \
625         test-pattern-largest.sh \
626         test-pattern-largest-for-qemu.sh \
627         $(NULL)
629 if HAVE_NBD_PLUGIN
630 # nbd plugin test.
631 LIBGUESTFS_TESTS += test-nbd
632 TESTS += \
633         test-nbd-extents.sh \
634         test-nbd-tls.sh \
635         test-nbd-tls-psk.sh \
636         $(NULL)
638 test_nbd_SOURCES = test-nbd.c test.h
639 test_nbd_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
640 test_nbd_LDADD = libtest.la $(LIBGUESTFS_LIBS)
641 endif HAVE_NBD_PLUGIN
643 # null plugin test.
644 LIBNBD_TESTS += test-null
645 TESTS += test-null-extents.sh
647 test_null_SOURCES = test-null.c
648 test_null_CFLAGS = $(WARNINGS_CFLAGS) $(LIBNBD_CFLAGS)
649 test_null_LDADD = $(LIBNBD_LIBS)
651 # random plugin test.
652 LIBNBD_TESTS += test-random
654 test_random_SOURCES = test-random.c
655 test_random_CPPFLAGS = -I $(top_srcdir)/common/include
656 test_random_CFLAGS = $(WARNINGS_CFLAGS) $(LIBNBD_CFLAGS)
657 test_random_LDADD = $(LIBNBD_LIBS)
659 # split files plugin test.
660 check_DATA += split1 split2 split3
661 CLEANFILES += split1 split2 split3
662 split1: file-data
663         rm -f $@ $@-t
664         dd if=$< of=$@-t bs=1 count=100
665         mv $@-t $@
666 split2: file-data
667         rm -f $@ $@-t
668         dd if=$< of=$@-t bs=1 count=100 skip=100
669         mv $@-t $@
670 split3: file-data
671         rm -f $@ $@-t
672         dd if=$< of=$@-t bs=1 skip=200
673         mv $@-t $@
674 LIBNBD_TESTS += test-split
676 test_split_SOURCES = test-split.c
677 test_split_CFLAGS = $(WARNINGS_CFLAGS) $(LIBNBD_CFLAGS)
678 test_split_LDADD = $(LIBNBD_LIBS)
680 TESTS += test-split-extents.sh
682 # ssh plugin test.
683 if HAVE_SSH
684 # Uses â€˜disk’ so we have to make it conditional on guestfish.
685 TESTS += test-ssh.sh
686 check_DATA += \
687         ssh/sshd_config \
688         ssh/ssh_host_rsa_key ssh/ssh_host_rsa_key.pub \
689         ssh/authorized_keys \
690         $(NULL)
691 SSH_RANDOM_PORT := $(shell bash -c 'echo $$(( 10000 + $$RANDOM ))')
692 CLEANFILES += \
693         ssh/*~ \
694         ssh/sshd_config \
695         ssh/authorized_keys \
696         $(NULL)
697 DISTCLEANFILES += \
698         ssh/ssh_host_rsa_key ssh/ssh_host_rsa_key.pub \
699         ssh/id_rsa ssh/id_rsa.pub \
700         stamp-ssh-host-key stamp-ssh-user-key \
701         $(NULL)
703 ssh/sshd_config: ssh/sshd_config.in Makefile
704         rm -f $@ $@-t
705         $(SED) \
706             -e 's,__abs_builddir__,$(abs_builddir),g' \
707             -e 's,__RANDOM_PORT__,$(SSH_RANDOM_PORT),g' \
708             < $< > $@-t
709         mv $@-t $@
711 ssh/ssh_host_rsa_key ssh/ssh_host_rsa_key.pub: stamp-ssh-host-key
712 stamp-ssh-host-key:
713         rm -f $@
714         rm -f ssh/ssh_host_rsa_key
715         rm -f ssh/ssh_host_rsa_key.pub
716         ssh-keygen -t rsa -f ssh/ssh_host_rsa_key -N ''
717         touch $@
719 ssh/authorized_keys: ssh/id_rsa.pub
720         rm -f $@ $@-t
721         cp $< $@-t
722         mv $@-t $@
724 ssh/id_rsa ssh/id_rsa.pub: stamp-ssh-user-key
725 stamp-ssh-user-key:
726         rm -f $@
727         rm -f ssh/id_rsa
728         rm -f ssh/id_rsa.pub
729         ssh-keygen -t rsa -f ssh/id_rsa -N ''
730         touch $@
731 endif HAVE_SSH
733 # streaming plugin test.
734 # Doesn't work:
735 LIBNBD_TESTS += test-streaming
737 test_streaming_SOURCES = test-streaming.c
738 test_streaming_CFLAGS = $(WARNINGS_CFLAGS) $(LIBNBD_CFLAGS)
739 test_streaming_LDADD = $(LIBNBD_LIBS)
741 if HAVE_VDDK
742 # VDDK plugin test.
743 # This only tests that the plugin can be loaded against a
744 # dummy VDDK library, it is not a detailed test.
746 # check_LTLIBRARIES won't build a shared library (see automake manual).
747 # So we have to do this and add a dependency.
748 noinst_LTLIBRARIES += libvixDiskLib.la
749 TESTS += \
750         test-vddk.sh \
751         test-vddk-real.sh \
752         $(NULL)
754 libvixDiskLib_la_SOURCES = \
755         dummy-vddk.c \
756         $(NULL)
757 libvixDiskLib_la_CPPFLAGS = \
758         -I$(top_srcdir)/plugins/vddk \
759         $(NULL)
760 libvixDiskLib_la_CXXFLAGS = $(WARNINGS_CFLAGS)
761 # For use of the -rpath option, see:
762 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
763 libvixDiskLib_la_LDFLAGS = \
764         -shared -version-number 6:0:0 -rpath /nowhere \
765         $(NULL)
766 endif HAVE_VDDK
768 # zero plugin test.
769 TESTS += test-zero.sh
771 # -D nbdkit.backend.* settings.
772 TESTS += test-nbdkit-backend-debug.sh
774 #----------------------------------------------------------------------
775 # Tests of language plugins.
777 # OCaml plugin test.
778 if HAVE_OCAML
780 LIBGUESTFS_TESTS += test-ocaml
782 # This is somewhat different from the other tests because we have
783 # to build an actual plugin here.
784 test_ocaml_SOURCES = test-ocaml.c test.h
785 test_ocaml_CFLAGS = \
786         $(WARNINGS_CFLAGS) \
787         $(LIBGUESTFS_CFLAGS) \
788         $(NULL)
789 test_ocaml_LDADD = libtest.la $(LIBGUESTFS_LIBS)
791 check_SCRIPTS += test-ocaml-plugin.so
792 test-ocaml-plugin.so: test_ocaml_plugin.cmx ../plugins/ocaml/libnbdkitocaml.la ../plugins/ocaml/NBDKit.cmi ../plugins/ocaml/NBDKit.cmx
793         $(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../plugins/ocaml \
794           -output-obj -runtime-variant _pic -o $@ \
795           NBDKit.cmx $< \
796           -cclib -L../plugins/ocaml/.libs -cclib -lnbdkitocaml
797 test_ocaml_plugin.cmx: test_ocaml_plugin.ml ../plugins/ocaml/NBDKit.cmi
798         $(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../plugins/ocaml -c $< -o $@
800 endif HAVE_OCAML
802 # perl plugin test.
803 if HAVE_PERL
805 TESTS += \
806         test-dump-plugin-example4.sh \
807         test-shebang-perl.sh \
808         $(NULL)
809 LIBGUESTFS_TESTS += test-perl
811 test_perl_SOURCES = test-lang-plugins.c test.h
812 test_perl_CFLAGS = \
813         -DLANG='"perl"' -DSCRIPT='"$(srcdir)/test.pl"' \
814         $(WARNINGS_CFLAGS) \
815         $(LIBGUESTFS_CFLAGS) \
816         $(NULL)
817 test_perl_LDADD = libtest.la $(LIBGUESTFS_LIBS)
819 endif HAVE_PERL
821 # python plugin test.
822 if HAVE_PYTHON
824 TESTS += \
825         test-python.sh \
826         test-python-exception.sh \
827         test-shebang-python.sh \
828         $(NULL)
830 endif HAVE_PYTHON
832 # Ruby plugin test.
833 if HAVE_RUBY
835 # Ruby tests are disabled.  See "WARNING" section in
836 # plugins/ruby/nbdkit-ruby-plugin.pod
838 #LIBGUESTFS_TESTS += \
839 #       test-ruby \
840 #       $(NULL)
841 #TESTS += test-shebang-ruby.sh
842 EXTRA_PROGRAMS += test-ruby
844 test_ruby_SOURCES = test-lang-plugins.c test.h
845 test_ruby_CFLAGS = \
846         -DLANG='"ruby"' -DSCRIPT='"$(srcdir)/test.rb"' \
847         $(WARNINGS_CFLAGS) \
848         $(LIBGUESTFS_CFLAGS) \
849         $(NULL)
850 test_ruby_LDADD = libtest.la $(LIBGUESTFS_LIBS)
852 endif HAVE_RUBY
854 # Shell (sh) plugin test.
855 LIBGUESTFS_TESTS += test-shell
856 check_DATA += test-shell.img
857 CLEANFILES += test-shell.img
859 test_shell_SOURCES = test-lang-plugins.c test.h
860 test_shell_CFLAGS = \
861         -DLANG='"sh"' -DSCRIPT='"$(srcdir)/test-shell.sh"' \
862         $(WARNINGS_CFLAGS) \
863         $(LIBGUESTFS_CFLAGS) \
864         $(NULL)
865 test_shell_LDADD = libtest.la $(LIBGUESTFS_LIBS)
867 test-shell.img:
868         truncate -s 1048576 $@
870 TESTS += \
871         test-sh-errors.sh \
872         test-sh-extents.sh \
873         $(NULL)
875 # Tcl plugin test.
876 if HAVE_TCL
878 LIBGUESTFS_TESTS += test-tcl
880 test_tcl_SOURCES = test-lang-plugins.c test.h
881 test_tcl_CFLAGS = \
882         -DLANG='"tcl"' -DSCRIPT='"$(srcdir)/test.tcl"' \
883         $(WARNINGS_CFLAGS) \
884         $(LIBGUESTFS_CFLAGS) \
885         $(NULL)
886 test_tcl_LDADD = libtest.la $(LIBGUESTFS_LIBS)
888 endif HAVE_TCL
890 # Lua plugin test.
891 if HAVE_LUA
893 LIBGUESTFS_TESTS += test-lua
895 test_lua_SOURCES = test-lang-plugins.c test.h
896 test_lua_CFLAGS = \
897         -DLANG='"lua"' -DSCRIPT='"$(srcdir)/test.lua"' \
898         $(WARNINGS_CFLAGS) \
899         $(LIBGUESTFS_CFLAGS) \
900         $(NULL)
901 test_lua_LDADD = libtest.la $(LIBGUESTFS_LIBS)
903 endif HAVE_LUA
905 #----------------------------------------------------------------------
906 # Tests of filters.
908 # Generic test of filter layers.
909 check_PROGRAMS += test-layers
910 TESTS += test-layers.sh test-layers
912 test_layers_SOURCES = \
913         test-layers.c \
914         $(NULL)
915 test_layers_CPPFLAGS = \
916         -I$(top_srcdir)/common/include \
917         -I$(top_srcdir)/common/protocol \
918         -I$(top_srcdir)/common/utils \
919         -I$(top_srcdir)/server \
920         $(NULL)
921 test_layers_CFLAGS = \
922         $(WARNINGS_CFLAGS) \
923         $(PTHREAD_CFLAGS) \
924         $(NULL)
925 test_layers_LDFLAGS = \
926         $(PTHREAD_LIBS) \
927         $(NULL)
928 test_layers_LDADD = \
929         $(top_builddir)/common/utils/libutils.la \
930         $(NULL)
931 test_layers_DEPENDENCIES = \
932         test-layers-plugin.la \
933         test-layers-filter1.la \
934         test-layers-filter2.la \
935         test-layers-filter3.la \
936         $(NULL)
938 # check_LTLIBRARIES won't build a shared library (see automake manual).
939 # So we have to do this and add a dependency.
940 noinst_LTLIBRARIES += \
941         test-layers-plugin.la \
942         test-layers-filter1.la \
943         test-layers-filter2.la \
944         test-layers-filter3.la \
945         $(NULL)
947 test_layers_plugin_la_SOURCES = \
948         test-layers-plugin.c \
949         $(top_srcdir)/include/nbdkit-plugin.h \
950         $(NULL)
951 test_layers_plugin_la_CPPFLAGS = -I$(top_srcdir)/include
952 test_layers_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
953 # For use of the -rpath option, see:
954 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
955 test_layers_plugin_la_LDFLAGS = \
956         -module -avoid-version -shared -rpath /nowhere \
957         $(NULL)
959 test_layers_filter1_la_SOURCES = \
960         test-layers-filter.c \
961         $(top_srcdir)/include/nbdkit-filter.h \
962         $(NULL)
963 test_layers_filter1_la_CPPFLAGS = -I$(top_srcdir)/include
964 test_layers_filter1_la_CFLAGS = $(WARNINGS_CFLAGS) -Dlayer='"filter1"'
965 # For use of the -rpath option, see:
966 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
967 test_layers_filter1_la_LDFLAGS = \
968         -module -avoid-version -shared -rpath /nowhere \
969         $(NULL)
971 test_layers_filter2_la_SOURCES = \
972         test-layers-filter.c \
973         $(top_srcdir)/include/nbdkit-filter.h \
974         $(NULL)
975 test_layers_filter2_la_CPPFLAGS = -I$(top_srcdir)/include
976 test_layers_filter2_la_CFLAGS = $(WARNINGS_CFLAGS) -Dlayer='"filter2"'
977 # For use of the -rpath option, see:
978 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
979 test_layers_filter2_la_LDFLAGS = \
980         -module -avoid-version -shared -rpath /nowhere \
981         $(NULL)
983 test_layers_filter3_la_SOURCES = \
984         test-layers-filter.c \
985         $(top_srcdir)/include/nbdkit-filter.h \
986         $(NULL)
987 test_layers_filter3_la_CPPFLAGS = -I$(top_srcdir)/include
988 test_layers_filter3_la_CFLAGS = $(WARNINGS_CFLAGS) -Dlayer='"filter3"'
989 # For use of the -rpath option, see:
990 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
991 test_layers_filter3_la_LDFLAGS = \
992         -module -avoid-version -shared -rpath /nowhere \
993         $(NULL)
995 # blocksize filter test.
996 TESTS += test-blocksize.sh
998 # cache filter test.
999 TESTS += \
1000         test-cache.sh \
1001         test-cache-on-read.sh \
1002         $(NULL)
1003 TESTS += test-cache-max-size.sh
1005 # cacheextents filter test.
1006 TESTS += test-cacheextents.sh
1008 # cow filter test.
1009 TESTS += \
1010         test-cow.sh \
1011         test-cow-null.sh \
1012         $(NULL)
1014 # delay filter tests.
1015 TESTS += test-shutdown.sh
1016 LIBNBD_TESTS += test-delay
1018 test_delay_SOURCES = test-delay.c
1019 test_delay_CFLAGS = $(WARNINGS_CFLAGS) $(LIBNBD_CFLAGS)
1020 test_delay_LDADD = $(LIBNBD_LIBS)
1022 # error filter test.
1023 TESTS += \
1024         test-error0.sh \
1025         test-error10.sh \
1026         test-error100.sh \
1027         test-error-triggered.sh \
1028         $(NULL)
1030 # extentlist filter test.
1031 TESTS += test-extentlist.sh
1033 # fua filter test.
1034 TESTS += test-fua.sh
1036 # ip filter test.
1037 TESTS += test-ip-filter.sh
1039 # log filter test.
1040 TESTS += test-log.sh
1042 # nofilter test.
1043 TESTS += test-nofilter.sh
1045 if HAVE_NBD_PLUGIN
1046 # nozero filter test.
1047 TESTS += test-nozero.sh
1048 endif HAVE_NBD_PLUGIN
1050 # offset filter test.
1051 LIBGUESTFS_TESTS += test-offset
1053 test_offset_SOURCES = test-offset.c test.h
1054 test_offset_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
1055 test_offset_LDADD = libtest.la $(LIBGUESTFS_LIBS)
1057 TESTS += \
1058         test-offset2.sh \
1059         test-offset-extents.sh \
1060         $(NULL)
1062 # partition filter test.
1063 TESTS += test-partition1.sh
1064 TESTS += test-partition2.sh
1066 # rate filter test.
1067 TESTS += \
1068         test-rate.sh \
1069         test-rate-dynamic.sh \
1070         $(NULL)
1072 # readahead filter test.
1073 TESTS += \
1074         test-readahead.sh \
1075         test-readahead-copy.sh \
1076         $(NULL)
1078 # retry filter test.
1079 TESTS += \
1080         test-retry.sh \
1081         test-retry-readonly.sh \
1082         test-retry-extents.sh \
1083         test-retry-size.sh \
1084         test-retry-reopen-fail.sh \
1085         test-retry-zero-flags.sh \
1086         $(NULL)
1088 # truncate filter tests.
1089 TESTS += \
1090         test-truncate1.sh \
1091         test-truncate2.sh \
1092         test-truncate3.sh \
1093         test-truncate4.sh \
1094         test-truncate-extents.sh \
1095         $(NULL)
1097 # xz filter test.
1098 if HAVE_LIBLZMA
1099 LIBGUESTFS_TESTS += test-xz
1100 check_DATA += disk.xz
1101 CLEANFILES += disk.xz
1103 test_xz_SOURCES = test-xz.c test.h
1104 test_xz_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
1105 test_xz_LDADD = libtest.la $(LIBGUESTFS_LIBS)
1107 disk.xz: disk
1108         rm -f $@
1109 # We choose a very small block size here only for testing.  Normally
1110 # you should choose a 16M block size.
1111         xz --best --block-size=32768 -c disk > $@
1113 # xz filter + curl.
1114 if HAVE_CURL
1115 LIBGUESTFS_TESTS += test-xz-curl
1117 test_xz_curl_SOURCES = \
1118         test-xz-curl.c \
1119         web-server.c \
1120         web-server.h \
1121         test.h \
1122         $(NULL)
1123 test_xz_curl_CPPFLAGS = \
1124         -I$(top_srcdir)/common/utils
1125 test_xz_curl_CFLAGS = \
1126         $(WARNINGS_CFLAGS) \
1127         $(LIBGUESTFS_CFLAGS) \
1128         $(PTHREAD_CFLAGS) \
1129         $(NULL)
1130 test_xz_curl_LDFLAGS = \
1131         $(top_builddir)/common/utils/libutils.la \
1132         $(PTHREAD_LIBS) \
1133         $(NULL)
1134 test_xz_curl_LDADD = \
1135         libtest.la \
1136         $(LIBGUESTFS_LIBS) \
1137         $(NULL)
1139 endif HAVE_CURL
1140 endif HAVE_LIBLZMA
1142 endif HAVE_PLUGINS
1144 #----------------------------------------------------------------------
1145 # Tests of old plugins.
1147 TESTS += \
1148         test-old-plugins-x86_64-Linux-v1.0.0.sh \
1149         test-old-plugins-x86_64-Linux-v1.2.8.sh \
1150         test-old-plugins-x86_64-Linux-v1.8.4.sh \
1151         test-old-plugins-x86_64-Linux-v1.12.8.sh \
1152         $(NULL)
1154 test-old-plugins-%.sh:
1155         rm -f $@ $@-t
1156         f=`echo "$@" | $(SED) 's/test-old-plugins-\(.*\).sh/\1/'`; \
1157         echo 'script=$@ exec $$srcdir/test-old-plugins.sh' "$$f" > $@-t
1158         chmod 0755 $@-t
1159         mv $@-t $@
1161 EXTRA_DIST += \
1162         old-plugins/README \
1163         old-plugins/*/*/*/nbdkit-file-plugin.so \
1164         test-old-plugins.sh \
1165         $(NULL)
1166 CLEANFILES += \
1167         test-old-plugins-*.sh \
1168         $(NULL)
1170 #----------------------------------------------------------------------
1172 if HAVE_LIBNBD
1173 check_PROGRAMS += $(LIBNBD_TESTS)
1174 TESTS += $(LIBNBD_TESTS)
1175 endif HAVE_LIBNBD
1177 if HAVE_LIBGUESTFS
1178 check_PROGRAMS += $(LIBGUESTFS_TESTS)
1179 TESTS += $(LIBGUESTFS_TESTS)
1180 endif HAVE_LIBGUESTFS