#include <zephyr/ztest.h>
#include <zpp/thread.hpp>
#include <zpp/sem.hpp>
#include <zpp/fmt.hpp>
#include <chrono>
Go to the source code of this file.
|  | 
|  | ZTEST_SUITE (zpp_thread_tests, NULL, NULL, NULL, NULL, NULL) | 
|  | 
|  | ZTEST (zpp_thread_tests, test_thread_creation) | 
|  | 
|  | ZTEST (zpp_thread_tests, test_thread_creation_void) | 
|  | 
|  | ZTEST (zpp_thread_tests, test_thread_creation_pointer) | 
|  | 
|  | ZTEST (zpp_thread_tests, test_thread_creation_params) | 
|  | 
◆ ZTEST() [1/4]
      
        
          | ZTEST | ( | zpp_thread_tests | , | 
        
          |  |  | test_thread_creation |  | 
        
          |  | ) |  |  | 
      
 
Definition at line 27 of file main.cpp.
   30   using namespace std::chrono;
 
   43     tcb, tstack(), attr, &theap,
 
   44     [&dummy, &done]() noexcept {
 
   45       print(
"Hello from thread tid={}\n",
 
   48       print(
"dummy = {}\n", (
void*)&dummy);
 
   49       print(
"done = {}\n", (
void*)&done);
 
   51       zassert_true(dummy == 42, 
"dummy not 42\n");
 
   60   zassert_true(rc == 
true, 
"join failed");
 
A counting semaphore class.
Thread creation attributes.
static constexpr thread_prio preempt(int prio) noexcept
Create a preemptive priority value.
The class thread repecents a single Zephyr thread.
auto get_id() noexcept
Get the thread ID of the current thread.
void print(const char *fmt, T_Args &&... args) noexcept
simple typesafe print function
 
References zpp::this_thread::get_id(), zpp::no, zpp::thread_prio::preempt(), and zpp::print().
 
 
◆ ZTEST() [2/4]
      
        
          | ZTEST | ( | zpp_thread_tests | , | 
        
          |  |  | test_thread_creation_params |  | 
        
          |  | ) |  |  | 
      
 
Definition at line 146 of file main.cpp.
  149   using namespace std::chrono;
 
  160       print(
"S() {} {} {}",
 
  164     S(
const S& other) noexcept : a(other.a), b(other.b)  {
 
  165       print(
"S(&{} {} {}) {} {} {}",
 
  166         (
void*)&other, other.a, other.b,
 
  170       print(
"~S() {} {} {}",
 
  185     tcb, tstack(), attr, &theap,
 
  186     [&done](S s, 
int a, 
int b) noexcept {
 
  187       print(
"Hello from thread tid={} s.a={} s.b={} a={} b={}\n",
 
  201   zassert_true(rc == 
true, 
"join failed");
 
 
References zpp::this_thread::get_id(), zpp::no, zpp::thread_prio::preempt(), and zpp::print().
 
 
◆ ZTEST() [3/4]
      
        
          | ZTEST | ( | zpp_thread_tests | , | 
        
          |  |  | test_thread_creation_pointer |  | 
        
          |  | ) |  |  | 
      
 
Definition at line 90 of file main.cpp.
   93   using namespace std::chrono;
 
  104       print(
"S() {} {} {}",
 
  108     S(
const S& other) noexcept : a(other.a), b(other.b)  {
 
  109       print(
"S(&{} {} {}) {} {} {}",
 
  110         (
void*)&other, other.a, other.b,
 
  114       print(
"~S() {} {} {}",
 
  127       print(
"Hello from thread tid={} s->a={} s->b={}\n",
 
  137   zassert_true(rc == 
true, 
"join failed");
 
  139   zassert_true(s.a == 21, 
"s.a != 21\n");
 
  140   zassert_true(s.b == 43, 
"s.a != 43\n");
 
auto join() noexcept
join the thread this object mamages.
 
References zpp::this_thread::get_id(), zpp::thread::join(), zpp::no, zpp::thread_prio::preempt(), and zpp::print().
 
 
◆ ZTEST() [4/4]
      
        
          | ZTEST | ( | zpp_thread_tests | , | 
        
          |  |  | test_thread_creation_void |  | 
        
          |  | ) |  |  | 
      
 
 
◆ ZTEST_SUITE()
      
        
          | ZTEST_SUITE | ( | zpp_thread_tests | , | 
        
          |  |  | NULL | , | 
        
          |  |  | NULL | , | 
        
          |  |  | NULL | , | 
        
          |  |  | NULL | , | 
        
          |  |  | NULL |  | 
        
          |  | ) |  |  |