[Libguestfs] [PATCH libnbd] tests: Add a test of nbd_{set, get}_socket_activation_name

Eric Blake eblake at redhat.com
Mon May 8 13:45:02 UTC 2023


On Sun, May 07, 2023 at 11:43:23AM +0100, Richard W.M. Jones wrote:
> Also test that the expected environment variable is set when
> connecting to nbdkit.
> 
> This test requires nbdkit >= 1.35.2 which added support for -D
> nbdkit.environ=1 to dump the environment, and will be skipped with
> other versions.
> ---
>  .gitignore                     |  1 +
>  tests/Makefile.am              |  8 +++
>  tests/socket-activation-name.c | 99 ++++++++++++++++++++++++++++++++++
>  3 files changed, 108 insertions(+)
> 
> +  /* Check firstly that it defaults to empty string. */
> +  r = nbd_get_socket_activation_name (nbd);
> +  assert (r != NULL);
> +  assert (strcmp (r, "") == 0);
> +  free (r);
> +
> +  /* Check we can set it to something and read that back. */
> +  assert (nbd_set_socket_activation_name (nbd, "hello") == 0);
> +  r = nbd_get_socket_activation_name (nbd);
> +  assert (r != NULL);
> +  assert (strcmp (r, "hello") == 0);
> +  free (r);
> +
> +  /* Run external nbdkit and check the LISTEN_FDNAMES environment
> +   * variable is set.  We need to capture the debug output of nbdkit,
> +   * hence the journey through the shell.
> +   */
> +  unlink (DEBUG_FILE);
> +  char *cmd[] = {
> +    "sh", "-c",
> +    "exec 2> " DEBUG_FILE "\n"
> +    "exec nbdkit -v -D nbdkit.environ=1 null 1024\n",
> +    NULL
> +  };
> +  if (nbd_connect_systemd_socket_activation (nbd, cmd) == -1) {
> +    fprintf (stderr, "%s\n", nbd_get_error ());
> +    exit (EXIT_FAILURE);
> +  }

Should we run this twice, once with a set name (as you did here, to
prove LISTEN_FDNAMES=hello makes it through), and again with the
default name (to see that LISTEN_FDNAMES=unknown is now populated)?

Otherwise, this is a nice addition.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


More information about the Libguestfs mailing list