tests: Add repeat argument to run-verify

* tests/run-verify.c (main): Add repeat argument.

--
This helps reproducing rare / random crashes.
This commit is contained in:
Andre Heinecke 2018-10-29 16:33:04 +01:00
parent 8f27511862
commit 681525be00
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C

View File

@ -230,6 +230,7 @@ show_usage (int ex)
" --openpgp use the OpenPGP protocol (default)\n" " --openpgp use the OpenPGP protocol (default)\n"
" --cms use the CMS protocol\n" " --cms use the CMS protocol\n"
" --sender MBOX use MBOX as sender address\n" " --sender MBOX use MBOX as sender address\n"
" --repeat N repeat the operation N times\n"
" --auto-key-retrieve\n" " --auto-key-retrieve\n"
, stderr); , stderr);
exit (ex); exit (ex);
@ -241,17 +242,11 @@ main (int argc, char **argv)
{ {
int last_argc = -1; int last_argc = -1;
const char *s; const char *s;
gpgme_error_t err;
gpgme_ctx_t ctx;
gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP; gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP;
FILE *fp_sig = NULL;
gpgme_data_t sig = NULL;
FILE *fp_msg = NULL;
gpgme_data_t msg = NULL;
gpgme_verify_result_t result;
int print_status = 0; int print_status = 0;
const char *sender = NULL; const char *sender = NULL;
int auto_key_retrieve = 0; int auto_key_retrieve = 0;
int repeats = 1;
if (argc) if (argc)
{ argc--; argv++; } { argc--; argv++; }
@ -294,6 +289,14 @@ main (int argc, char **argv)
sender = *argv; sender = *argv;
argc--; argv++; argc--; argv++;
} }
else if (!strcmp (*argv, "--repeat"))
{
argc--; argv++;
if (!argc)
show_usage (1);
repeats = atoi (*argv);
argc--; argv++;
}
else if (!strcmp (*argv, "--auto-key-retrieve")) else if (!strcmp (*argv, "--auto-key-retrieve"))
{ {
auto_key_retrieve = 1; auto_key_retrieve = 1;
@ -308,87 +311,108 @@ main (int argc, char **argv)
if (argc < 1 || argc > 2) if (argc < 1 || argc > 2)
show_usage (1); show_usage (1);
fp_sig = fopen (argv[0], "rb"); init_gpgme (protocol);
if (!fp_sig)
for (int i = 0; i < repeats; i++)
{ {
err = gpgme_error_from_syserror (); gpgme_error_t err;
fprintf (stderr, PGM ": can't open `%s': %s\n", gpgme_ctx_t ctx;
argv[0], gpgme_strerror (err)); FILE *fp_sig = NULL;
exit (1); gpgme_data_t sig = NULL;
} FILE *fp_msg = NULL;
if (argc > 1) gpgme_data_t msg = NULL;
{ gpgme_verify_result_t result;
fp_msg = fopen (argv[1], "rb");
if (!fp_msg) if (repeats > 1)
{
printf ("Repeat: %i\n", i);
}
fp_sig = fopen (argv[0], "rb");
if (!fp_sig)
{ {
err = gpgme_error_from_syserror (); err = gpgme_error_from_syserror ();
fprintf (stderr, PGM ": can't open `%s': %s\n", fprintf (stderr, PGM ": can't open `%s': %s\n",
argv[1], gpgme_strerror (err)); argv[0], gpgme_strerror (err));
exit (1); exit (1);
} }
} if (argc > 1)
init_gpgme (protocol);
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_protocol (ctx, protocol);
if (print_status)
{
gpgme_set_status_cb (ctx, status_cb, NULL);
gpgme_set_ctx_flag (ctx, "full-status", "1");
}
/* gpgme_set_ctx_flag (ctx, "raw-description", "1"); */
if (auto_key_retrieve)
{
gpgme_set_ctx_flag (ctx, "auto-key-retrieve", "1");
s = gpgme_get_ctx_flag (ctx, "auto-key-retrieve");
if (!s || strcmp (s, "1"))
{ {
fprintf (stderr, PGM ": gpgme_get_ctx_flag failed for '%s'\n", fp_msg = fopen (argv[1], "rb");
"auto-key-retrieve"); if (!fp_msg)
exit (1); {
err = gpgme_error_from_syserror ();
fprintf (stderr, PGM ": can't open `%s': %s\n",
argv[1], gpgme_strerror (err));
exit (1);
}
} }
}
if (sender) err = gpgme_new (&ctx);
{
err = gpgme_set_sender (ctx, sender);
fail_if_err (err); fail_if_err (err);
} gpgme_set_protocol (ctx, protocol);
if (print_status)
{
gpgme_set_status_cb (ctx, status_cb, NULL);
gpgme_set_ctx_flag (ctx, "full-status", "1");
}
/* gpgme_set_ctx_flag (ctx, "raw-description", "1"); */
err = gpgme_data_new_from_stream (&sig, fp_sig); if (auto_key_retrieve)
if (err) {
{ gpgme_set_ctx_flag (ctx, "auto-key-retrieve", "1");
fprintf (stderr, PGM ": error allocating data object: %s\n", s = gpgme_get_ctx_flag (ctx, "auto-key-retrieve");
gpgme_strerror (err)); if (!s || strcmp (s, "1"))
exit (1); {
} fprintf (stderr, PGM ": gpgme_get_ctx_flag failed for '%s'\n",
if (fp_msg) "auto-key-retrieve");
{ exit (1);
err = gpgme_data_new_from_stream (&msg, fp_msg); }
}
if (sender)
{
err = gpgme_set_sender (ctx, sender);
fail_if_err (err);
}
err = gpgme_data_new_from_stream (&sig, fp_sig);
if (err) if (err)
{ {
fprintf (stderr, PGM ": error allocating data object: %s\n", fprintf (stderr, PGM ": error allocating data object: %s\n",
gpgme_strerror (err)); gpgme_strerror (err));
exit (1); exit (1);
} }
if (fp_msg)
{
err = gpgme_data_new_from_stream (&msg, fp_msg);
if (err)
{
fprintf (stderr, PGM ": error allocating data object: %s\n",
gpgme_strerror (err));
exit (1);
}
}
err = gpgme_op_verify (ctx, sig, msg, NULL);
result = gpgme_op_verify_result (ctx);
if (result)
print_result (result);
if (err)
{
fprintf (stderr, PGM ": verify failed: %s\n", gpgme_strerror (err));
exit (1);
}
gpgme_data_release (msg);
gpgme_data_release (sig);
gpgme_release (ctx);
if (fp_msg)
fclose (fp_msg);
if (fp_sig)
fclose (fp_sig);
} }
err = gpgme_op_verify (ctx, sig, msg, NULL);
result = gpgme_op_verify_result (ctx);
if (result)
print_result (result);
if (err)
{
fprintf (stderr, PGM ": verify failed: %s\n", gpgme_strerror (err));
exit (1);
}
gpgme_data_release (msg);
gpgme_data_release (sig);
gpgme_release (ctx);
return 0; return 0;
} }