1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

common: Add test case for IPC with spawned process.

* common/Makefile.am (module_tests): Add t-exechelp.
* common/t-exechelp.c [HAVE_W32_SYSTEM] (print_open_fds)
(test_close_all_fds, main): Exclude the test_close_all_fds test.
(run_server, test_pipe_stream): New.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2023-06-07 09:08:58 +09:00
parent 22350d0768
commit 9433dfa5dd
No known key found for this signature in database
GPG Key ID: 640114AF89DE6054
2 changed files with 103 additions and 4 deletions

View File

@ -161,11 +161,11 @@ module_tests = t-stringhelp t-timestuff \
t-convert t-percent t-gettime t-sysutils t-sexputil \ t-convert t-percent t-gettime t-sysutils t-sexputil \
t-session-env t-openpgp-oid t-ssh-utils \ t-session-env t-openpgp-oid t-ssh-utils \
t-mapstrings t-zb32 t-mbox-util t-iobuf t-strlist \ t-mapstrings t-zb32 t-mbox-util t-iobuf t-strlist \
t-name-value t-ccparray t-recsel t-w32-cmdline t-name-value t-ccparray t-recsel t-w32-cmdline t-exechelp
if HAVE_W32_SYSTEM if HAVE_W32_SYSTEM
module_tests += t-w32-reg module_tests += t-w32-reg
else else
module_tests += t-exechelp t-exectool module_tests += t-exectool
endif endif
if MAINTAINER_MODE if MAINTAINER_MODE

View File

@ -29,7 +29,7 @@
static int verbose; static int verbose;
#ifndef HAVE_W32_SYSTEM
static void static void
print_open_fds (int *array) print_open_fds (int *array)
{ {
@ -169,20 +169,119 @@ test_close_all_fds (void)
} }
} }
#endif
static char buff12k[1024*12];
static void
run_server (void)
{
estream_t fp;
int i;
char *p;
unsigned int len;
int ret;
fp = es_fdopen_nc (1, "w");
if (fp == NULL)
{
fprintf (stderr, "es_fdopen failed\n");
exit (1);
}
/* Fill the buffer by ASCII chars. */
p = buff12k;
for (i = 0; i < sizeof (buff12k); i++)
if ((i % 64) == 63)
*p++ = '\n';
else
*p++ = (i % 64) + '@';
len = sizeof (buff12k);
ret = es_write (fp, (void *)&len, sizeof (len), NULL);
if (ret)
{
fprintf (stderr, "es_write (1) failed\n");
exit (1);
}
ret = es_write (fp, buff12k, sizeof (buff12k), NULL);
if (ret)
{
fprintf (stderr, "es_write (2) failed\n");
exit (1);
}
es_fclose (fp);
exit (0);
}
static void
test_pipe_stream (const char *pgmname)
{
gpg_error_t err;
gnupg_process_t proc;
estream_t outfp;
const char *argv[2];
unsigned int len;
size_t n;
int ret;
argv[0] = "--server";
argv[1] = NULL;
err = gnupg_process_spawn (pgmname, argv,
(GNUPG_PROCESS_STDOUT_PIPE
|GNUPG_PROCESS_STDERR_KEEP),
NULL, NULL, &proc);
if (err)
{
fprintf (stderr, "gnupg_process_spawn failed\n");
exit (1);
}
gnupg_process_get_streams (proc, 0, NULL, &outfp, NULL);
ret = es_read (outfp, (void *)&len, sizeof (len), NULL);
if (ret)
{
fprintf (stderr, "es_read (1) failed\n");
exit (1);
}
ret = es_read (outfp, buff12k, sizeof (buff12k), &n);
if (ret || n != sizeof (buff12k))
{
fprintf (stderr, "es_read (2) failed\n");
exit (1);
}
es_fclose (outfp);
gnupg_process_release (proc);
}
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
const char *myname = "no-pgm";
if (argc) if (argc)
{ argc--; argv++; } {
myname = argv[0];
argc--; argv++;
}
if (argc && !strcmp (argv[0], "--verbose")) if (argc && !strcmp (argv[0], "--verbose"))
{ {
verbose = 1; verbose = 1;
argc--; argv++; argc--; argv++;
} }
if (argc && !strcmp (argv[0], "--server"))
run_server ();
#ifndef HAVE_W32_SYSTEM
test_close_all_fds (); test_close_all_fds ();
#endif
test_pipe_stream (myname);
return 0; return 0;
} }