tests: Test retry after partial extents
[nbdkit/ericb.git] / tests / Makefile.am
blob60cba6c5cb459f3ca8f83e1790b3dc2f3ea94527
1 # nbdkit
2 # Copyright (C) 2013-2019 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 EXTRA_DIST = \
35         generate-file-data.sh \
36         generate-offset-data.sh \
37         make-pki.sh \
38         make-psk.sh \
39         python-exception.py \
40         README.tests \
41         shebang.pl \
42         shebang.py \
43         shebang.rb \
44         ssh/sshd_config.in \
45         test-ansi-c.sh \
46         test-blocksize.sh \
47         test-cache.sh \
48         test-cache-max-size.sh \
49         test-cache-on-read.sh \
50         test-cacheextents.sh \
51         test-captive.sh \
52         test-cow.sh \
53         test-cow-null.sh \
54         test-cxx.sh \
55         test-data-7E.sh \
56         test-data-base64.sh \
57         test-data-extents.sh \
58         test-data-file.sh \
59         test-data-raw.sh \
60         test-debug-flags.sh \
61         test-dump-config.sh \
62         test-dump-plugin.sh \
63         test-dump-plugin-example4.sh \
64         test-eflags.sh \
65         test-error0.sh \
66         test-error10.sh \
67         test-error100.sh \
68         test-export-name.sh \
69         test-file-extents.sh \
70         test-floppy.sh \
71         test-foreground.sh \
72         test-fua.sh \
73         test-full.sh \
74         test-help.sh \
75         test-help-plugin.sh \
76         test-info-address.sh \
77         test-info-base64.sh \
78         test-info-raw.sh \
79         test-info-time.sh \
80         test-info-uptime.sh \
81         test-info-conntime.sh \
82         test-ip.sh \
83         test-iso.sh \
84         test-layers.sh \
85         test-linuxdisk.sh \
86         test-linuxdisk-copy-out.sh \
87         test-log.sh \
88         test-long-name.sh \
89         test.lua \
90         test-memory-largest.sh \
91         test-memory-largest-for-qemu.sh \
92         test-nbd-extents.sh \
93         test-nbd-tls.sh \
94         test-nbd-tls-psk.sh \
95         test-nozero.sh \
96         test-null-extents.sh \
97         test_ocaml_plugin.ml \
98         test-ocaml.c \
99         test-offset2.sh \
100         test-offset-extents.sh \
101         test-parallel-file.sh \
102         test-parallel-nbd.sh \
103         test-parallel-sh.sh \
104         test-partition1.sh \
105         test-partition2.sh \
106         test-partitioning1.sh \
107         test-partitioning2.sh \
108         test-partitioning3.sh \
109         test-partitioning4.sh \
110         test-partitioning5.sh \
111         test-partitioning6.sh \
112         test-pattern.sh \
113         test-pattern-largest.sh \
114         test-pattern-largest-for-qemu.sh \
115         test-python-exception.sh \
116         test.pl \
117         test.py \
118         test-rate.sh \
119         test-rate-dynamic.sh \
120         test.rb \
121         test-readahead-copy.sh \
122         test-retry.sh \
123         test-retry-extents.sh \
124         test-retry-readonly.sh \
125         test-retry-reopen-fail.sh \
126         test-shutdown.sh \
127         test-ssh.sh \
128         test.tcl \
129         test-shebang-perl.sh \
130         test-shebang-python.sh \
131         test-shebang-ruby.sh \
132         test-shell.sh \
133         test-sh-errors.sh \
134         test-sh-extents.sh \
135         test-single.sh \
136         test-single-from-file.sh \
137         test-start.sh \
138         test-random-sock.sh \
139         test-tls.sh \
140         test-tls-psk.sh \
141         test-truncate1.sh \
142         test-truncate2.sh \
143         test-truncate3.sh \
144         test-truncate4.sh \
145         test-truncate-extents.sh \
146         test-vddk.sh \
147         test-vddk-real.sh \
148         test-version.sh \
149         test-version-filter.sh \
150         test-version-plugin.sh \
151         test-zero.sh \
152         $(NULL)
154 # Use 'make check' to run the ordinary tests.  To run all the tests
155 # under valgrind, use the following rule:
156 check-valgrind:
157         NBDKIT_VALGRIND=1 $(MAKE) check
159 # To run only tests which require root, use:
160 check-root:
161         $(MAKE) check TESTS="test-file-block"
163 # Run a basic check against a real copy of VDDK.  You must set
164 # vddkdir to point to the library location, eg:
166 #   make check-vddk vddkdir=vmware-vix-disklib-distrib
167 check-vddk:
168         $(MAKE) check TESTS=test-vddk-real.sh
170 #----------------------------------------------------------------------
171 # Basic server command line and start-up tests.
173 check_PROGRAMS =
174 check_DATA =
175 check_SCRIPTS =
176 check_LTLIBRARIES =
177 noinst_LTLIBRARIES =
179 # Ensure we're testing the local copy by running everything through
180 # the nbdkit helper script in the top build directory.
181 TESTS_ENVIRONMENT = PATH=$(abs_top_builddir):$(PATH) SRCDIR=$(srcdir)
183 TESTS = \
184         test-help.sh \
185         test-version.sh \
186         test-dump-config.sh \
187         $(NULL)
189 if HAVE_PLUGINS
191 TESTS += \
192         test-help-plugin.sh \
193         test-version-plugin.sh \
194         test-version-filter.sh \
195         test-dump-plugin.sh \
196         test-start.sh \
197         test-single.sh \
198         test-single-from-file.sh \
199         test-captive.sh \
200         test-random-sock.sh \
201         test-tls.sh \
202         test-tls-psk.sh \
203         test-ip.sh \
204         test-socket-activation \
205         test-foreground.sh \
206         test-debug-flags.sh \
207         test-long-name.sh \
208         $(NULL)
210 check_PROGRAMS += \
211         test-socket-activation \
212         $(NULL)
214 test_socket_activation_SOURCES = test-socket-activation.c
215 test_socket_activation_CPPFLAGS = \
216         -I$(top_srcdir)/common/protocol \
217         $(NULL)
218 test_socket_activation_CFLAGS = $(WARNINGS_CFLAGS)
220 endif HAVE_PLUGINS
222 # Test the header files can be included on their own.
223 check_PROGRAMS += \
224         test-just-plugin-header \
225         test-just-filter-header
226         $(NULL)
227 TESTS += \
228         test-just-plugin-header \
229         test-just-filter-header
230         $(NULL)
232 test_just_plugin_header_SOURCES = \
233         test-just-plugin-header.c \
234         $(NULL)
235 test_just_plugin_header_CPPFLAGS = \
236         -I$(top_srcdir)/include \
237         $(NULL)
238 test_just_plugin_header_CFLAGS = $(WARNINGS_CFLAGS)
240 test_just_filter_header_SOURCES = \
241         test-just-filter-header.c \
242         $(NULL)
243 test_just_filter_header_CPPFLAGS = \
244         -I$(top_srcdir)/include \
245         $(NULL)
246 test_just_filter_header_CFLAGS = $(WARNINGS_CFLAGS)
248 if CAN_TEST_ANSI_C
249 # This builds a plugin using an ANSI (ISO C90) compiler to ensure that
250 # the header file is compatible.  The plugin does nothing very
251 # interesting, it's mainly a compile test.
252 TESTS += \
253         test-ansi-c.sh \
254         $(NULL)
255 # check_LTLIBRARIES won't build a shared library (see automake manual).
256 # So we have to do this and add a dependency.
257 noinst_LTLIBRARIES += test-ansi-c-plugin.la
258 test-ansi-c.sh: test-ansi-c-plugin.la
260 test_ansi_c_plugin_la_SOURCES = \
261         test-ansi-c-plugin.c \
262         $(top_srcdir)/include/nbdkit-plugin.h \
263         $(NULL)
264 test_ansi_c_plugin_la_CPPFLAGS = \
265         -std=c90 -pedantic \
266         -I$(top_srcdir)/include \
267         $(NULL)
268 test_ansi_c_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
269 # For use of the -rpath option, see:
270 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
271 test_ansi_c_plugin_la_LDFLAGS = \
272         -module -avoid-version -shared -rpath /nowhere \
273         $(NULL)
274 endif CAN_TEST_ANSI_C
276 if HAVE_CXX
277 # This builds a plugin and a filter using the C++ compiler.  They
278 # don't do anything interesting when run.
279 TESTS += \
280         test-cxx.sh \
281         $(NULL)
282 # check_LTLIBRARIES won't build a shared library (see automake manual).
283 # So we have to do this and add a dependency.
284 noinst_LTLIBRARIES += test-cxx-plugin.la test-cxx-filter.la
285 test-cxx.sh: test-cxx-plugin.la test-cxx-filter.la
287 test_cxx_plugin_la_SOURCES = \
288         test-cxx-plugin.cpp \
289         $(top_srcdir)/include/nbdkit-plugin.h \
290         $(NULL)
291 test_cxx_plugin_la_CPPFLAGS = \
292         -I$(top_srcdir)/include \
293         $(NULL)
294 test_cxx_plugin_la_CXXFLAGS = $(WARNINGS_CFLAGS)
295 # For use of the -rpath option, see:
296 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
297 test_cxx_plugin_la_LDFLAGS = \
298         -module -avoid-version -shared -rpath /nowhere \
299         $(NULL)
301 test_cxx_filter_la_SOURCES = \
302         test-cxx-filter.cpp \
303         $(top_srcdir)/include/nbdkit-filter.h \
304         $(NULL)
305 test_cxx_filter_la_CPPFLAGS = \
306         -I$(top_srcdir)/include \
307         $(NULL)
308 test_cxx_filter_la_CXXFLAGS = $(WARNINGS_CFLAGS)
309 # For use of the -rpath option, see:
310 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
311 test_cxx_filter_la_LDFLAGS = \
312         -module -avoid-version -shared -rpath /nowhere \
313         $(NULL)
314 endif HAVE_CXX
316 # Exit with parent test.
317 check_PROGRAMS += test-exit-with-parent
318 TESTS += test-exit-with-parent
320 test_exit_with_parent_SOURCES = \
321         test-exit-with-parent.c test.h \
322         $(NULL)
323 test_exit_with_parent_CPPFLAGS = \
324         -I$(top_srcdir)/common/include \
325         $(NULL)
326 test_exit_with_parent_CFLAGS = \
327         $(WARNINGS_CFLAGS) \
328         $(LIBGUESTFS_CFLAGS) \
329         $(NULL)
331 # PKI files for the TLS tests.
332 check_DATA += pki/.stamp
333 pki/.stamp: $(srcdir)/make-pki.sh
334         SRCDIR=$(srcdir) $(srcdir)/make-pki.sh
336 # PSK keys for the TLS-PSK tests.
337 check_DATA += keys.psk
338 keys.psk: $(srcdir)/make-psk.sh
339         SRCDIR=$(srcdir) $(srcdir)/make-psk.sh
341 # Keys are expensive to recreate so only delete them when we do
342 # â€˜make distclean’.
343 DISTCLEANFILES = keys.psk
344 distclean-local: distclean-local-tls
345 distclean-local-tls:
346         rm -rf pki
348 #----------------------------------------------------------------------
349 # Tests of C plugins or tests which require plugins.
351 if HAVE_PLUGINS
353 # Common data shared by multiple tests
354 check_DATA += file-data
355 CLEANFILES += file-data
356 file-data: generate-file-data.sh
357         $(srcdir)/generate-file-data.sh $@
359 # While most tests need libguestfs, testing parallel I/O is easier when
360 # using qemu-io to kick off asynchronous requests.
361 TESTS += \
362         test-parallel-file.sh \
363         test-parallel-nbd.sh \
364         test-parallel-sh.sh \
365         $(NULL)
367 # Most in-depth tests need libguestfs, since that is a convenient way to
368 # drive qemu.
369 LIBGUESTFS_TESTS =
370 EXTRA_PROGRAMS =
371 if HAVE_LIBGUESTFS
372 check_PROGRAMS += $(LIBGUESTFS_TESTS)
373 TESTS += $(LIBGUESTFS_TESTS)
375 # Use the 'direct' backend, and ensure maximum libguestfs and libnbd
376 # debugging is written to the *.log files in case there is a problem.
377 TESTS_ENVIRONMENT += \
378         LIBGUESTFS_ATTACH_METHOD=appliance \
379         LIBGUESTFS_DEBUG=1 \
380         LIBGUESTFS_TRACE=1 \
381         LIBNBD_DEBUG=1 \
382         $(NULL)
384 # Common test library.
385 check_LTLIBRARIES += libtest.la
386 libtest_la_SOURCES = test.c test.h
387 libtest_la_CFLAGS = $(WARNINGS_CFLAGS)
389 # Basic connection test.
390 LIBGUESTFS_TESTS += test-connect
392 test_connect_SOURCES = test-connect.c test.h
393 test_connect_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
394 test_connect_LDADD = libtest.la $(LIBGUESTFS_LIBS)
396 # newstyle protocol test.
397 LIBGUESTFS_TESTS += test-newstyle
399 test_newstyle_SOURCES = test-newstyle.c test.h
400 test_newstyle_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
401 test_newstyle_LDADD = libtest.la $(LIBGUESTFS_LIBS)
403 # oldstyle protocol test.
404 LIBGUESTFS_TESTS += test-oldstyle
406 test_oldstyle_SOURCES = test-oldstyle.c test.h
407 test_oldstyle_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
408 test_oldstyle_LDADD = libtest.la $(LIBGUESTFS_LIBS)
410 endif HAVE_LIBGUESTFS
412 # Test export flags.
413 TESTS += test-eflags.sh
415 # Test export name.
416 TESTS += test-export-name.sh
418 # common disk image shared with several tests
419 if HAVE_GUESTFISH
420 check_DATA += disk
421 CLEANFILES += disk
423 disk:
424         rm -f $@ $@-t
425         guestfish -N $@-t=fs:ext4:100M -m /dev/sda1 \
426             write /hello.txt "hello,world"
427         mv $@-t $@
429 endif HAVE_GUESTFISH
431 # curl plugin test.
433 if HAVE_CURL
434 if HAVE_GUESTFISH
436 # curl plugin test.
437 LIBGUESTFS_TESTS += test-curl
439 test_curl_SOURCES = \
440         test-curl.c \
441         web-server.c \
442         web-server.h \
443         test.h \
444         $(NULL)
445 test_curl_CPPFLAGS = \
446         -I$(top_srcdir)/common/utils
447 test_curl_CFLAGS = \
448         $(WARNINGS_CFLAGS) \
449         $(LIBGUESTFS_CFLAGS) \
450         $(PTHREAD_CFLAGS) \
451         $(NULL)
452 test_curl_LDFLAGS = \
453         $(top_builddir)/common/utils/libutils.la \
454         $(PTHREAD_LIBS) \
455         $(NULL)
456 test_curl_LDADD = \
457         libtest.la \
458         $(LIBGUESTFS_LIBS) \
459         $(NULL)
461 endif HAVE_GUESTFISH
462 endif HAVE_CURL
464 # data plugin test.
465 LIBGUESTFS_TESTS += test-data
466 TESTS += \
467         test-data-7E.sh \
468         test-data-base64.sh \
469         test-data-extents.sh \
470         test-data-file.sh \
471         test-data-raw.sh \
472         $(NULL)
474 test_data_SOURCES = test-data.c test.h
475 test_data_CPPFLAGS = -I$(top_srcdir)/common/include
476 test_data_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
477 test_data_LDADD = libtest.la $(LIBGUESTFS_LIBS)
479 # ext2 plugin test.
480 if HAVE_EXT2
481 if HAVE_GUESTFISH
483 LIBGUESTFS_TESTS += test-ext2
484 check_DATA += ext2.img
485 CLEANFILES += ext2.img
487 ext2.img: disk
488         rm -f $@ $@-t
489         guestfish \
490             sparse $@-t 2G : \
491             run : \
492             mkfs ext4 /dev/sda : \
493             mount /dev/sda / : \
494             mkdir /disks : \
495             upload $< /disks/disk.img
496         mv $@-t $@
498 test_ext2_SOURCES = test-ext2.c test.h
499 test_ext2_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
500 test_ext2_LDADD = libtest.la $(LIBGUESTFS_LIBS)
502 endif HAVE_GUESTFISH
503 endif HAVE_EXT2
505 # file plugin test.
506 LIBGUESTFS_TESTS += test-file test-file-block
508 test_file_SOURCES = test-file.c test.h
509 test_file_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
510 test_file_LDADD = libtest.la $(LIBGUESTFS_LIBS)
512 test_file_block_SOURCES = test-file-block.c test.h
513 test_file_block_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
514 test_file_block_LDADD = libtest.la $(LIBGUESTFS_LIBS)
516 if HAVE_GUESTFISH
517 TESTS += test-file-extents.sh
518 endif HAVE_GUESTFISH
520 # floppy plugin test.
521 if HAVE_GUESTFISH
522 TESTS += test-floppy.sh
523 endif HAVE_GUESTFISH
525 # full plugin test.
526 TESTS += test-full.sh
528 # gzip plugin test.
529 if HAVE_ZLIB
530 if HAVE_GUESTFISH
532 LIBGUESTFS_TESTS += test-gzip
533 check_DATA += disk.gz
534 CLEANFILES += disk.gz
536 test_gzip_SOURCES = test-gzip.c test.h
537 test_gzip_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
538 test_gzip_LDADD = libtest.la $(LIBGUESTFS_LIBS)
540 disk.gz: disk
541         rm -f $@
542         gzip -9 -c disk > $@
544 endif HAVE_GUESTFISH
545 endif HAVE_ZLIB
547 # info plugin test.
548 TESTS += \
549         test-info-address.sh \
550         test-info-base64.sh \
551         test-info-raw.sh \
552         test-info-time.sh \
553         test-info-uptime.sh \
554         test-info-conntime.sh \
555         $(NULL)
557 # iso plugin test.
558 if HAVE_ISO
559 if HAVE_GUESTFISH
561 TESTS += test-iso.sh
563 endif HAVE_GUESTFISH
564 endif HAVE_ISO
566 # linuxdisk plugin test.
567 if HAVE_GUESTFISH
568 TESTS += \
569         test-linuxdisk.sh \
570         test-linuxdisk-copy-out.sh \
571         $(NULL)
572 endif HAVE_GUESTFISH
574 # memory plugin test.
575 LIBGUESTFS_TESTS += test-memory
576 TESTS += test-memory-largest.sh test-memory-largest-for-qemu.sh
578 test_memory_SOURCES = test-memory.c test.h
579 test_memory_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
580 test_memory_LDADD = libtest.la $(LIBGUESTFS_LIBS)
582 # partitioning plugin test.
583 TESTS += \
584         test-partitioning1.sh \
585         test-partitioning4.sh \
586         test-partitioning6.sh \
587         $(NULL)
588 if HAVE_GUESTFISH
589 TESTS += \
590         test-partitioning2.sh \
591         test-partitioning3.sh \
592         test-partitioning5.sh \
593         $(NULL)
594 endif HAVE_GUESTFISH
596 # pattern plugin test.
597 TESTS += \
598         test-pattern.sh \
599         test-pattern-largest.sh \
600         test-pattern-largest-for-qemu.sh \
601         $(NULL)
603 # nbd plugin test.
604 LIBGUESTFS_TESTS += test-nbd
605 TESTS += \
606         test-nbd-extents.sh \
607         test-nbd-tls.sh \
608         test-nbd-tls-psk.sh \
609         $(NULL)
611 test_nbd_SOURCES = test-nbd.c test.h
612 test_nbd_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
613 test_nbd_LDADD = libtest.la $(LIBGUESTFS_LIBS)
615 # null plugin test.
616 LIBGUESTFS_TESTS += test-null
617 TESTS += test-null-extents.sh
619 test_null_SOURCES = test-null.c test.h
620 test_null_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
621 test_null_LDADD = libtest.la $(LIBGUESTFS_LIBS)
623 # random plugin test.
624 LIBGUESTFS_TESTS += test-random
626 test_random_SOURCES = test-random.c test.h
627 test_random_CPPFLAGS = -I $(top_srcdir)/common/include
628 test_random_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
629 test_random_LDADD = libtest.la $(LIBGUESTFS_LIBS)
631 # split files plugin test.
632 check_DATA += split1 split2 split3
633 CLEANFILES += split1 split2 split3
634 split1: file-data
635         rm -f $@ $@-t
636         dd if=$< of=$@-t bs=1 count=100
637         mv $@-t $@
638 split2: file-data
639         rm -f $@ $@-t
640         dd if=$< of=$@-t bs=1 count=100 skip=100
641         mv $@-t $@
642 split3: file-data
643         rm -f $@ $@-t
644         dd if=$< of=$@-t bs=1 skip=200
645         mv $@-t $@
646 LIBGUESTFS_TESTS += test-split
648 test_split_SOURCES = test-split.c test.h
649 test_split_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
650 test_split_LDADD = libtest.la $(LIBGUESTFS_LIBS)
652 # ssh plugin test.
653 if HAVE_SSH
654 # Uses â€˜disk’ so we have to make it conditional on guestfish.
655 if HAVE_GUESTFISH
656 TESTS += test-ssh.sh
657 endif HAVE_GUESTFISH
658 check_DATA += \
659         ssh/sshd_config \
660         ssh/ssh_host_rsa_key ssh/ssh_host_rsa_key.pub \
661         ssh/authorized_keys \
662         $(NULL)
663 SSH_RANDOM_PORT := $(shell bash -c 'echo $$(( 10000 + $$RANDOM ))')
664 CLEANFILES += \
665         ssh/*~ \
666         ssh/sshd_config \
667         ssh/authorized_keys \
668         $(NULL)
669 DISTCLEANFILES += \
670         ssh/ssh_host_rsa_key ssh/ssh_host_rsa_key.pub \
671         ssh/id_rsa ssh/id_rsa.pub \
672         stamp-ssh-host-key stamp-ssh-user-key \
673         $(NULL)
675 ssh/sshd_config: ssh/sshd_config.in Makefile
676         rm -f $@ $@-t
677         $(SED) \
678             -e 's,__abs_builddir__,$(abs_builddir),g' \
679             -e 's,__RANDOM_PORT__,$(SSH_RANDOM_PORT),g' \
680             < $< > $@-t
681         mv $@-t $@
683 ssh/ssh_host_rsa_key ssh/ssh_host_rsa_key.pub: stamp-ssh-host-key
684 stamp-ssh-host-key:
685         rm -f $@
686         rm -f ssh/ssh_host_rsa_key
687         rm -f ssh/ssh_host_rsa_key.pub
688         ssh-keygen -t rsa -f ssh/ssh_host_rsa_key -N ''
689         touch $@
691 ssh/authorized_keys: ssh/id_rsa.pub
692         rm -f $@ $@-t
693         cp $< $@-t
694         mv $@-t $@
696 ssh/id_rsa ssh/id_rsa.pub: stamp-ssh-user-key
697 stamp-ssh-user-key:
698         rm -f $@
699         rm -f ssh/id_rsa
700         rm -f ssh/id_rsa.pub
701         ssh-keygen -t rsa -f ssh/id_rsa -N ''
702         touch $@
703 endif HAVE_SSH
705 # streaming plugin test.
706 # Doesn't work:
707 #LIBGUESTFS_TESTS += test-streaming
708 EXTRA_PROGRAMS += test-streaming
710 test_streaming_SOURCES = test-streaming.c test.h
711 test_streaming_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
712 test_streaming_LDADD = libtest.la $(LIBGUESTFS_LIBS)
714 # VDDK plugin test.
715 # This only tests that the plugin can be loaded against a
716 # dummy VDDK library, it is not a detailed test.
718 # check_LTLIBRARIES won't build a shared library (see automake manual).
719 # So we have to do this and add a dependency.
720 noinst_LTLIBRARIES += libvixDiskLib.la
721 TESTS += \
722         test-vddk.sh \
723         test-vddk-real.sh \
724         $(NULL)
726 libvixDiskLib_la_SOURCES = \
727         dummy-vddk.c \
728         $(NULL)
729 libvixDiskLib_la_CPPFLAGS = \
730         -I$(top_srcdir)/plugins/vddk \
731         $(NULL)
732 libvixDiskLib_la_CXXFLAGS = $(WARNINGS_CFLAGS)
733 # For use of the -rpath option, see:
734 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
735 libvixDiskLib_la_LDFLAGS = \
736         -shared -version-number 6:0:0 -rpath /nowhere \
737         $(NULL)
739 # zero plugin test.
740 TESTS += test-zero.sh
742 #----------------------------------------------------------------------
743 # Tests of language plugins.
745 # OCaml plugin test.
746 if HAVE_OCAML
748 LIBGUESTFS_TESTS += test-ocaml
750 # This is somewhat different from the other tests because we have
751 # to build an actual plugin here.
752 test_ocaml_SOURCES = test-ocaml.c test.h
753 test_ocaml_CFLAGS = \
754         $(WARNINGS_CFLAGS) \
755         $(LIBGUESTFS_CFLAGS) \
756         $(NULL)
757 test_ocaml_LDADD = libtest.la $(LIBGUESTFS_LIBS)
759 check_SCRIPTS += test-ocaml-plugin.so
760 test-ocaml-plugin.so: test_ocaml_plugin.cmx ../plugins/ocaml/libnbdkitocaml.la ../plugins/ocaml/NBDKit.cmi ../plugins/ocaml/NBDKit.cmx
761         $(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../plugins/ocaml \
762           -output-obj -runtime-variant _pic -o $@ \
763           NBDKit.cmx $< \
764           -cclib -L../plugins/ocaml/.libs -cclib -lnbdkitocaml
765 test_ocaml_plugin.cmx: test_ocaml_plugin.ml ../plugins/ocaml/NBDKit.cmi
766         $(OCAMLOPT) $(OCAMLOPTFLAGS) -I ../plugins/ocaml -c $< -o $@
768 endif HAVE_OCAML
770 # perl plugin test.
771 if HAVE_PERL
773 TESTS += \
774         test-dump-plugin-example4.sh \
775         test-shebang-perl.sh \
776         $(NULL)
777 LIBGUESTFS_TESTS += test-perl
779 test_perl_SOURCES = test-lang-plugins.c test.h
780 test_perl_CFLAGS = \
781         -DLANG='"perl"' -DSCRIPT='"$(srcdir)/test.pl"' \
782         $(WARNINGS_CFLAGS) \
783         $(LIBGUESTFS_CFLAGS) \
784         $(NULL)
785 test_perl_LDADD = libtest.la $(LIBGUESTFS_LIBS)
787 endif HAVE_PERL
789 # python plugin test.
790 if HAVE_PYTHON
792 TESTS += \
793         test-python-exception.sh \
794         test-shebang-python.sh \
795         $(NULL)
796 LIBGUESTFS_TESTS += test-python
798 test_python_SOURCES = test-lang-plugins.c test.h
799 test_python_CFLAGS = \
800         -DLANG='"python"' -DSCRIPT='"$(srcdir)/test.py"' \
801         $(WARNINGS_CFLAGS) \
802         $(LIBGUESTFS_CFLAGS) \
803         $(NULL)
804 test_python_LDADD = libtest.la $(LIBGUESTFS_LIBS)
806 endif HAVE_PYTHON
808 # Ruby plugin test.
809 if HAVE_RUBY
811 # Ruby tests are disabled.  See "WARNING" section in
812 # plugins/ruby/nbdkit-ruby-plugin.pod
814 #LIBGUESTFS_TESTS += \
815 #       test-ruby \
816 #       $(NULL)
817 #TESTS += test-shebang-ruby.sh
818 EXTRA_PROGRAMS += test-ruby
820 test_ruby_SOURCES = test-lang-plugins.c test.h
821 test_ruby_CFLAGS = \
822         -DLANG='"ruby"' -DSCRIPT='"$(srcdir)/test.rb"' \
823         $(WARNINGS_CFLAGS) \
824         $(LIBGUESTFS_CFLAGS) \
825         $(NULL)
826 test_ruby_LDADD = libtest.la $(LIBGUESTFS_LIBS)
828 endif HAVE_RUBY
830 # Shell (sh) plugin test.
831 LIBGUESTFS_TESTS += test-shell
832 check_DATA += test-shell.img
833 CLEANFILES += test-shell.img
835 test_shell_SOURCES = test-lang-plugins.c test.h
836 test_shell_CFLAGS = \
837         -DLANG='"sh"' -DSCRIPT='"$(srcdir)/test-shell.sh"' \
838         $(WARNINGS_CFLAGS) \
839         $(LIBGUESTFS_CFLAGS) \
840         $(NULL)
841 test_shell_LDADD = libtest.la $(LIBGUESTFS_LIBS)
843 test-shell.img:
844         truncate -s 1048576 $@
846 TESTS += \
847         test-sh-errors.sh \
848         test-sh-extents.sh \
849         $(NULL)
851 # Tcl plugin test.
852 if HAVE_TCL
854 LIBGUESTFS_TESTS += test-tcl
856 test_tcl_SOURCES = test-lang-plugins.c test.h
857 test_tcl_CFLAGS = \
858         -DLANG='"tcl"' -DSCRIPT='"$(srcdir)/test.tcl"' \
859         $(WARNINGS_CFLAGS) \
860         $(LIBGUESTFS_CFLAGS) \
861         $(NULL)
862 test_tcl_LDADD = libtest.la $(LIBGUESTFS_LIBS)
864 endif HAVE_TCL
866 # Lua plugin test.
867 if HAVE_LUA
869 LIBGUESTFS_TESTS += test-lua
871 test_lua_SOURCES = test-lang-plugins.c test.h
872 test_lua_CFLAGS = \
873         -DLANG='"lua"' -DSCRIPT='"$(srcdir)/test.lua"' \
874         $(WARNINGS_CFLAGS) \
875         $(LIBGUESTFS_CFLAGS) \
876         $(NULL)
877 test_lua_LDADD = libtest.la $(LIBGUESTFS_LIBS)
879 endif HAVE_LUA
881 #----------------------------------------------------------------------
882 # Tests of filters.
884 # Generic test of filter layers.
885 check_PROGRAMS += test-layers
886 TESTS += test-layers.sh test-layers
888 test_layers_SOURCES = \
889         test-layers.c \
890         $(NULL)
891 test_layers_CPPFLAGS = \
892         -I$(top_srcdir)/common/include \
893         -I$(top_srcdir)/common/protocol \
894         -I$(top_srcdir)/common/utils \
895         -I$(top_srcdir)/server \
896         $(NULL)
897 test_layers_CFLAGS = \
898         $(WARNINGS_CFLAGS) \
899         $(PTHREAD_CFLAGS) \
900         $(NULL)
901 test_layers_LDFLAGS = \
902         $(PTHREAD_LIBS) \
903         $(NULL)
904 test_layers_LDADD = \
905         $(top_builddir)/common/utils/libutils.la \
906         $(NULL)
907 test_layers_DEPENDENCIES = \
908         test-layers-plugin.la \
909         test-layers-filter1.la \
910         test-layers-filter2.la \
911         test-layers-filter3.la \
912         $(NULL)
914 # check_LTLIBRARIES won't build a shared library (see automake manual).
915 # So we have to do this and add a dependency.
916 noinst_LTLIBRARIES += \
917         test-layers-plugin.la \
918         test-layers-filter1.la \
919         test-layers-filter2.la \
920         test-layers-filter3.la \
921         $(NULL)
923 test_layers_plugin_la_SOURCES = \
924         test-layers-plugin.c \
925         $(top_srcdir)/include/nbdkit-plugin.h \
926         $(NULL)
927 test_layers_plugin_la_CPPFLAGS = -I$(top_srcdir)/include
928 test_layers_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
929 # For use of the -rpath option, see:
930 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
931 test_layers_plugin_la_LDFLAGS = \
932         -module -avoid-version -shared -rpath /nowhere \
933         $(NULL)
935 test_layers_filter1_la_SOURCES = \
936         test-layers-filter.c \
937         $(top_srcdir)/include/nbdkit-filter.h \
938         $(NULL)
939 test_layers_filter1_la_CPPFLAGS = -I$(top_srcdir)/include
940 test_layers_filter1_la_CFLAGS = $(WARNINGS_CFLAGS) -Dlayer='"filter1"'
941 # For use of the -rpath option, see:
942 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
943 test_layers_filter1_la_LDFLAGS = \
944         -module -avoid-version -shared -rpath /nowhere \
945         $(NULL)
947 test_layers_filter2_la_SOURCES = \
948         test-layers-filter.c \
949         $(top_srcdir)/include/nbdkit-filter.h \
950         $(NULL)
951 test_layers_filter2_la_CPPFLAGS = -I$(top_srcdir)/include
952 test_layers_filter2_la_CFLAGS = $(WARNINGS_CFLAGS) -Dlayer='"filter2"'
953 # For use of the -rpath option, see:
954 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
955 test_layers_filter2_la_LDFLAGS = \
956         -module -avoid-version -shared -rpath /nowhere \
957         $(NULL)
959 test_layers_filter3_la_SOURCES = \
960         test-layers-filter.c \
961         $(top_srcdir)/include/nbdkit-filter.h \
962         $(NULL)
963 test_layers_filter3_la_CPPFLAGS = -I$(top_srcdir)/include
964 test_layers_filter3_la_CFLAGS = $(WARNINGS_CFLAGS) -Dlayer='"filter3"'
965 # For use of the -rpath option, see:
966 # https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html
967 test_layers_filter3_la_LDFLAGS = \
968         -module -avoid-version -shared -rpath /nowhere \
969         $(NULL)
971 # blocksize filter test.
972 TESTS += test-blocksize.sh
974 # cache filter test.
975 if HAVE_GUESTFISH
976 TESTS += \
977         test-cache.sh \
978         test-cache-on-read.sh \
979         $(NULL)
980 endif HAVE_GUESTFISH
981 TESTS += test-cache-max-size.sh
983 # cacheextents filter test.
984 TESTS += test-cacheextents.sh
986 # cow filter test.
987 if HAVE_GUESTFISH
988 TESTS += test-cow.sh
989 endif HAVE_GUESTFISH
990 TESTS += test-cow-null.sh
992 # delay filter tests.
993 TESTS += test-shutdown.sh
994 LIBGUESTFS_TESTS += test-delay
996 test_delay_SOURCES = test-delay.c test.h
997 test_delay_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
998 test_delay_LDADD = libtest.la $(LIBGUESTFS_LIBS)
1000 # error filter test.
1001 LIBGUESTFS_TESTS += test-error
1003 test_error_SOURCES = test-error.c test.h
1004 test_error_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
1005 test_error_LDADD = libtest.la $(LIBGUESTFS_LIBS)
1007 TESTS += \
1008         test-error0.sh \
1009         test-error10.sh \
1010         test-error100.sh \
1011         $(NULL)
1013 # fua filter test.
1014 TESTS += test-fua.sh
1016 # log filter test.
1017 TESTS += test-log.sh
1019 # nozero filter test.
1020 TESTS += test-nozero.sh
1022 # offset filter test.
1023 check_DATA += offset-data
1024 CLEANFILES += offset-data
1025 LIBGUESTFS_TESTS += test-offset
1027 offset-data: generate-offset-data.sh
1028         $(srcdir)/generate-offset-data.sh $@
1030 test_offset_SOURCES = test-offset.c test.h
1031 test_offset_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
1032 test_offset_LDADD = libtest.la $(LIBGUESTFS_LIBS)
1034 TESTS += \
1035         test-offset2.sh \
1036         test-offset-extents.sh \
1037         $(NULL)
1039 # partition filter test.
1040 TESTS += test-partition1.sh
1041 if HAVE_GUESTFISH
1042 TESTS += test-partition2.sh
1043 endif HAVE_GUESTFISH
1045 # rate filter test.
1046 TESTS += \
1047         test-rate.sh \
1048         test-rate-dynamic.sh \
1049         $(NULL)
1051 # readahead filter test.
1052 LIBGUESTFS_TESTS += test-readahead
1053 TESTS += test-readahead-copy.sh
1055 test_readahead_SOURCES = test-readahead.c test.h
1056 test_readahead_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
1057 test_readahead_LDADD = libtest.la $(LIBGUESTFS_LIBS)
1059 # retry filter test.
1060 TESTS += \
1061         test-retry.sh \
1062         test-retry-readonly.sh \
1063         test-retry-extents.sh \
1064         test-retry-reopen-fail.sh \
1065         $(NULL)
1067 # truncate filter tests.
1068 TESTS += \
1069         test-truncate1.sh \
1070         test-truncate2.sh \
1071         test-truncate3.sh \
1072         test-truncate4.sh \
1073         test-truncate-extents.sh \
1074         $(NULL)
1076 # xz filter test.
1077 if HAVE_LIBLZMA
1078 if HAVE_GUESTFISH
1080 LIBGUESTFS_TESTS += test-xz
1081 check_DATA += disk.xz
1082 CLEANFILES += disk.xz
1084 test_xz_SOURCES = test-xz.c test.h
1085 test_xz_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
1086 test_xz_LDADD = libtest.la $(LIBGUESTFS_LIBS)
1088 disk.xz: disk
1089         rm -f $@
1090 # We choose a very small block size here only for testing.  Normally
1091 # you should choose a 16M block size.
1092         xz --best --block-size=32768 -c disk > $@
1094 if HAVE_CURL
1096 # xz filter + curl.
1097 LIBGUESTFS_TESTS += test-xz-curl
1099 test_xz_curl_SOURCES = \
1100         test-xz-curl.c \
1101         web-server.c \
1102         web-server.h \
1103         test.h \
1104         $(NULL)
1105 test_xz_curl_CPPFLAGS = \
1106         -I$(top_srcdir)/common/utils
1107 test_xz_curl_CFLAGS = \
1108         $(WARNINGS_CFLAGS) \
1109         $(LIBGUESTFS_CFLAGS) \
1110         $(PTHREAD_CFLAGS) \
1111         $(NULL)
1112 test_xz_curl_LDFLAGS = \
1113         $(top_builddir)/common/utils/libutils.la \
1114         $(PTHREAD_LIBS) \
1115         $(NULL)
1116 test_xz_curl_LDADD = \
1117         libtest.la \
1118         $(LIBGUESTFS_LIBS) \
1119         $(NULL)
1121 endif HAVE_CURL
1123 endif HAVE_GUESTFISH
1124 endif HAVE_LIBLZMA
1126 endif HAVE_PLUGINS