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

Go to the source code of this file.

Functions

 ZTEST_SUITE (test_zpp_sem, NULL, NULL, NULL, NULL, NULL)
 
 ZTEST (test_zpp_sem, test_sem_cmp)
 
 ZTEST (test_zpp_sem, test_sem_try_take)
 
 ZTEST (test_zpp_sem, test_sem_try_take_fails)
 
 ZTEST (test_zpp_sem, test_sem_try_take_for_fails)
 
 ZTEST (test_zpp_sem, test_sem_try_take_ref)
 
 ZTEST (test_zpp_sem, test_sem_try_take_fails_ref)
 
 ZTEST (test_zpp_sem, test_sem_try_take_for_fails_ref)
 

Function Documentation

◆ ZTEST() [1/7]

ZTEST ( test_zpp_sem  ,
test_sem_cmp   
)

Definition at line 27 of file main.cpp.

28 {
29  bool res;
30 
31  res = simple_sem == simple_ref_sem;
32  zassert_false(res, "unable to compare sem == sem_ref\n");
33 
34  res = simple_sem != simple_ref_sem;
35  zassert_true(res, "unable to compare sem != sem_ref\n");
36 
37  res = simple_ref_sem == simple_sem;
38  zassert_false(res, "unable to compare sem_ref == sem\n");
39 
40  res = simple_ref_sem != simple_sem;
41  zassert_true(res, "unable to compare sem_ref != sem\n");
42 
43  res = simple_ref_sem == &g_sem;
44  zassert_true(res, "unable to compare sem_ref == k_sem*\n");
45 
46  res = simple_ref_sem != &g_sem;
47  zassert_false(res, "unable to compare sem_ref != k_sem*\n");
48 
49  res = simple_sem == &g_sem;
50  zassert_false(res, "unable to compare sem == k_sem*\n");
51 
52  res = simple_sem != &g_sem;
53  zassert_true(res, "unable to compare sem != k_sem*\n");
54 
55  res = &g_sem == simple_ref_sem;
56  zassert_true(res, "unable to compare k_sem* == sem_ref\n");
57 
58  res = &g_sem != simple_ref_sem;
59  zassert_false(res, "unable to compare k_sem* != sem_ref\n");
60 
61  res = &g_sem == simple_sem;
62  zassert_false(res, "unable to compare k_sem* == sem\n");
63 
64  res = &g_sem != simple_sem;
65  zassert_true(res, "unable to compare k_sem* != sem\n");
66 
67 }

◆ ZTEST() [2/7]

ZTEST ( test_zpp_sem  ,
test_sem_try_take   
)

Definition at line 69 of file main.cpp.

70 {
71  simple_sem.reset();
72 
73  for (int i = 0; i < 5; i++) {
74  simple_sem++;
75 
76  auto signal_count = simple_sem.count();
77  zassert_true(signal_count == (i + 1),
78  "signal count missmatch Expected %d, got %d\n",
79  (i + 1), signal_count);
80  }
81 
82  for (int i = 4; i >= 0; i--) {
83  auto ret_value = simple_sem.try_take();
84  zassert_true(ret_value == true,
85  "unable to do k_sem_take which returned %d\n",
86  ret_value);
87 
88  auto signal_count = simple_sem.count();
89  zassert_true(signal_count == i,
90  "signal count missmatch Expected %d, got %d\n",
91  i, signal_count);
92  }
93 }

◆ ZTEST() [3/7]

ZTEST ( test_zpp_sem  ,
test_sem_try_take_fails   
)

Definition at line 95 of file main.cpp.

96 {
97  simple_sem.reset();
98 
99  for (int i = 4; i >= 0; i--) {
100  auto ret_value = simple_sem.try_take();
101  zassert_true(ret_value == false,
102  "k_sem_take returned when not possible");
103 
104  auto signal_count = simple_sem.count();
105  zassert_true(signal_count == 0U,
106  "signal count missmatch Expected 0, got %d\n",
107  signal_count);
108  }
109 }

◆ ZTEST() [4/7]

ZTEST ( test_zpp_sem  ,
test_sem_try_take_fails_ref   
)

Definition at line 150 of file main.cpp.

151 {
152  simple_ref_sem.reset();
153 
154  for (int i = 4; i >= 0; i--) {
155  auto ret_value = simple_ref_sem.try_take();
156  zassert_true(ret_value == false,
157  "k_sem_take returned when not possible");
158 
159  auto signal_count = simple_ref_sem.count();
160  zassert_true(signal_count == 0U,
161  "signal count missmatch Expected 0, got %d\n",
162  signal_count);
163  }
164 }

◆ ZTEST() [5/7]

ZTEST ( test_zpp_sem  ,
test_sem_try_take_for_fails   
)

Definition at line 111 of file main.cpp.

112 {
113  using namespace std::chrono;
114 
115  simple_sem.reset();
116 
117  for (int i = 4; i >= 0; i--) {
118  auto ret_value = simple_sem.try_take_for(100ms);
119  zassert_true(ret_value == false,
120  "k_sem_take succeeded when its not possible");
121  }
122 }

◆ ZTEST() [6/7]

ZTEST ( test_zpp_sem  ,
test_sem_try_take_for_fails_ref   
)

Definition at line 166 of file main.cpp.

167 {
168  using namespace std::chrono;
169 
170  simple_ref_sem.reset();
171 
172  for (int i = 4; i >= 0; i--) {
173  auto ret_value = simple_ref_sem.try_take_for(100ms);
174  zassert_true(ret_value == false,
175  "k_sem_take succeeded when its not possible");
176  }
177 }

◆ ZTEST() [7/7]

ZTEST ( test_zpp_sem  ,
test_sem_try_take_ref   
)

Definition at line 124 of file main.cpp.

125 {
126  simple_ref_sem.reset();
127 
128  for (int i = 0; i < 5; i++) {
129  simple_ref_sem++;
130 
131  auto signal_count = simple_ref_sem.count();
132  zassert_true(signal_count == (i + 1),
133  "signal count missmatch Expected %d, got %d\n",
134  (i + 1), signal_count);
135  }
136 
137  for (int i = 4; i >= 0; i--) {
138  auto ret_value = simple_ref_sem.try_take();
139  zassert_true(ret_value == true,
140  "unable to do k_sem_take which returned %d\n",
141  ret_value);
142 
143  auto signal_count = simple_ref_sem.count();
144  zassert_true(signal_count == i,
145  "signal count missmatch Expected %d, got %d\n",
146  i, signal_count);
147  }
148 }

◆ ZTEST_SUITE()

ZTEST_SUITE ( test_zpp_sem  ,
NULL  ,
NULL  ,
NULL  ,
NULL  ,
NULL   
)