LCOV - code coverage report
Current view: top level - test - test_hs_metrics.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 23 23 100.0 %
Date: 2021-11-24 03:28:48 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.14