File: README.tests

package info (click to toggle)
nbdkit 1.46.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,504 kB
  • sloc: ansic: 63,658; sh: 18,717; makefile: 6,814; python: 1,848; cpp: 1,143; perl: 504; ml: 504; tcl: 62
file content (111 lines) | stat: -rw-r--r-- 3,125 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
For users
=========

To run the tests:

  make check
  make check-valgrind

To test against the real VDDK library:

  make check-vddk vddkdir=vmware-vix-disklib-distrib

Optionally:

  sudo make check-root


For developers
==============

This directory contains the nbdkit test suite.  It uses the automake
Parallel Test Harness[1] to run the tests in parallel.  We prefer
individual small tests as they are easier to parallelize and debug.

[1] https://www.gnu.org/software/automake/manual/html_node/Parallel-Test-Harness.html

Existing tests generally use one of these approaches:

(1) shell script + qemu-io.

(2) shell script + guestfish.

(3) shell script + nbdsh (preferred over (1) and (2), if possible).

(4) C program using libguestfs + test harness.  The test harness is
    described below.

(5) C program using libnbd (somewhat preferred over (4), if possible).


Shell script tests
------------------

At the top of the shell script use:

  source ./functions.sh
  set -e     # optional, depends on the test
  set -x     # optional, but usually better to have it

The ‘functions.sh’ script contains many useful functions that help
with writing tests, specifying test prerequisites, and cleaning up.

Mosts tests will need one or more ‘requires’ lines in order to skip
the test if required utilities are not available.  See existing tests
for examples.

Before any shell script test will run, you must add it to ‘TESTS’ and
‘EXTRA_DIST’ in the ‘Makefile.am’ file.

There are many examples, eg. ‘tests/test-limit.sh’.


To test a plugin using libnbd
-----------------------------

Open a libnbd handle, and configure it using:

  nbd_connect_command (nbd,
                       (char *[]) {
                         "nbdkit", "-s", "--exit-with-parent",
                         "plugin", <plugin args ...>, NULL });

Perform tests via libnbd functions.

Add the test to ‘LIBNBD_TESTS’ and ‘EXTRA_DIST’ in ‘Makefile.am’.

For an example, see ‘test-delay.c’.


To test a plugin using libguestfs
---------------------------------

There is a small test harness to help with tests written in C using
libguestfs (http://libguestfs.org).

#include "test.h"

Call at the beginning.  This starts the nbdkit server:

  test_start_nbdkit ("plugin", <plugin args ...>, NULL)

Open a libguestfs handle, and configure the NBD client using:

  guestfs_add_drive_opts (g, "",
                          GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
                          GUESTFS_ADD_DRIVE_OPTS_PROTOCOL, "nbd",
                          GUESTFS_ADD_DRIVE_OPTS_SERVER, server,
                          -1);

‘server’ is a global that is initialized by ‘test_start_nbdkit’ and
points to the nbdkit server socket.

Perform tests via libguestfs using the libguestfs device "/dev/sda",
which corresponds to the NBD drive exposed by the plugin.

Close the handle and exit.  An atexit handler installed by
‘test_start_nbdkit’ cleans up the server automatically.

Add the test to ‘LIBGUESTFS_TESTS’ and ‘EXTRA_DIST’ in ‘Makefile.am’.

For an example, see ‘test-data.c’.