Skip to content

Commit 81b1e41

Browse files
VeithMetroCopilotsebaszm
authored
[TestPriorityQueue] Create a plugin and an application to test the new Priority Queue feature (#932)
* Created the plugin using PSG * Adjust the test plugin to work on Windows * Finally adjustments * Partially revert HEAD (only selected files) * Add an option to build the test plugin to the tests cmake * Update tests/TestPriorityQueue/TestPriorityQueue.h Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/TestPriorityQueue/test_app/TestPriorityQueueApp.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/TestPriorityQueue/TestPriorityQueueImplementation.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/TestPriorityQueue/TestPriorityQueuePlugin.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Adjust the copyrights * Adjust the copyrights in cmake as well --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: sebaszm <45654185+sebaszm@users.noreply.github.com>
1 parent 85aab6f commit 81b1e41

15 files changed

+1108
-1
lines changed

tests/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ option(TEST_AUTOMATION_TOOLS "Utility to verify Thunder functions trigerred by A
2929
option(PLUGIN_TESTCONTROLLER "Include TestController plugin" OFF)
3030
option(PLUGIN_TESTUTILITY "Include TestUtility plugin" OFF)
3131
option(PLUGIN_TESTTEXTOPTIONS "Utility to verify the name of JSONRPC functions" OFF)
32+
option(PLUGIN_TESTPRIORITYQUEUE "Utility to verify the PriorityQueue implementation" OFF)
3233

3334
if(STORE_TEST)
3435
add_subdirectory(StoreTest)
@@ -50,4 +51,8 @@ endif()
5051

5152
if(PLUGIN_TESTTEXTOPTIONS)
5253
add_subdirectory(TestTextOptions)
53-
endif()
54+
endif()
55+
56+
if(PLUGIN_TESTPRIORITYQUEUE)
57+
add_subdirectory(TestPriorityQueue)
58+
endif()
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# If not stated otherwise in this file or this component's license file the
2+
# following copyright and licenses apply:
3+
#
4+
# Copyright 2025 Metrological
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
project(TestPriorityQueue)
19+
20+
cmake_minimum_required(VERSION 3.15)
21+
22+
find_package(Thunder)
23+
24+
project_version(1.0.0)
25+
26+
set(MODULE_NAME ${NAMESPACE}${PROJECT_NAME})
27+
28+
message("Setup ${MODULE_NAME} v${PROJECT_VERSION}")
29+
30+
set(PLUGIN_TESTPRIORITYQUEUE_STARTMODE "Activated" CACHE STRING "Automatically start TestPriorityQueue plugin")
31+
set(PLUGIN_TESTPRIORITYQUEUE_MODE "Local" CACHE STRING "Controls if the plugin should run in its own process, in process, container or remote.")
32+
33+
if(BUILD_REFERENCE)
34+
add_definitions(-DBUILD_REFERENCE=${BUILD_REFERENCE})
35+
endif()
36+
37+
find_package(${NAMESPACE}Plugins REQUIRED)
38+
find_package(${NAMESPACE}Messaging REQUIRED)
39+
find_package(CompileSettingsDebug CONFIG REQUIRED)
40+
41+
add_library(${MODULE_NAME} SHARED
42+
TestPriorityQueue.cpp
43+
TestPriorityQueueImplementation.cpp
44+
Module.cpp
45+
)
46+
47+
set_target_properties(${MODULE_NAME} PROPERTIES
48+
CXX_STANDARD 11
49+
CXX_STANDARD_REQUIRED YES)
50+
51+
target_link_libraries(${MODULE_NAME}
52+
PRIVATE
53+
CompileSettingsDebug::CompileSettingsDebug
54+
${NAMESPACE}Plugins::${NAMESPACE}Plugins
55+
${NAMESPACE}Messaging::${NAMESPACE}Messaging)
56+
57+
target_include_directories(${MODULE_NAME}
58+
PRIVATE
59+
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
60+
61+
install(TARGETS ${MODULE_NAME}
62+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${STORAGE_DIRECTORY}/plugins COMPONENT ${NAMESPACE}_Runtime)
63+
64+
add_subdirectory(test_app)
65+
66+
write_config()

tests/TestPriorityQueue/Module.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* If not stated otherwise in this file or this component's LICENSE file the
3+
* following copyright and licenses apply:
4+
*
5+
* Copyright 2025 Metrological
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#include "Module.h"
21+
22+
MODULE_NAME_DECLARATION(BUILD_REFERENCE)

tests/TestPriorityQueue/Module.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* If not stated otherwise in this file or this component's LICENSE file the
3+
* following copyright and licenses apply:
4+
*
5+
* Copyright 2025 Metrological
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#ifndef MODULE_NAME
23+
#define MODULE_NAME Plugin_TestPriorityQueue
24+
#endif
25+
26+
#include <com/com.h>
27+
#include <core/core.h>
28+
#include <plugins/plugins.h>
29+
30+
#undef EXTERNAL
31+
#define EXTERNAL
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
startmode = "@PLUGIN_TESTPRIORITYQUEUE_STARTMODE@"
2+
3+
configuration = JSON()
4+
5+
root = JSON()
6+
root.add("mode", "@PLUGIN_TESTPRIORITYQUEUE_MODE@")
7+
configuration.add("root", root)
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* If not stated otherwise in this file or this component's LICENSE file the
3+
* following copyright and licenses apply:
4+
*
5+
* Copyright 2025 Metrological
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#include "TestPriorityQueue.h"
21+
22+
namespace Thunder {
23+
namespace Plugin {
24+
25+
namespace {
26+
27+
static Metadata<TestPriorityQueue>metadata(
28+
// Version
29+
1, 0, 0,
30+
// Preconditions
31+
{},
32+
// Terminations
33+
{},
34+
// Controls
35+
{}
36+
);
37+
}
38+
39+
const string TestPriorityQueue::Initialize(PluginHost::IShell* service)
40+
{
41+
string message;
42+
43+
ASSERT(_service == nullptr);
44+
ASSERT(service != nullptr);
45+
ASSERT(_implMath == nullptr);
46+
ASSERT(_connectionId == 0);
47+
48+
_service = service;
49+
_service->AddRef();
50+
_service->Register(&_notification);
51+
52+
_implMath = service->Root<Exchange::IMath>(_connectionId, timeout, _T("TestPriorityQueueImplementation"));
53+
if (_implMath == nullptr) {
54+
message = _T("Couldn't create instance of implMath");
55+
}
56+
/*else {
57+
StartFlood(100000, std::max(1u, std::thread::hardware_concurrency()));
58+
}*/
59+
60+
return (message);
61+
}
62+
63+
void TestPriorityQueue::Deinitialize(PluginHost::IShell* service)
64+
{
65+
//StopFlood();
66+
67+
ASSERT(_service == service);
68+
69+
_service->Unregister(&_notification);
70+
71+
if (_implMath != nullptr) {
72+
73+
RPC::IRemoteConnection* connection(service->RemoteConnection(_connectionId));
74+
VARIABLE_IS_NOT_USED uint32_t result = _implMath->Release();
75+
_implMath = nullptr;
76+
77+
ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED);
78+
79+
// The process can disappear in the meantime...
80+
if (connection != nullptr) {
81+
// But if it did not disappear in the meantime, forcefully terminate it. Shoot to kill
82+
connection->Terminate();
83+
connection->Release();
84+
}
85+
}
86+
_service->Release();
87+
_service = nullptr;
88+
_connectionId = 0;
89+
}
90+
91+
string TestPriorityQueue::Information() const {
92+
return (string());
93+
}
94+
95+
void TestPriorityQueue::StartFlood(uint32_t totalCalls, uint32_t parallelism)
96+
{
97+
StopFlood();
98+
99+
_stop.store(false, std::memory_order_release);
100+
101+
const uint32_t perThread = (totalCalls / parallelism);
102+
_workers.reserve(parallelism);
103+
104+
for (uint32_t i = 0; i < parallelism; ++i) {
105+
_workers.emplace_back([this, perThread]() {
106+
uint16_t res = 0;
107+
108+
for (uint32_t n = 0; ((n < perThread) && (_stop.load(std::memory_order_acquire) == false)); ++n) {
109+
const uint16_t a = static_cast<uint16_t>(n * 2);
110+
const uint16_t b = static_cast<uint16_t>(n);
111+
_implMath->Add(a, b, res);
112+
_implMath->Sub(a, b, res);
113+
}
114+
});
115+
}
116+
}
117+
118+
void TestPriorityQueue::StopFlood()
119+
{
120+
_stop.store(true, std::memory_order_release);
121+
122+
for (auto& w : _workers) {
123+
if (w.joinable()) {
124+
w.join();
125+
}
126+
}
127+
_workers.clear();
128+
}
129+
130+
void TestPriorityQueue::Deactivated(RPC::IRemoteConnection* connection) {
131+
if (connection->Id() == _connectionId) {
132+
ASSERT(_service != nullptr);
133+
Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE));
134+
}
135+
}
136+
137+
} // Plugin
138+
} // Thunder

0 commit comments

Comments
 (0)