tests: Add a way to write tests using libnbd.
[nbdkit/ericb.git] / tests / README.tests
blob568f6fb389bb3fd87c4ac08954932ebbd02b2a3d
1 To test a plugin using libguestfs
2 =================================
4   - #include <test.h>
6   - Call:
8     test_start_nbdkit ("plugin", <plugin args ...>, NULL)
10     at the beginning.  This starts the nbdkit server.
12   - Open a libguestfs handle, and configure the NBD client using:
14     guestfs_add_drive_opts (g, "",
15                             GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
16                             GUESTFS_ADD_DRIVE_OPTS_PROTOCOL, "nbd",
17                             GUESTFS_ADD_DRIVE_OPTS_SERVER, server,
18                             -1);
20     'server' is a global that is initialized by 'test_start_nbdkit' and
21     points to the nbdkit server socket.
23   - Perform tests via libguestfs using the libguestfs device "/dev/sda",
24     which corresponds to the NBD drive exposed by the plugin.
26   - Close the handle and exit.  An 'atexit' handler installed by
27     'test_start_nbdkit' cleans up the server automatically.
29 For an example, see 'test-data.c'.
31 To test a plugin using libnbd
32 =============================
34   - Open a libnbd handle, and configure it using:
36     char *args[] = { "nbdkit", "-s", "--exit-with-parent",
37                      "plugin", <plugin args ...>, NULL };
38     nbd_connect_command (nbd, args);
40   - Perform tests via libnbd.
42 For an example, see 'test-delay.c'.