zpp
Zephyr C++20 Framework
main.cpp File Reference
#include <zephyr/ztest.h>
#include <zephyr/kernel.h>
#include <zpp/mutex.hpp>
#include <zpp/thread.hpp>
#include <zpp/lock_guard.hpp>
#include <zpp/utils.hpp>
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

 ZTEST_SUITE (test_zpp_mutex, NULL, NULL, NULL, NULL, NULL)
 
 ZTEST (test_zpp_mutex, test_mutex_cmp)
 
 ZTEST (test_zpp_mutex, test_mutex)
 
 ZTEST (test_zpp_mutex, test_mutex_ref)
 
 ZTEST (test_zpp_mutex, test_lock_guard)
 

Function Documentation

◆ ZTEST() [1/4]

ZTEST ( test_zpp_mutex  ,
test_lock_guard   
)

Definition at line 93 of file main.cpp.

94 {
95  zpp::lock_guard g(m);
96  zpp::lock_guard g_ref(m_ref);
97 }
lock_guard using zpp::mutex as a lock.
Definition: lock_guard.hpp:23

◆ ZTEST() [2/4]

ZTEST ( test_zpp_mutex  ,
test_mutex   
)

Definition at line 71 of file main.cpp.

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 }

◆ ZTEST() [3/4]

ZTEST ( test_zpp_mutex  ,
test_mutex_cmp   
)

Definition at line 29 of file main.cpp.

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 }

◆ ZTEST() [4/4]

ZTEST ( test_zpp_mutex  ,
test_mutex_ref   
)

Definition at line 82 of file main.cpp.

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 }

◆ ZTEST_SUITE()

ZTEST_SUITE ( test_zpp_mutex  ,
NULL  ,
NULL  ,
NULL  ,
NULL  ,
NULL   
)