summaryrefslogtreecommitdiff
path: root/test/benchmark_tests/security_tests/bm_load_policies.cpp
blob: bfafd7e7498306c525633797a6bf9136a8e73634 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (C) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <gtest/gtest.h>
#include "../../common/utility.hpp"
#include <benchmark/benchmark.h>

namespace {
std::string configuration_file { "/vsomeip/0_0/vsomeip_security.json" };
}

// Since this set of tests check a private method, there is the need to indirectly change the
// parameters used by load_policies, and check its changes using other methods.
// The remove_security_policy method checks if there is any loaded policy.
// The is_audit method checks the check_credentials value.
// No test was created for allow_remote_clients because it was inacessible.

static void BM_load_policies_loaded_policies(benchmark::State &state)
{
    std::unique_ptr<vsomeip_v3::policy_manager_impl> security(new vsomeip_v3::policy_manager_impl);

    // Force load of some policies.
    std::set<std::string> its_failed;
    std::vector<vsomeip_v3::configuration_element> policy_elements;
    std::set<std::string> input { utility::get_policies_path() + configuration_file };
    utility::read_data(input, policy_elements, its_failed);

    // Using load function to indirectly call load_policies.
    for (auto _ : state) {
        security->load(policy_elements.at(0));
    }
}

static void BM_load_policies_no_policies(benchmark::State &state)
{
    std::unique_ptr<vsomeip_v3::policy_manager_impl> security(new vsomeip_v3::policy_manager_impl);

    // Force load of some policies.
    std::set<std::string> its_failed;
    std::vector<vsomeip_v3::configuration_element> policy_elements;
    std::set<std::string> input { utility::get_policies_path() + configuration_file };
    utility::read_data(input, policy_elements, its_failed);

    // Remove all the policies from the file.
    policy_elements.at(0).tree_.get_child("security").erase("policies");

    // Using load function to indirectly call load_policies.
    for (auto _ : state) {
        security->load(policy_elements.at(0));
    }
}

static void  BM_load_policies_check_credentials_true(benchmark::State &state)
{
    std::unique_ptr<vsomeip_v3::policy_manager_impl> security(new vsomeip_v3::policy_manager_impl);

    // Force load of some policies without the check credentials value set.
    std::set<std::string> its_failed;
    std::vector<vsomeip_v3::configuration_element> policy_elements;
    std::set<std::string> input { utility::get_policies_path() + configuration_file };
    utility::read_data(input, policy_elements, its_failed);

    // Load the check credentials value as false.
    bool check_credentials_value {true};
    policy_elements.at(0).tree_.add<bool>("security.check_credentials", check_credentials_value);

    // Using load function to indirectly call load_policies.
    for (auto _ : state) {
        security->load(policy_elements.at(0));
    }
}

static void  BM_load_policies_check_credentials_false(benchmark::State &state)
{
    std::unique_ptr<vsomeip_v3::policy_manager_impl> security(new vsomeip_v3::policy_manager_impl);

    // Force load of some policies without the check credentials value set.
    std::set<std::string> its_failed;
    std::vector<vsomeip_v3::configuration_element> policy_elements;
    std::set<std::string> input { utility::get_policies_path() + configuration_file };
    utility::read_data(input, policy_elements, its_failed);

    // Load the check credentials value as false.
    bool check_credentials_value {false};
    policy_elements.at(0).tree_.add<bool>("security.check_credentials", check_credentials_value);

    // Using load function to indirectly call load_policies.
    for (auto _ : state) {
        security->load(policy_elements.at(0));
    }
}

BENCHMARK(BM_load_policies_loaded_policies);
BENCHMARK(BM_load_policies_no_policies);
BENCHMARK(BM_load_policies_check_credentials_true);
BENCHMARK(BM_load_policies_check_credentials_false);