Skip to content

Commit

Permalink
Merge branch 'master' into development/METROL-948
Browse files Browse the repository at this point in the history
  • Loading branch information
VeithMetro authored Aug 19, 2024
2 parents 48b37c2 + 90d7fa0 commit b074d05
Show file tree
Hide file tree
Showing 13 changed files with 1,876 additions and 452 deletions.
2 changes: 1 addition & 1 deletion Source/core/Singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace Core {
}

inline static SINGLETON& Instance() {
// As available does not see through friend clas/protected
// As available does not see through friend clas/protected
// declarations, we can not rely on the output of it.
// If this Instance method id called, assume it has a
// default constructor..
Expand Down
4 changes: 4 additions & 0 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ endif()
if(MESSAGEBUFFER_TEST)
add_subdirectory(message-buffer)
endif()

if(CYCLICBUFFER_TEST)
add_subdirectory(cyclic-buffer)
endif()
31 changes: 31 additions & 0 deletions Tests/cyclic-buffer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# If not stated otherwise in this file or this component's license file the
# following copyright and licenses apply:
#
# Copyright 2020 Metrological
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

add_executable(CyclicBuffer main.cpp)

set_target_properties(CyclicBuffer PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
)

target_link_libraries(CyclicBuffer
PRIVATE
${NAMESPACE}Core
)

install(TARGETS CyclicBuffer DESTINATION bin)

72 changes: 72 additions & 0 deletions Tests/cyclic-buffer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2020 Metrological
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "process.h"

#include <future>

#define ASYNC_TIMEOUT_BEGIN \
std::promise<bool> promise; \
std::future<bool> future = promise.get_future(); \
std::thread([&](std::promise<bool> completed) \
{ /* Before code that should complete before timeout expires */

#define ASYNC_TIMEOUT_END(MILLISECONDS /* timeout in milliseconds */, RESULT /* variable that has boolean result of executed code */) \
/* After code that should complete timely */ \
/* completed.set_value(true); */ \
completed.set_value_at_thread_exit(RESULT); \
} \
, std::move(promise)).detach() \
; \
if (future.wait_for(std::chrono::milliseconds(MILLISECONDS)) == std::future_status::timeout) { /* Task completed before timeout */ \
TRACE_L1(_T("Error : Stopping unresposive process.")); \
killpg(getpgrp(), SIGUSR1); /* Possible 'unresponsive' system, 'unlock' all related 'child' processes, default action is terminate */ \
} \
RESULT = future.get();

int main(int argc, char* argv[])
{
using namespace WPEFramework::Core;

constexpr uint8_t maxChildren = 3;

constexpr uint32_t memoryMappedFileRequestedSize = 446;
constexpr uint32_t internalBufferSize = 446;

constexpr char fileName[] = "/tmp/SharedCyclicBuffer";

constexpr uint32_t totalRuntime = infinite /*20000*/; // Milliseconds
constexpr uint32_t totalTimeout = /*totalRuntime +*/ 20000; // Milliseconds

WPEFramework::Tests::Process<memoryMappedFileRequestedSize, internalBufferSize, maxChildren> process(fileName);

bool result = false;

ASYNC_TIMEOUT_BEGIN // result will never be updated in its original scope

result = process.SetTotalRuntime(totalRuntime)
&& process.SetParentUsers(0, 0) /* 0 extra writer(s), 0 reader(s) */
&& process.SetChildUsers(1, 1) /* 1 writer(s), 1 reader(s) */
&& process.Execute()
;

ASYNC_TIMEOUT_END(totalTimeout, result)

return result ? EXIT_SUCCESS : EXIT_FAILURE;
}
Loading

0 comments on commit b074d05

Please sign in to comment.