-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into development/METROL-948
- Loading branch information
Showing
13 changed files
with
1,876 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.