summaryrefslogtreecommitdiff
path: root/src/util/test_helper_eddsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/test_helper_eddsa.c')
-rw-r--r--src/util/test_helper_eddsa.c160
1 files changed, 125 insertions, 35 deletions
diff --git a/src/util/test_helper_eddsa.c b/src/util/test_helper_eddsa.c
index 4b44f6041..0119e4278 100644
--- a/src/util/test_helper_eddsa.c
+++ b/src/util/test_helper_eddsa.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2020 Taler Systems SA
+ (C) 2020, 2021 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -27,7 +27,7 @@
* we should never have more than 6 active keys, plus for during
* key expiration / revocation.
*/
-#define MAX_KEYS 7
+#define MAX_KEYS 20
/**
* How many random key revocations should we test?
@@ -36,7 +36,7 @@
/**
* How many iterations of the successful signing test should we run
- * during the benchmark phase?
+ * during the test phase?
*/
#define NUM_SIGN_TESTS 3
@@ -46,6 +46,11 @@
*/
#define NUM_SIGN_PERFS 100
+/**
+ * How many parallel clients should we use for the parallel
+ * benchmark? (> 500 may cause problems with the max open FD number limit).
+ */
+#define NUM_CORES 8
/**
* Number of keys currently in #keys.
@@ -60,7 +65,7 @@ struct KeyData
/**
* Validity start point.
*/
- struct GNUNET_TIME_Absolute start_time;
+ struct GNUNET_TIME_Timestamp start_time;
/**
* Key expires for signing at @e start_time plus this value.
@@ -107,15 +112,23 @@ static struct KeyData keys[MAX_KEYS];
*/
static void
key_cb (void *cls,
- struct GNUNET_TIME_Absolute start_time,
+ struct GNUNET_TIME_Timestamp start_time,
struct GNUNET_TIME_Relative validity_duration,
const struct TALER_ExchangePublicKeyP *exchange_pub,
const struct TALER_SecurityModulePublicKeyP *sm_pub,
const struct TALER_SecurityModuleSignatureP *sm_sig)
{
+ (void) cls;
(void) sm_pub;
(void) sm_sig;
- if (0 == validity_duration.rel_value_us)
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Update on key %s (%s)...",
+ TALER_B2S (exchange_pub),
+ GNUNET_STRINGS_relative_time_to_string (validity_duration,
+ GNUNET_YES));
+
+ if (GNUNET_TIME_relative_is_zero (validity_duration))
{
bool found = false;
@@ -184,23 +197,34 @@ test_revocation (struct TALER_CRYPTO_ExchangeSignHelper *esh)
}
keys[j].revoked = true;
fprintf (stderr,
- "Revoking key ...");
+ "Revoking key %s (%u) ...",
+ TALER_B2S (&keys[j].exchange_pub),
+ j);
TALER_CRYPTO_helper_esign_revoke (esh,
&keys[j].exchange_pub);
for (unsigned int k = 0; k<1000; k++)
{
TALER_CRYPTO_helper_esign_poll (esh);
- if (! keys[j].revoked)
+ if ( (! keys[j].revoked) ||
+ (GNUNET_TIME_absolute_is_past (
+ GNUNET_TIME_absolute_add (keys[j].start_time.abs_time,
+ keys[j].validity_duration))) )
+ {
break;
+ }
nanosleep (&req, NULL);
fprintf (stderr, ".");
}
- if (keys[j].revoked)
+ if ( (keys[j].revoked) &&
+ (! GNUNET_TIME_absolute_is_past (
+ GNUNET_TIME_absolute_add (keys[j].start_time.abs_time,
+ keys[j].validity_duration))) )
{
fprintf (stderr,
"\nFAILED: timeout trying to revoke key %u\n",
j);
TALER_CRYPTO_helper_esign_disconnect (esh);
+ esh = NULL;
return 2;
}
fprintf (stderr, "\n");
@@ -270,7 +294,8 @@ test_signing (struct TALER_CRYPTO_ExchangeSignHelper *esh)
* @return 0 on success
*/
static int
-perf_signing (struct TALER_CRYPTO_ExchangeSignHelper *esh)
+perf_signing (struct TALER_CRYPTO_ExchangeSignHelper *esh,
+ const char *type)
{
struct GNUNET_CRYPTO_EccSignaturePurpose purpose = {
.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST),
@@ -303,8 +328,71 @@ perf_signing (struct TALER_CRYPTO_ExchangeSignHelper *esh)
delay);
} /* for j */
fprintf (stderr,
- "%u (sequential) signature operations took %s\n",
- (unsigned int) NUM_SIGN_TESTS,
+ "%u (%s) signature operations took %s\n",
+ (unsigned int) NUM_SIGN_PERFS,
+ type,
+ GNUNET_STRINGS_relative_time_to_string (duration,
+ GNUNET_YES));
+ return 0;
+}
+
+
+/**
+ * Parallel signing logic.
+ *
+ * @param esh handle to the helper
+ * @return 0 on success
+ */
+static int
+par_signing (struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct GNUNET_TIME_Absolute start;
+ struct GNUNET_TIME_Relative duration;
+ pid_t pids[NUM_CORES];
+ struct TALER_CRYPTO_ExchangeSignHelper *esh;
+
+ memset (keys,
+ 0,
+ sizeof (keys));
+ num_keys = 0;
+ start = GNUNET_TIME_absolute_get ();
+ for (unsigned int i = 0; i<NUM_CORES; i++)
+ {
+ pids[i] = fork ();
+ GNUNET_assert (-1 != pids[i]);
+ if (0 == pids[i])
+ {
+ int ret;
+
+ esh = TALER_CRYPTO_helper_esign_connect (cfg,
+ "taler-exchange",
+ &key_cb,
+ NULL);
+ if (NULL == esh)
+ {
+ GNUNET_break (0);
+ exit (EXIT_FAILURE);
+ }
+ ret = perf_signing (esh,
+ "parallel");
+ TALER_CRYPTO_helper_esign_disconnect (esh);
+ esh = NULL;
+ exit (ret);
+ }
+ }
+ for (unsigned int i = 0; i<NUM_CORES; i++)
+ {
+ int wstatus;
+
+ GNUNET_assert (pids[i] ==
+ waitpid (pids[i],
+ &wstatus,
+ 0));
+ }
+ duration = GNUNET_TIME_absolute_get_duration (start);
+ fprintf (stderr,
+ "%u (parallel) signature operations took %s (total real time)\n",
+ (unsigned int) NUM_SIGN_PERFS * NUM_CORES,
GNUNET_STRINGS_relative_time_to_string (duration,
GNUNET_YES));
return 0;
@@ -319,10 +407,10 @@ run_test (void)
{
struct GNUNET_CONFIGURATION_Handle *cfg;
struct TALER_CRYPTO_ExchangeSignHelper *esh;
+ int ret;
struct timespec req = {
.tv_nsec = 250000000
};
- int ret;
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK !=
@@ -334,54 +422,53 @@ run_test (void)
}
/* wait for helper to start and give us keys */
- fprintf (stderr, "Waiting for helper client directory to become available ");
- for (unsigned int i = 0; i<1000; i++)
+ fprintf (stderr, "Waiting for helper to start ... ");
+ for (unsigned int i = 0; i<100; i++)
{
+ nanosleep (&req,
+ NULL);
esh = TALER_CRYPTO_helper_esign_connect (cfg,
+ "taler-exchange",
&key_cb,
NULL);
if (NULL != esh)
break;
- nanosleep (&req, NULL);
fprintf (stderr, ".");
}
- GNUNET_CONFIGURATION_destroy (cfg);
if (NULL == esh)
{
- GNUNET_break (0);
+ fprintf (stderr,
+ "\nFAILED: timeout trying to connect to helper\n");
+ GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
- fprintf (stderr, " done.\n");
-
- /* wait for helper to start and give us keys */
- fprintf (stderr, "Waiting for helper to start ");
- for (unsigned int i = 0; i<1000; i++)
- {
- TALER_CRYPTO_helper_esign_poll (esh);
- if (0 != num_keys)
- break;
- nanosleep (&req, NULL);
- fprintf (stderr, ".");
- }
if (0 == num_keys)
{
fprintf (stderr,
- "\nFAILED: timeout trying to connect to helper\n");
+ "\nFAILED: no keys returned by helper\n");
TALER_CRYPTO_helper_esign_disconnect (esh);
+ esh = NULL;
+ GNUNET_CONFIGURATION_destroy (cfg);
return 1;
}
fprintf (stderr,
- "\nOK: Helper ready (%u keys)\n",
+ " Done (%u keys)\n",
num_keys);
-
ret = 0;
if (0 == ret)
ret = test_revocation (esh);
if (0 == ret)
ret = test_signing (esh);
if (0 == ret)
- ret = perf_signing (esh);
- TALER_CRYPTO_helper_esign_disconnect (esh);
+ ret = perf_signing (esh,
+ "sequential");
+ if (NULL != esh)
+ {
+ TALER_CRYPTO_helper_esign_disconnect (esh);
+ esh = NULL;
+ }
+ if (0 == ret)
+ ret = par_signing (cfg);
/* clean up our state */
for (unsigned int i = 0; i<MAX_KEYS; i++)
if (keys[i].valid)
@@ -390,6 +477,7 @@ run_test (void)
GNUNET_assert (num_keys > 0);
num_keys--;
}
+ GNUNET_CONFIGURATION_destroy (cfg);
return ret;
}
@@ -407,6 +495,8 @@ main (int argc,
(void) argc;
(void) argv;
+ unsetenv ("XDG_DATA_HOME");
+ unsetenv ("XDG_CONFIG_HOME");
GNUNET_log_setup ("test-helper-eddsa",
"INFO",
NULL);