aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-12-18 18:59:05 -0500
committerNick Mathewson <nickm@torproject.org>2018-12-18 18:59:05 -0500
commitbb091da1e7e229d6b938ae99d40078610b13ac76 (patch)
treef413f518f3a4118e323358e55bc51628370e00f2 /src/test
parent372df7a630afa4ffb0782287366b629916e0f728 (diff)
parent976c62e62a38c9f30c32ca742a43d59633a0e6ab (diff)
downloadtor-bb091da1e7e229d6b938ae99d40078610b13ac76.tar.gz
tor-bb091da1e7e229d6b938ae99d40078610b13ac76.zip
Merge branch 'ticket28839_v2_squashed'
Diffstat (limited to 'src/test')
-rw-r--r--src/test/bench.c40
-rw-r--r--src/test/test_parsecommon.c8
-rw-r--r--src/test/test_util_format.c4
3 files changed, 47 insertions, 5 deletions
diff --git a/src/test/bench.c b/src/test/bench.c
index ff8707d41c..f8680c3ab6 100644
--- a/src/test/bench.c
+++ b/src/test/bench.c
@@ -39,6 +39,9 @@
#include "lib/crypt_ops/digestset.h"
#include "lib/crypt_ops/crypto_init.h"
+#include "feature/dirparse/microdesc_parse.h"
+#include "feature/nodelist/microdesc.h"
+
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_PROCESS_CPUTIME_ID)
static uint64_t nanostart;
static inline uint64_t
@@ -639,6 +642,41 @@ bench_ecdh_p224(void)
}
#endif
+static void
+bench_md_parse(void)
+{
+ uint64_t start, end;
+ const int N = 100000;
+ // selected arbitrarily
+ const char md_text[] =
+ "@last-listed 2018-12-14 18:14:14\n"
+ "onion-key\n"
+ "-----BEGIN RSA PUBLIC KEY-----\n"
+ "MIGJAoGBAMHkZeXNDX/49JqM2BVLmh1Fnb5iMVnatvZZTLJyedqDLkbXZ1WKP5oh\n"
+ "7ec14dj/k3ntpwHD4s2o3Lb6nfagWbug4+F/rNJ7JuFru/PSyOvDyHGNAuegOXph\n"
+ "3gTGjdDpv/yPoiadGebbVe8E7n6hO+XxM2W/4dqheKimF0/s9B7HAgMBAAE=\n"
+ "-----END RSA PUBLIC KEY-----\n"
+ "ntor-onion-key QgF/EjqlNG1wRHLIop/nCekEH+ETGZSgYOhu26eiTF4=\n"
+ "family $00E9A86E7733240E60D8435A7BBD634A23894098 "
+ "$329BD7545DEEEBBDC8C4285F243916F248972102 "
+ "$69E06EBB2573A4F89330BDF8BC869794A3E10E4D "
+ "$DCA2A3FAE50B3729DAA15BC95FB21AF03389818B\n"
+ "p accept 53,80,443,5222-5223,25565\n"
+ "id ed25519 BzffzY99z6Q8KltcFlUTLWjNTBU7yKK+uQhyi1Ivb3A\n";
+
+ reset_perftime();
+ start = perftime();
+ for (int i = 0; i < N; ++i) {
+ smartlist_t *s = microdescs_parse_from_string(md_text, NULL, 1,
+ SAVED_IN_CACHE, NULL);
+ SMARTLIST_FOREACH(s, microdesc_t *, md, microdesc_free(md));
+ smartlist_free(s);
+ }
+
+ end = perftime();
+ printf("Microdesc parse: %f nsec\n", NANOCOUNT(start, end, N));
+}
+
typedef void (*bench_fn)(void);
typedef struct benchmark_t {
@@ -666,6 +704,8 @@ static struct benchmark_t benchmarks[] = {
ENT(ecdh_p256),
ENT(ecdh_p224),
#endif
+
+ ENT(md_parse),
{NULL,NULL,0}
};
diff --git a/src/test/test_parsecommon.c b/src/test/test_parsecommon.c
index 6da125dd0a..8e74fcdb4d 100644
--- a/src/test/test_parsecommon.c
+++ b/src/test/test_parsecommon.c
@@ -300,8 +300,8 @@ test_parsecommon_get_next_token_parse_keys(void *arg)
tt_int_op(token->tp, OP_EQ, R_IPO_ONION_KEY);
tt_int_op(token->n_args, OP_EQ, 0);
tt_str_op(token->object_type, OP_EQ, "RSA PUBLIC KEY");
- tt_int_op(token->object_size, OP_EQ, 0);
- tt_assert(!token->object_body);
+ tt_int_op(token->object_size, OP_EQ, 140);
+ tt_assert(token->object_body);
tt_assert(token->key);
tt_assert(!token->error);
@@ -335,8 +335,8 @@ test_parsecommon_get_next_token_parse_keys(void *arg)
tt_int_op(token2->tp, OP_EQ, C_CLIENT_KEY);
tt_int_op(token2->n_args, OP_EQ, 0);
tt_str_op(token2->object_type, OP_EQ, "RSA PRIVATE KEY");
- tt_int_op(token2->object_size, OP_EQ, 0);
- tt_assert(!token2->object_body);
+ tt_int_op(token2->object_size, OP_EQ, 608);
+ tt_assert(token2->object_body);
tt_assert(token2->key);
tt_assert(!token->error);
diff --git a/src/test/test_util_format.c b/src/test/test_util_format.c
index 85d8a8e62e..fd57125b86 100644
--- a/src/test/test_util_format.c
+++ b/src/test/test_util_format.c
@@ -392,10 +392,13 @@ test_util_format_encoded_size(void *arg)
base64_encode(outbuf, sizeof(outbuf), (char *)inbuf, i, 0);
tt_int_op(strlen(outbuf), OP_EQ, base64_encode_size(i, 0));
+ tt_int_op(i, OP_LE, base64_decode_maxsize(strlen(outbuf)));
+
base64_encode(outbuf, sizeof(outbuf), (char *)inbuf, i,
BASE64_ENCODE_MULTILINE);
tt_int_op(strlen(outbuf), OP_EQ,
base64_encode_size(i, BASE64_ENCODE_MULTILINE));
+ tt_int_op(i, OP_LE, base64_decode_maxsize(strlen(outbuf)));
}
done:
@@ -417,4 +420,3 @@ struct testcase_t util_format_tests[] = {
{ "encoded_size", test_util_format_encoded_size, 0, NULL, NULL },
END_OF_TESTCASES
};
-