summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2004-03-03 08:08:05 +0000
committerWerner Koch <wk@gnupg.org>2004-03-03 08:08:05 +0000
commitf599114325e534a40f06d54c590fde0638ac10c7 (patch)
tree7529f6208bd1bf2e57e03be094e909956e72a3e0 /tests
parent05e7c6fe5dfa3c20ffd740c4990f1cdbc03226b0 (diff)
downloadlibgcrypt-f599114325e534a40f06d54c590fde0638ac10c7.tar.gz
* Makefile.am (TEST): Add benchmark.
* benchmark.c (md_bench, cipher_bench): Allow NULL arg to to run tests for all algorithms. (main): Run all tests by default.
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog8
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/benchmark.c68
3 files changed, 61 insertions, 19 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 8d1656b5..42d477c4 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,11 @@
+2004-02-25 Werner Koch <wk@gnupg.org>
+
+ * Makefile.am (TEST): Add benchmark.
+
+ * benchmark.c (md_bench, cipher_bench): Allow NULL arg to to run
+ tests for all algorithms.
+ (main): Run all tests by default.
+
2004-02-03 Werner Koch <wk@gnupg.org>
* tsexp.c (basic): New pass to check secure memory switching.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6b5e7035..f717ca57 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -18,12 +18,12 @@
## Process this file with automake to produce Makefile.in
-TESTS = prime register ac basic tsexp keygen pubkey
+TESTS = prime register ac basic tsexp keygen pubkey benchmark
INCLUDES = -I$(top_srcdir)/src
LDADD = ../src/libgcrypt.la
-EXTRA_PROGRAMS = benchmark testapi
+EXTRA_PROGRAMS = testapi
noinst_PROGRAMS = $(TESTS)
AM_CFLAGS = @GPG_ERROR_CFLAGS@
diff --git a/tests/benchmark.c b/tests/benchmark.c
index 1b467408..8ca13b31 100644
--- a/tests/benchmark.c
+++ b/tests/benchmark.c
@@ -1,5 +1,5 @@
/* benchmark.c - for libgcrypt
- * Copyright (C) 2002 Free Software Foundation, Inc.
+ * Copyright (C) 2002, 2004 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
@@ -93,12 +93,21 @@ random_bench (void)
static void
md_bench ( const char *algoname )
{
- int algo = gcry_md_map_name (algoname);
+ int algo;
gcry_md_hd_t hd;
int i;
char buf[1000];
gcry_error_t err = GPG_ERR_NO_ERROR;
+ if (!algoname)
+ {
+ for (i=1; i < 400; i++)
+ if ( !gcry_md_test_algo (i) )
+ md_bench (gcry_md_algo_name (i));
+ return;
+ }
+
+ algo = gcry_md_map_name (algoname);
if (!algo)
{
fprintf (stderr, PGM ": invalid hash algorithm `%s'\n", algoname);
@@ -108,14 +117,14 @@ md_bench ( const char *algoname )
err = gcry_md_open (&hd, algo, 0);
if (err)
{
- fprintf (stderr, PGM ": error opeing hash algorithm `%s'/n", algoname);
+ fprintf (stderr, PGM ": error opening hash algorithm `%s'\n", algoname);
exit (1);
}
for (i=0; i < sizeof buf; i++)
buf[i] = i;
- printf ("%-10s", gcry_md_algo_name (algo));
+ printf ("%-12s", gcry_md_algo_name (algo));
start_timer ();
for (i=0; i < 1000; i++)
@@ -148,7 +157,7 @@ static void
cipher_bench ( const char *algoname )
{
static int header_printed;
- int algo = gcry_cipher_map_name (algoname);
+ int algo;
gcry_cipher_hd_t hd;
int i;
int keylen, blklen;
@@ -166,19 +175,30 @@ cipher_bench ( const char *algoname )
int modeidx;
gcry_error_t err = GPG_ERR_NO_ERROR;
+
+ if (!algoname)
+ {
+ for (i=1; i < 400; i++)
+ if ( !gcry_cipher_test_algo (i) )
+ cipher_bench (gcry_cipher_algo_name (i));
+ return;
+ }
+
+
if (!header_printed)
{
- printf ("%-10s", "Algo");
+ printf ("%-10s", "");
for (modeidx=0; modes[modeidx].mode; modeidx++)
printf (" %-15s", modes[modeidx].name );
putchar ('\n');
- printf ( "----------");
+ printf ("%-10s", "");
for (modeidx=0; modes[modeidx].mode; modeidx++)
printf (" ---------------" );
putchar ('\n');
header_printed = 1;
}
+ algo = gcry_cipher_map_name (algoname);
if (!algo)
{
fprintf (stderr, PGM ": invalid cipher algorithm `%s'\n", algoname);
@@ -359,26 +379,40 @@ mpi_bench (void)
int
main( int argc, char **argv )
{
- if (argc < 2 )
+ if (argc)
+ { argc--; argv++; }
+
+ if ( !argc )
{
- fprintf (stderr, "usage: benchmark md|cipher|random|mpi [algonames]\n");
- return 1;
+ md_bench (NULL);
+ putchar ('\n');
+ cipher_bench (NULL);
+ putchar ('\n');
+ mpi_bench ();
+ putchar ('\n');
+ random_bench ();
}
- argc--; argv++;
-
- if ( !strcmp (*argv, "random"))
+ else if ( !strcmp (*argv, "--help"))
+ fputs ("usage: benchmark [md|cipher|random|mpi [algonames]]\n", stdout);
+ else if ( !strcmp (*argv, "random"))
{
random_bench ();
}
else if ( !strcmp (*argv, "md"))
{
- for (argc--, argv++; argc; argc--, argv++)
- md_bench ( *argv );
+ if (argc == 1)
+ md_bench (NULL);
+ else
+ for (argc--, argv++; argc; argc--, argv++)
+ md_bench ( *argv );
}
else if ( !strcmp (*argv, "cipher"))
{
- for (argc--, argv++; argc; argc--, argv++)
- cipher_bench ( *argv );
+ if (argc == 1)
+ cipher_bench (NULL);
+ else
+ for (argc--, argv++; argc; argc--, argv++)
+ cipher_bench ( *argv );
}
else if ( !strcmp (*argv, "mpi"))
{