process-cpp
3.0.0
A simple convenience library for handling processes in C++11.
cross_process_sync_test.cpp
Go to the documentation of this file.
1
/*
2
* Copyright © 2013 Canonical Ltd.
3
*
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
12
*
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
17
*/
18
19
#include <
core/testing/cross_process_sync.h
>
20
21
#include <
core/testing/fork_and_run.h
>
22
23
#include <gtest/gtest.h>
24
25
TEST
(CrossProcessSync, signalling_the_sync_object_results_in_correct_count)
26
{
27
core::testing::CrossProcessSync
cps;
28
29
auto
service = [&cps]()
30
{
31
for
(
unsigned
int
i = 1; i <= 50; i++)
32
{
33
EXPECT_NO_THROW(cps.try_signal_ready_for(std::chrono::milliseconds{500}));
34
}
35
return ::testing::Test::HasFailure() ?
36
core::posix::exit::Status::failure
:
core::posix::exit::Status::success
;
37
};
38
39
auto
client = [&cps]()
40
{
41
std::uint32_t counter = 0;
42
for
(
unsigned
int
i = 1; i <= 50; i++)
43
{
44
EXPECT_NO_THROW(counter = cps.wait_for_signal_ready_for(std::chrono::milliseconds{500}));
45
EXPECT_EQ(i, counter);
46
}
47
48
return ::testing::Test::HasFailure() ?
49
core::posix::exit::Status::failure
:
core::posix::exit::Status::success
;
50
};
51
52
EXPECT_EQ(
core::testing::ForkAndRunResult::empty
,
core::testing::fork_and_run
(service, client));
53
}
54
55
TEST
(CrossProcessSync, timed_out_wait_on_sync_object_throws_correct_exception)
56
{
57
core::testing::CrossProcessSync
cps;
58
59
EXPECT_THROW(cps.wait_for_signal_ready_for(std::chrono::milliseconds{1}),
60
core::testing::CrossProcessSync::Error::Timeout
);
61
}
core::testing::CrossProcessSync
A cross-process synchronization primitive that supports simple wait-condition-like scenarios.
Definition
cross_process_sync.h:37
cross_process_sync.h
TEST
TEST(CrossProcessSync, signalling_the_sync_object_results_in_correct_count)
Definition
cross_process_sync_test.cpp:25
fork_and_run.h
core::posix::exit::Status::success
@ success
core::posix::exit::Status::failure
@ failure
core::testing::ForkAndRunResult::empty
@ empty
Special value indicating no bit being set.
core::testing::fork_and_run
CORE_POSIX_DLL_PUBLIC ForkAndRunResult fork_and_run(const std::function< core::posix::exit::Status()> &service, const std::function< core::posix::exit::Status()> &client)
Forks two processes for both the service and the client.
Definition
fork_and_run.cpp:41
core::testing::CrossProcessSync::Error::Timeout
Thrown if any of the *_for functions times out.
Definition
cross_process_sync.h:48
tests
cross_process_sync_test.cpp
Generated on Tue Jan 16 2024 00:00:00 for process-cpp by
1.10.0