1 /*
2  * Copyright (c) 2006-2019, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2021-09-03     liukang      the first version
9  */
10 
11 #include <rtthread.h>
12 #include "utest.h"
13 #include <thread>
14 
test_thread(void)15 static void test_thread(void)
16 {
17     int count = 0;
18     auto func = [&]() mutable
19     {
20         for (int i = 0; i < 100; ++i)
21         {
22             ++count;
23         }
24     };
25 
26     std::thread t1(func);
27     t1.join();
28 
29     if (count != 100)
30     {
31         uassert_false(1);
32     }
33 
34     std::thread t2(func);
35     t2.join();
36 
37     if (count != 200)
38     {
39         uassert_false(1);
40     }
41 
42     uassert_true(1);
43 }
44 
utest_tc_init(void)45 static rt_err_t utest_tc_init(void)
46 {
47     return RT_EOK;
48 }
49 
utest_tc_cleanup(void)50 static rt_err_t utest_tc_cleanup(void)
51 {
52     return RT_EOK;
53 }
54 
testcase(void)55 static void testcase(void)
56 {
57     UTEST_UNIT_RUN(test_thread);
58 }
59 UTEST_TC_EXPORT(testcase, "testcases.cpp11.thread_tc", utest_tc_init, utest_tc_cleanup, 10);
60