zpp
Zephyr C++20 Framework
main.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2021 Erwin Rol <erwin@erwinrol.com>
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#include <zephyr/ztest.h>
8
9
#include <zephyr/kernel.h>
10
11
#include <
zpp/mutex.hpp
>
12
#include <
zpp/thread.hpp
>
13
#include <
zpp/lock_guard.hpp
>
14
#include <
zpp/utils.hpp
>
15
16
17
ZTEST_SUITE
(test_zpp_mutex, NULL, NULL, NULL, NULL, NULL);
18
19
namespace
{
20
21
zpp::mutex
m;
22
23
K_MUTEX_DEFINE(g_mutex);
24
25
zpp::mutex_ref
m_ref(&g_mutex);
26
27
}
// namespace
28
29
ZTEST
(test_zpp_mutex, test_mutex_cmp)
30
{
31
bool
res;
32
33
res = m == m_ref;
34
zassert_false(res,
"unable to compare mutex == mutex_ref\n"
);
35
36
res = m != m_ref;
37
zassert_true(res,
"unable to compare mutex != mutex_ref\n"
);
38
39
res = m_ref == m;
40
zassert_false(res,
"unable to compare mutex_ref == mutex\n"
);
41
42
res = m_ref != m;
43
zassert_true(res,
"unable to compare mutex_ref != mutex\n"
);
44
45
res = m_ref == &g_mutex;
46
zassert_true(res,
"unable to compare mutex_ref == k_condvar*\n"
);
47
48
res = m_ref != &g_mutex;
49
zassert_false(res,
"unable to compare mutex_ref != k_condvar*\n"
);
50
51
res = m == &g_mutex;
52
zassert_false(res,
"unable to compare mutex == k_condvar*\n"
);
53
54
res = m != &g_mutex;
55
zassert_true(res,
"unable to compare mutex != k_mutex*\n"
);
56
57
res = &g_mutex == m_ref;
58
zassert_true(res,
"unable to compare k_condvar* == mutex_ref\n"
);
59
60
res = &g_mutex != m_ref;
61
zassert_false(res,
"unable to compare k_condvar* != mutex_ref\n"
);
62
63
res = &g_mutex == m;
64
zassert_false(res,
"unable to compare mutex == k_condvar* == mutex\n"
);
65
66
res = &g_mutex != m;
67
zassert_true(res,
"unable to compare k_mutex* != mutex\n"
);
68
69
}
70
71
ZTEST
(test_zpp_mutex, test_mutex)
72
{
73
auto
rc = m.lock();
74
75
zassert_true(!!rc,
"Failed to lock mutex: %d\n"
, rc.error());
76
77
rc = m.unlock();
78
79
zassert_true(!!rc,
"Failed to unlock mutex: %d\n"
, rc.error());
80
}
81
82
ZTEST
(test_zpp_mutex, test_mutex_ref)
83
{
84
auto
rc = m_ref.lock();
85
86
zassert_true(!!rc,
"Failed to lock mutex_ref: %d\n"
, rc.error());
87
88
rc = m_ref.unlock();
89
90
zassert_true(!!rc,
"Failed to unlock mutex_ref: %d\n"
, rc.error());
91
}
92
93
ZTEST
(test_zpp_mutex, test_lock_guard)
94
{
95
zpp::lock_guard
g(m);
96
zpp::lock_guard
g_ref(m_ref);
97
}
zpp::lock_guard
lock_guard using zpp::mutex as a lock.
Definition:
lock_guard.hpp:23
zpp::mutex_ref
A recursive mutex class borrowing the native mutex.
Definition:
mutex.hpp:191
zpp::mutex
A recursive mutex class.
Definition:
mutex.hpp:150
lock_guard.hpp
mutex.hpp
ZTEST
ZTEST(zpp_atomic_tests, test_atomic_bitset)
Definition:
main.cpp:23
ZTEST_SUITE
ZTEST_SUITE(zpp_atomic_tests, NULL, NULL, NULL, NULL, NULL)
thread.hpp
utils.hpp
tests
mutex
src
main.cpp
Generated by
1.9.1