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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 | // Copyright (C) 2020-2023 Internet Systems Consortium, Inc. ("ISC")
//
// 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 <config.h>
#include <cc/data.h>
#include <dhcpsrv/cfg_multi_threading.h>
#include <util/multi_threading_mgr.h>
#include <gtest/gtest.h><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
using namespace isc::data;
using namespace isc::dhcp;
using namespace isc::util;
namespace {
/// @brief Test fixture class for @c MultiThreadingConfigParser
class CfgMultiThreadingTest : public ::testing::Test {
public:
/// @brief Constructor
CfgMultiThreadingTest() = default;
/// @brief Destructor
virtual ~CfgMultiThreadingTest() = default;
protected:
/// @brief Setup for each test.
///
/// Clears the configuration in the @c MultiThreadingMgr.
virtual void SetUp();
/// @brief Cleans up after each test.
///
/// Clears the configuration in the @c MultiThreadingMgr.
virtual void TearDown();
};
void
CfgMultiThreadingTest::SetUp() {
MultiThreadingMgr::instance().apply(false, 0, 0);
}
void
CfgMultiThreadingTest::TearDown() {
MultiThreadingMgr::instance().apply(false, 0 , 0);
}
/// @brief Verifies that extracting multi threading settings works
TEST_F(CfgMultiThreadingTest, extract) {<--- syntax error
bool enabled = false;
uint32_t thread_count = 0;
uint32_t queue_size = 0;
std::string content_json =
"{"
" \"enable-multi-threading\": true,\n"
" \"thread-pool-size\": 4,\n"
" \"packet-queue-size\": 64\n"
"}";
ConstElementPtr param;
ASSERT_NO_THROW(param = Element::fromJSON(content_json))
<< "invalid context_json, test is broken";
ASSERT_NO_THROW(CfgMultiThreading::extract(param, enabled, thread_count,
queue_size));
EXPECT_EQ(enabled, true);
EXPECT_EQ(thread_count, 4);
EXPECT_EQ(queue_size, 64);
content_json = "{}";
ASSERT_NO_THROW(param = Element::fromJSON(content_json))
<< "invalid context_json, test is broken";
//check empty config
ASSERT_NO_THROW(CfgMultiThreading::extract(param, enabled, thread_count,
queue_size));
EXPECT_EQ(enabled, true);
EXPECT_EQ(thread_count, 0);
EXPECT_EQ(queue_size, 0);
enabled = true;
thread_count = 4;
queue_size = 64;
// check empty data
ASSERT_NO_THROW(CfgMultiThreading::extract(ConstElementPtr(), enabled,
thread_count, queue_size));
EXPECT_EQ(enabled, true);
EXPECT_EQ(thread_count, 0);
EXPECT_EQ(queue_size, 0);
}
/// @brief Verifies that applying multi threading settings works
TEST_F(CfgMultiThreadingTest, apply) {
EXPECT_FALSE(MultiThreadingMgr::instance().getMode());
EXPECT_EQ(MultiThreadingMgr::instance().getThreadPoolSize(), 0);
EXPECT_EQ(MultiThreadingMgr::instance().getPacketQueueSize(), 0);
EXPECT_EQ(MultiThreadingMgr::instance().getThreadPool().getMaxQueueSize(), 0);
std::string content_json =
"{"
" \"enable-multi-threading\": true,\n"
" \"thread-pool-size\": 4,\n"
" \"packet-queue-size\": 64\n"
"}";
ConstElementPtr param;
ASSERT_NO_THROW(param = Element::fromJSON(content_json))
<< "invalid context_json, test is broken";
CfgMultiThreading::apply(param);
EXPECT_TRUE(MultiThreadingMgr::instance().getMode());
EXPECT_EQ(MultiThreadingMgr::instance().getThreadPoolSize(), 4);
EXPECT_EQ(MultiThreadingMgr::instance().getPacketQueueSize(), 64);
EXPECT_EQ(MultiThreadingMgr::instance().getThreadPool().getMaxQueueSize(), 64);
}
} // namespace
|