aboutsummaryrefslogtreecommitdiff
path: root/src/test/testing_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/testing_common.c')
-rw-r--r--src/test/testing_common.c91
1 files changed, 15 insertions, 76 deletions
diff --git a/src/test/testing_common.c b/src/test/testing_common.c
index 9c6580f788..7e9c47b48d 100644
--- a/src/test/testing_common.c
+++ b/src/test/testing_common.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2016, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
extern const char tor_git_revision[];
@@ -21,6 +21,7 @@ const char tor_git_revision[] = "";
#include "rephist.h"
#include "backtrace.h"
#include "test.h"
+#include "channelpadding.h"
#include <stdio.h>
#ifdef HAVE_FCNTL_H
@@ -32,13 +33,12 @@ const char tor_git_revision[] = "";
#include <direct.h>
#else
#include <dirent.h>
-#endif
+#endif /* defined(_WIN32) */
#include "or.h"
#ifdef USE_DMALLOC
#include <dmalloc.h>
-#include <openssl/crypto.h>
#include "main.h"
#endif
@@ -84,7 +84,7 @@ setup_directory(void)
(int)getpid(), rnd32);
r = mkdir(temp_dir);
}
-#else
+#else /* !(defined(_WIN32)) */
tor_snprintf(temp_dir, sizeof(temp_dir), "/tmp/tor_test_%d_%s",
(int) getpid(), rnd32);
r = mkdir(temp_dir, 0700);
@@ -92,7 +92,7 @@ setup_directory(void)
/* undo sticky bit so tests don't get confused. */
r = chown(temp_dir, getuid(), getgid());
}
-#endif
+#endif /* defined(_WIN32) */
if (r) {
fprintf(stderr, "Can't create directory %s:", temp_dir);
perror("");
@@ -178,65 +178,6 @@ remove_directory(void)
rm_rf(temp_dir);
}
-/** Define this if unit tests spend too much time generating public keys*/
-#define CACHE_GENERATED_KEYS
-
-#define N_PREGEN_KEYS 11
-static crypto_pk_t *pregen_keys[N_PREGEN_KEYS];
-static int next_key_idx;
-
-/** Generate and return a new keypair for use in unit tests. If we're using
- * the key cache optimization, we might reuse keys. "idx" is ignored.
- * Our only guarantee is that we won't reuse a key till this function has been
- * called several times. The order in which keys are returned is slightly
- * randomized, so that tests that depend on a particular order will not be
- * reliable. */
-crypto_pk_t *
-pk_generate(int idx)
-{
- (void) idx;
-#ifdef CACHE_GENERATED_KEYS
- /* Either skip 1 or 2 keys. */
- next_key_idx += crypto_rand_int_range(1,3);
- next_key_idx %= N_PREGEN_KEYS;
- return crypto_pk_dup_key(pregen_keys[next_key_idx]);
-#else
- crypto_pk_t *result;
- int res;
- result = crypto_pk_new();
- res = crypto_pk_generate_key__real(result);
- tor_assert(!res);
- return result;
-#endif
-}
-
-#ifdef CACHE_GENERATED_KEYS
-static int
-crypto_pk_generate_key_with_bits__get_cached(crypto_pk_t *env, int bits)
-{
- if (bits != 1024)
- return crypto_pk_generate_key_with_bits__real(env, bits);
-
- crypto_pk_t *newkey = pk_generate(0);
- crypto_pk_assign_(env, newkey);
- crypto_pk_free(newkey);
- return 0;
-}
-#endif
-
-/** Free all storage used for the cached key optimization. */
-static void
-free_pregenerated_keys(void)
-{
- unsigned idx;
- for (idx = 0; idx < N_PREGEN_KEYS; ++idx) {
- if (pregen_keys[idx]) {
- crypto_pk_free(pregen_keys[idx]);
- pregen_keys[idx] = NULL;
- }
- }
-}
-
static void *
passthrough_test_setup(const struct testcase_t *testcase)
{
@@ -297,14 +238,15 @@ main(int c, const char **v)
#ifdef USE_DMALLOC
{
- int r = CRYPTO_set_mem_ex_functions(tor_malloc_, tor_realloc_, tor_free_);
- tor_assert(r);
+ int r = crypto_use_tor_alloc_functions();
+ tor_assert(r == 0);
}
-#endif
+#endif /* defined(USE_DMALLOC) */
update_approx_time(time(NULL));
options = options_new();
tor_threads_init();
+ tor_compress_init();
network_init();
@@ -363,17 +305,14 @@ main(int c, const char **v)
tor_free(errmsg);
return 1;
}
+
tor_set_failed_assertion_callback(an_assertion_failed);
-#ifdef CACHE_GENERATED_KEYS
- for (i = 0; i < N_PREGEN_KEYS; ++i) {
- pregen_keys[i] = crypto_pk_new();
- int r = crypto_pk_generate_key(pregen_keys[i]);
- tor_assert(r == 0);
- }
- MOCK(crypto_pk_generate_key_with_bits,
- crypto_pk_generate_key_with_bits__get_cached);
-#endif
+ init_pregenerated_keys();
+
+ channelpadding_new_consensus_params(NULL);
+
+ predicted_ports_init();
atexit(remove_directory);