Update copyrights to 2021, using "make update-copyright"
[tor.git] / src / test / test_hs_metrics.c
blob8625933df7a45a43cf1f851e29c59a86e299256c
1 /* Copyright (c) 2020-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 /**
5 * \file test_hs_metrics.c
6 * \brief Test hidden service metrics.
7 */
9 #define HS_SERVICE_PRIVATE
11 #include "test/test.h"
12 #include "test/test_helpers.h"
13 #include "test/log_test_helpers.h"
15 #include "app/config/config.h"
17 #include "feature/hs/hs_metrics.h"
18 #include "feature/hs/hs_service.h"
20 #include "lib/crypt_ops/crypto_ed25519.h"
22 static void
23 test_metrics(void *arg)
25 hs_service_t *service = NULL;
27 (void) arg;
29 hs_init();
31 service = hs_service_new(get_options());
32 tt_assert(service);
33 service->config.version = HS_VERSION_THREE;
34 ed25519_secret_key_generate(&service->keys.identity_sk, 0);
35 ed25519_public_key_generate(&service->keys.identity_pk,
36 &service->keys.identity_sk);
37 register_service(get_hs_service_map(), service);
39 tt_assert(service->metrics.store);
41 /* Update entry by identifier. */
42 hs_metrics_update_by_ident(HS_METRICS_NUM_INTRODUCTIONS,
43 &service->keys.identity_pk, 0, 42);
45 /* Confirm the entry value. */
46 const smartlist_t *entries = metrics_store_get_all(service->metrics.store,
47 "tor_hs_intro_num_total");
48 tt_assert(entries);
49 tt_int_op(smartlist_len(entries), OP_EQ, 1);
50 const metrics_store_entry_t *entry = smartlist_get(entries, 0);
51 tt_assert(entry);
52 tt_int_op(metrics_store_entry_get_value(entry), OP_EQ, 42);
54 /* Update entry by service now. */
55 hs_metrics_update_by_service(HS_METRICS_NUM_INTRODUCTIONS,
56 service, 0, 42);
57 tt_int_op(metrics_store_entry_get_value(entry), OP_EQ, 84);
59 done:
60 hs_free_all();
63 struct testcase_t hs_metrics_tests[] = {
65 { "metrics", test_metrics, TT_FORK, NULL, NULL },
67 END_OF_TESTCASES